Windows Phone 8.1相机初始化 - 访问被拒绝的例外

时间:2014-08-09 23:29:50

标签: c# .net camera windows-8.1 windows-phone-8.1

使用适用于Windows Phone的8.1 ​​MediaCapture类。

已宣布"音频"和#34;网络摄像头",其中90%是作为例外的原因。

Kicker是,它在WP模拟器中完美运行,但在实际设备上中断。

完全例外是here

enter image description here

我添加了一大堆支票,以确保我们不会重新初始化已经初始化的相机或尝试在初始化之前阅读等等(因为我认为问题是由引起的)所以它是这不太可能。

    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以显示预览。

1 个答案:

答案 0 :(得分:3)

这是Windows api的临时错误。它是在2014年9月24日发布的Windows Phone 8.1更新中修复的。