【问题标题】:CaptureSource.Start() throws System.UnauthorizedAccessException in Windows Phone Silverlight 8.1CaptureSource.Start() 在 Windows Phone Silverlight 8.1 中引发 System.UnauthorizedAccessException
【发布时间】: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 功能的信息(在同一页面上)。但是我添加它有问题,因为:

  1. 我在设计器中找不到此功能
  2. 手动将其添加到 .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


    【解决方案1】:

    首先,您似乎正在尝试将该功能添加到 Package.appxmanifest 而不是 WMAppManifest.xml。您应该可以在解决方案资源管理器 -> -> 属性下找到WMAppManifest.xml

    打开该文件后,您应该可以选择添加 ID_CAP_* 功能。

    其次,您需要同时指定ID_CAP_ISV_CAMERAID_CAP_MICROPHONE 才能使用CaptureSource.Start(),即使您只使用其中一种设备。

    【讨论】:

    • 感谢您的出色回答。我没有在属性中搜索,我确定 Package.appxmanifest 是正确的文件(名称非常相似)。我在正确的WMAppManifest.xml 文件中找到了ID_CAP_ISV_CAMERAID_CAP_MICROPHONE,现在它工作得很好:)
    猜你喜欢
    • 1970-01-01
    • 2014-11-21
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    相关资源
    最近更新 更多