CaptureSource.Start() 在 Windows Phone Silverlight 8.1 中抛出 System.UnauthorizedAccessException
CaptureSource.Start() throws System.UnauthorizedAccessException in Windows Phone Silverlight 8.1
我在 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 解决方案来解决这个问题吗?
首先,您似乎正在尝试将该功能添加到 Package.appxmanifest
而不是 WMAppManifest.xml
。您应该能够在 Solution Explorer -> -> Properties:
下找到 WMAppManifest.xml
打开该文件应该可以让您选择添加 ID_CAP_*
功能。
其次,您需要同时指定 ID_CAP_ISV_CAMERA
和 ID_CAP_MICROPHONE
才能使用 CaptureSource.Start()
,即使您只使用其中一台设备。
我在 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 解决方案来解决这个问题吗?
首先,您似乎正在尝试将该功能添加到 Package.appxmanifest
而不是 WMAppManifest.xml
。您应该能够在 Solution Explorer ->
WMAppManifest.xml
打开该文件应该可以让您选择添加 ID_CAP_*
功能。
其次,您需要同时指定 ID_CAP_ISV_CAMERA
和 ID_CAP_MICROPHONE
才能使用 CaptureSource.Start()
,即使您只使用其中一台设备。