我在使用Windows Phone Silverlight 8.1應用程序中的相機時遇到問題。我只想初始化相機並查看其預覽(現在我不需要任何照片或視頻捕捉)。我發現nice and simple example on MSDN和CaptureSource.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
功能的信息(在同一頁上)。但我有問題,將它添加,這是因爲:
- 我無法找到設計師這種能力
- 我得到的錯誤,當我將其添加到manualy .xml文件
錯誤重現如下:
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解決方案來解決這個問題?
感謝您的好評。我沒有在屬性中搜索,我確信Package.appxmanifest是正確的文件(名稱非常相似)。我在適當的'WMAppManifest.xml'文件中找到了'ID_CAP_ISV_CAMERA'和'ID_CAP_MICROPHONE',現在它完美的工作:) –