【发布时间】:2015-05-02 18:44:19
【问题描述】:
我在 Windows Phone Silverlight 8.1 应用程序中使用相机时遇到问题。我只想初始化相机并查看它的预览(现在我不需要任何照片或视频捕获)。我找到了nice and simple example on MSDN 和
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 功能的信息(在同一页面上)。但是我添加它有问题,因为:
- 我在设计器中找不到此功能
- 手动将其添加到 .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 解决方案来解决这个问题?
【问题讨论】:
标签: c# silverlight windows-phone-8.1