6
votes

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.

1
The error sounds consistent with the behavior described at msdn.microsoft.com/en-us/library/windows/apps/hh768223. Is it possible that on the test device, the user account has accidentally denied access to the webcam or microphone for this app?Chris Culter
That was my first though, however, being windows phone, from what I know, you as a user can't disable/enable access to the above. AFAIk this is only done initially when installing the app from store?Kaelan Fouwels
There seems to be a problem (also with my device) - I had one simple program that used to take a photo and was working, after some updates now it's not working. I've also tried to run MSDN example without success.Romasz
I have the exact same problem on both a Lumia 620 as well as the Lumia 1020. It is noteworthy though, that for a brief period of time I had the (front) camera working on the 620. After updating to the newest developer preview, I started getting access denied exceptions again, just like on the 1020. - No solution yet.pkluz
Is there a solution to this issue yet?WereWolfBoy

1 Answers

3
votes

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.