2015-05-02 88 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',现在它完美的工作:) –

相关问题