本文介绍了Windows Phone 8.1相机初始化 - 访问被拒绝例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为Windows Phone使用8.1 MediaCapture类。



已声明Audio和Webcam的功能,其中90% / em>是引起异常的原因。



Kicker是,它在WP模拟器中工作得很好,但在实际设备上断开。



完全例外是:



>



我添加了一个检查山,以确保我们不重新初始化已经初始化的相机或尝试读取之前的初始化..等(因为我假设的问题是由)。所以这是不太可能

  private async任务InitializeCameraAsync()
{
if(_isInitialized)
{
Debug.WriteLine(跳过不必要的初始化);
return;
}

Debug.WriteLine(初始化摄像机媒体捕获...);
_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!);

//仅代码完成,不可能相关

//设置低滞后照片捕获
if(IsNotUsingInstantCapture)
{
Debug.WriteLine(准备低滞后照片捕获);
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,


解决方案

这是Windows api的一个临时错误。它是与2014年9月24日发布的Windows Phone 8.1更新固定的。


Using the 8.1 MediaCapture classes for Windows Phone.

Have declared the capabilities for "Audio" and "Webcam", which 90% is what would be the cause of the exception.

Kicker is, it works perfectly in the WP emulator, but breaks on an actual device.

Exact exception is here :

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 is then being bound to the .source of a xaml CaptureElement to show a preview.

解决方案

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相机初始化 - 访问被拒绝例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:27