我在使用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',现在它完美的工作:) –