問題描述
使用適用于 Windows Phone 的 8.1 MediaCapture 類.
Using the 8.1 MediaCapture classes for Windows Phone.
已聲明音頻"和網絡攝像頭"的功能,其中 90% 是導致異常的原因.
Have declared the capabilities for "Audio" and "Webcam", which 90% is what would be the cause of the exception.
Kicker 是,它在 WP 模擬器中完美運行,但在實際設備上中斷.
Kicker is, it works perfectly in the WP emulator, but breaks on an actual device.
確切的例外是這里:
我添加了大量檢查,以確保我們沒有重新初始化已經初始化的相機或嘗試在初始化之前讀取..等等(因為我認為問題是由以下原因引起的)所以這不太可能就是這樣.
I have added a mountain of checks to make sure we aren't re-initializing the already initialized camera or trying to read before the initializations.. etc (as I assumed the issue was being caused by) So it is very unlikely to be that.
private async Task InitializeCameraAsync()
{
if (_isInitialized)
{
Debug.WriteLine("Skipping unnecessary initialization");
return;
}
Debug.WriteLine("Initializing camera media capture...");
_deviceCapture = new MediaCapture();
await _deviceCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = _cameraInfoCollection[_currentVideoDevice].Id,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = _microphoneInfoCollection[_currentAudioDevice].Id
StreamingCaptureMode = StreamingCaptureMode.Video
});
Debug.WriteLine("Initialized camera media capture!");
// For code completion only, unlikely to be relevant
// Set up low-lag photo capture
if (IsNotUsingInstantCapture)
{
Debug.WriteLine("Preparing low-lag photo capture");
var imageEncoding = ImageEncodingProperties.CreateJpeg();
imageEncoding.Width = PhotoCaptureWidth;
imageEncoding.Height = PhotoCaptureHeight;
_lowLagPhotoCapture = await _deviceCapture.PrepareLowLagPhotoCaptureAsync(imageEncoding);
}
_isInitialized = true;
Debug.WriteLine("Initialized camera!");
}
_mediacapture 隨后被綁定到 xaml CaptureElement 的 .source 以顯示預覽.
_mediacapture is then being bound to the .source of a xaml CaptureElement to show a preview.
推薦答案
這是 Windows api 的臨時錯誤.它已在 2014 年 9 月 24 日發布的 Windows Phone 8.1 更新中得到修復.
It was a temporary bug with the Windows api. It was fixed with the Windows Phone 8.1 update that was released the 24th of september 2014.
這篇關于Windows Phone 8.1 相機初始化 - 訪問被拒絕異常的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!