UnauthorizedAccessException when calling MediaCapture InitializeAsync ()

I am trying to use MediaCapture

for shooting with Windows Phone 8.1 Lumia 930.

However, as soon as I call InitializeAsync()

in my MediaCapture

-object, I get UnauthorizedAccessException

with a message Access is denied

.

This is my code:

class SimpleCamera
{

    private MediaCaptureInitializationSettings _captureInitSettings;
    private List<Windows.Devices.Enumeration.DeviceInformation> _deviceList;
    private Windows.Media.MediaProperties.MediaEncodingProfile _profile;
    private Windows.Media.Capture.MediaCapture _mediaCapture;
    private bool _recording = false;
    private bool _previewing = false;

    private async void EnumerateCameras()
    {
        var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(
            Windows.Devices.Enumeration.DeviceClass.VideoCapture);

        _deviceList = new List<Windows.Devices.Enumeration.DeviceInformation>();

        // Add the devices to deviceList
        if (devices.Count > 0)
        {

            for (var i = 0; i < devices.Count; i++)
            {
                _deviceList.Add(devices[i]);
            }

            InitCaptureSettings();
            InitMediaCapture();
            //rootPage.NotifyUser("Initialization complete.", NotifyType.StatusMessage);

        }
        else
        {
            //rootPage.NotifyUser("No camera device is found ", NotifyType.ErrorMessage);
        }
    }

    // Begin initialization.
    public void Initialization()
    {
        //rootPage.NotifyUser("Initialization started.", NotifyType.StatusMessage);
        EnumerateCameras();
    }


    private void InitCaptureSettings()
    {
        _captureInitSettings = null;
        _captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
        _captureInitSettings.AudioDeviceId = "";
        _captureInitSettings.VideoDeviceId = "";
        _captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;
        _captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;

        if (_deviceList.Count > 0)
            _captureInitSettings.VideoDeviceId = _deviceList[0].Id;
    }

    // Create a profile.
    private void CreateProfile()
    {
        _profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(
        Windows.Media.MediaProperties.VideoEncodingQuality.Qvga);
    }

    // Create and initialze the MediaCapture object.
    public async void InitMediaCapture()
    {
        _mediaCapture = null;
        _mediaCapture = new Windows.Media.Capture.MediaCapture();

        // Set the MediaCapture to a variable in App.xaml.cs to handle suspension.
        //(App.Current as App).MediaCapture = _mediaCapture;

        await _mediaCapture.InitializeAsync(_captureInitSettings);

        CreateProfile();
    }

    // Start the video capture.
    public async void StartMediaCaptureSession()
    {
        if (!this._recording) { 
            var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(
                "cameraCapture.mp4", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            await _mediaCapture.StartRecordToStorageFileAsync(_profile, storageFile);
            this._recording = true;
        }
    }

    public Boolean isRecording()
    {
        return this._recording;
    }

    // Stop the video capture.
    public async void StopMediaCaptureSession()
    {
        if (this._recording)
        {
            await _mediaCapture.StopRecordAsync();
            this._recording = false;
            //(App.Current as App).IsRecording = false;
        }
    }

}

      

In mine, Package.appxmanifest

I chose webcam, microphone, etc.

I have updated my phone to the latest version.

What else can I do? Does anyone else have this problem?

+3


source to share





All Articles