Windows phone 8.1摄像头初始化- UnAuthorizedException
本文关键字:初始化 UnAuthorizedException 摄像头 phone Windows | 更新日期: 2023-09-27 18:17:46
我正在尝试在我的windows phone 8.1通用应用程序上使用MediaCapture api启动相机。该代码在windows 8.1和windows phone 8.1模拟器上工作正常。我会启动相机拍照。
但是它会在Windows Phone 8.1设备上抛出UnauthorizedException。这里也有类似的问题
但是,我不知道是否有人解决了这个问题。我正在设备上加载应用程序进行测试。我的要求是在侧载应用程序上启动相机。
代码片段:
初始化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_);
似乎这个错误已经在上次更新中被纠正了。
正如我在开发者预览版8.10.14176.243上测试的那样,MediaCapture.InitializeAsync
现在应该可以正常工作了。