Windows phone 8.1 Camera Initialisation - UnAuthorizedException

时间:2014-08-13 16:11:39

标签: c# camera windows-phone-8.1

我正试图在我的Windows Phone 8.1通用应用程序上使用MediaCapture api启动相机。该代码适用于Windows 8.1和Windows Phone 8.1模拟器。我能够发射相机并拍照。

但是它会在Windows Phone 8.1设备上抛出UnauthorizedException。类似的问题被问到Here

但是,我不知道是否有人解决了这个问题。我正在设备旁边加载应用程序进行测试。我的要求是在侧载应用程序上启动摄像头。

代码段:

初始化MediaCapture:

                DeviceInformation cameraDevice = await GetCameraID();
                if (cameraDevice != null)
                {
                    mMediaManager_ = new Windows.Media.Capture.MediaCapture();
                    var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                    settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
                    settings.MediaCategory = Windows.Media.Capture.MediaCategory.Other;
                    settings.AudioProcessing = Windows.Media.AudioProcessing.Default;
                    settings.VideoDeviceId = cameraDevice.Id;                       

                    await mMediaManager_.InitializeAsync(settings);
                    mMediaManager_.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(RecordLimitationExceeded);
                    mMediaManager_.Failed += new Windows.Media.Capture.MediaCaptureFailedEventHandler(RecordFailed);

                }

拍照:

                mMediaStorageFile_ = await folder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);
                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mMediaManager_.CapturePhotoToStorageFileAsync(imageProperties, mMediaStorageFile_);                   
                mCameraScreen_.setPreviewImage(mMediaStorageFile_);

1 个答案:

答案 0 :(得分:0)

这个错误似乎已在上次更新时得到纠正。

我已经在开发人员预览版8.10.14176.243上进行了测试,MediaCapture.InitializeAsync现在应该可以正常运行了。