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.
来源:https://stackoverflow.com/questions/25224102/windows-phone-8-1-camera-initialisation-access-denied-exception