2017-06-29 1 views
2

J'essaie d'accéder à la caméra dans une application UWP mais j'ai une erreur:Que faire pour accéder à la caméra dans une application UWP en utilisant MediaCapture?

Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll 
WinRT information: Access is denied. 

The app was denied access to the camera 
The thread 0x2c9c has exited with code 0 (0x0). 
The program '[3352] CameraGetPreviewFrame.exe' has exited with code 1 (0x1). 

Voici mon code:

if (cameraDevice == null) 
{ 
    Debug.WriteLine("No camera device found!"); 
    return; 
} 

// Create MediaCapture and its settings 
_mediaCapture = new MediaCapture(); 

// Register for a notification when something goes wrong 
_mediaCapture.Failed += MediaCapture_Failed; 

var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id }; 

// Initialize MediaCapture 
try 
{ 
    await _mediaCapture.InitializeAsync(settings); 
    _isInitialized = true; 
} 
catch (UnauthorizedAccessException) 
{ 
    Debug.WriteLine("The app was denied access to the camera"); 
} 

Pourriez-vous me expliquer pourquoi ne l'exception se produit et comment résoudre le problème?

Répondre

3

Vous devez définir les capacités de microphone et webcam pour votre projet. Pour ce faire, vous pouvez suivre les étapes ci-dessous

  1. Ouvrir Package.appxmanifest
  2. Aller à Capacités Tab
  3. Vérifier Microphone et Webcam