Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8.1 Camera Initialisation - Access Denied Exception

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 :

enter image description 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.

like image 222
Kaelan Fouwels Avatar asked Aug 09 '14 23:08

Kaelan Fouwels


1 Answers

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.

like image 142
WereWolfBoy Avatar answered Oct 20 '22 00:10

WereWolfBoy