2015-05-02 90 views
2

我在使用Windows Phone Silverlight 8.1應用程序中的相機時遇到問題。我只想初始化相機並查看其預覽(現在我不需要任何照片或視頻捕捉)。我發現nice and simple example on MSDNCaptureSource.Start()在Windows Phone Silverlight 8.1中引發System.UnauthorizedAccessException Silverlight 8.1

private CaptureSource captureSource; 
private VideoCaptureDevice videoCaptureDevice; 

private void InitializeVideoRecorder() 
{ 
    try 
    { 
     if (captureSource == null) 
     { 
      captureSource = new CaptureSource(); 
      var a = captureSource.VideoCaptureDevice; 

      videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); 

      captureSource.CaptureFailed += OnCaptureFailed; 

      if (videoCaptureDevice != null) 
      { 
       VideoRecorderBrush = new VideoBrush(); 
       VideoRecorderBrush.SetSource(captureSource); 

       captureSource.Start(); 
       CameraStatus = "Tap record to start recording..."; 
      } 
      else 
      { 
       CameraStatus = "A camera is not supported on this phone."; 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     CameraStatus = "ERROR: " + ex.Message.ToString(); 
    } 
} 

代碼停在captureSource.Start();System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.

首先,我發現在'WMAppManifest.xml'中需要ID_CAP_ISV_CAMERA功能的信息(在同一頁上)。但我有問題,將它添加,這是因爲:

  1. 我無法找到設計師這種能力 Designer capabilities
  2. 我得到的錯誤,當我將其添加到manualy .xml文件 WMAppManifest.xml capabilities

錯誤重現如下:

Warning 1 The 'Name' attribute is invalid - The value 'ID_CAP_ISV_CAMERA' is invalid according to its datatype 'http://schemas.microsoft.com/appx/2010/manifest:ST_Capabilities' - The Enumeration constraint failed. 
Error 3 App manifest validation failed. Value 'ID_CAP_ISV_CAMERA' of attribute '/Package/Capabilities/Capability/@Name' must be a valid capability. 

我甚至找到了相同的解決方案SO WP8.1 SilverLight Microsoft.Devices.PhotoCamera Access Denied

有人可以告訴我爲什麼我不能使用原始MSDN解決方案來解決這個問題?

回答

1

首先,它看起來像是試圖將該功能添加到Package.appxmanifest而不是WMAppManifest.xml。你應該能夠找到WMAppManifest.xml下,解決方案管理器 - > <項目> - >屬性:

enter image description here

打開該文件應該給你加ID_CAP_*功能的選項。

其次,你需要指定ID_CAP_ISV_CAMERAID_CAP_MICROPHONE爲了使用CaptureSource.Start(),即使你只使用的設備之一。

+1

感謝您的好評。我沒有在屬性中搜索,我確信Package.appxmanifest是正確的文件(名稱非常相似)。我在適當的'WMAppManifest.xml'文件中找到了'ID_CAP_ISV_CAMERA'和'ID_CAP_MICROPHONE',現在它完美的工作:) –

相關問題