简体   繁体   中英

Issue with Using WebRTC getUserMedia with UWP WebView

I've created a basic UWP application with a WebView . I'm navigating to this URL: https://webrtc.github.io/samples/src/content/getusermedia/gum/ to test the use of getUserMedia() .

The error I get is:

getUserMedia error: NotFoundError

I have also add Capabilities Webcam capability to enable the Camera device for your app. but no luck.

Does anyone know if this should be possible, and if I'm therefore doing something wrong? Anyone using getUserMedia within a UWP WebView ?

You need allow PermissionRequest in PermissionRequested event handler.

In addition to the app handling the PermissionRequested event, the user will have to approve standard system dialogs for apps requesting location or media capabilities in order for these features to be enabled

MyWebView.PermissionRequested += MyWebView_PermissionRequested;

private void MyWebView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
{
    if (args.PermissionRequest.PermissionType == WebViewPermissionType.Media)
    {
        args.PermissionRequest.Allow();
    }
}

Update For WinJS app, you could refer this document .

document.getElementById('live-preview').addEventListener("MSWebViewPermissionRequested", permissionRequestedEventArgs => {
    const permissionRequest = permissionRequestedEventArgs.permissionRequest;
    switch (permissionRequest.type) {
        case "geolocation":
        case "media":
            permissionRequest.allow();
            break;
        case "pointerlock":
        case "webnotifications":
        case "screen":
        case "immersiveview":
        case "unlimitedIndexedDBQuota":
        default:
            permissionRequest.deny();
            break;
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM