C# Windows phone 8.1摄像头初始化-未经授权异常
我正在尝试在我的windows phone 8.1通用应用程序上使用MediaCapture api启动摄像头。该代码在Windows 8.1和Windows Phone 8.1 emulator上运行良好。我可以启动相机并拍照 但它在WindowsPhone8.1设备上抛出了一个未经授权的异常。有人提出了类似的问题 但是,我不知道是否有人绕过了这个问题。我正在设备上加载应用程序进行测试。我的要求是在侧装应用程序上启动摄像头 代码段: 正在初始化MediaCapture:C# Windows phone 8.1摄像头初始化-未经授权异常,c#,camera,windows-phone-8.1,C#,Camera,Windows Phone 8.1,我正在尝试在我的windows phone 8.1通用应用程序上使用MediaCapture api启动摄像头。该代码在Windows 8.1和Windows Phone 8.1 emulator上运行良好。我可以启动相机并拍照 但它在WindowsPhone8.1设备上抛出了一个未经授权的异常。有人提出了类似的问题 但是,我不知道是否有人绕过了这个问题。我正在设备上加载应用程序进行测试。我的要求是在侧装应用程序上启动摄像头 代码段: 正在初始化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
现在应该可以正常工作了 可能很难找到解决未授权异常的方法。在我看来,这是上次更新后出现的一个bug——我的工作示例也抛出了异常(所以MSDN示例)。我们可能要等到下一次更新。因为我们正在设备上运行Windows Phone 8.1操作系统预览。它可能需要适当的固件更新,以支持最新的MediaCapture api。所以,我只是在想,在正式发布的操作系统上,代码可能工作得很好。再说一遍,这只是我的直觉。