调用MediaCapture时的UnauthorizedAccessException:InitializeAsync()

时间:2014-09-28 17:29:20

标签: .net sdk camera windows-phone-8.1

我正在尝试使用MediaCapture使用Windows Phone 8.1 Lumia 930拍照。

但是,只要我在InitializeAsync() - 对象上拨打MediaCapture,我就会收到UnauthorizedAccessException消息Access is denied

这是我的代码:

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;
        }
    }

}

在我的Package.appxmanifest我选择了网络摄像头,麦克风等

我将手机更新到最新版本。

我还能做什么?其他人有这个问题吗?

0 个答案:

没有答案