2
votes

I have problem with using camera in Windows Phone Silverlight 8.1 application. I want just to initialize camera and see its preview (for now I don't need any photos or video capture). I have found nice and simple example on MSDN and

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();
    }
}

The code stops at captureSource.Start(); throwing System.UnauthorizedAccessException: Attempted to perform an unauthorized operation..

First of all I found information (on the same page) that ID_CAP_ISV_CAMERA capability is needed in `WMAppManifest.xml'. But I have problem with adding it, because:

  1. I can't find this capability in designer Designer capabilities
  2. I get error when I add it manualy to .xml file WMAppManifest.xml capabilities

Error reproduced below:

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.

I have even found the same solution on SO WP8.1 SilverLight Microsoft.Devices.PhotoCamera Access Denied

Can somebody tell me why can't I use original MSDN solution to this problem?

1

1 Answers

1
votes

First, it looks like you're trying to add that capability to Package.appxmanifest instead of WMAppManifest.xml. You should be able to find WMAppManifest.xml under Solution Explorer -> <your project> -> Properties:

enter image description here

Opening that file should give you the option to add ID_CAP_* capabilities.

Second, you need to specify both ID_CAP_ISV_CAMERA and ID_CAP_MICROPHONE in order to use CaptureSource.Start(), even if you're only using one of the devices.