问题
I am trying to launch camera using MediaCapture api on my windows phone 8.1 universal app. The code works fine on Windows 8.1 and Windows Phone 8.1 emulator. I am able to launch camera and take picture.
But it throws an UnauthorizedException on Windows Phone 8.1 device. Similar question is asked Here
But, i dont know whether someone got around this problem. And I am sideloading application on device for testing. My requirement is to launch camera on sideloaded applications.
Code snippet:
Initializing 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);
}
Taking Photo:
mMediaStorageFile_ = await folder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
await mMediaManager_.CapturePhotoToStorageFileAsync(imageProperties, mMediaStorageFile_);
mCameraScreen_.setPreviewImage(mMediaStorageFile_);
回答1:
It seems that this bug has been corrected with the last update.
As I've tested on developer preview version 8.10.14176.243, MediaCapture.InitializeAsync
should work now without problems.
来源:https://stackoverflow.com/questions/25291122/windows-phone-8-1-camera-initialisation-unauthorizedexception