简体   繁体   English

通过UWP WebView使用WebRTC getUserMedia的问题

[英]Issue with Using WebRTC getUserMedia with UWP WebView

I've created a basic UWP application with a WebView . 我已经使用WebView创建了一个基本的UWP应用程序。 I'm navigating to this URL: https://webrtc.github.io/samples/src/content/getusermedia/gum/ to test the use of getUserMedia() . 我导航到以下URL: https : //webrtc.github.io/samples/src/content/getusermedia/gum/以测试getUserMedia()的使用。

The error I get is: 我得到的错误是:

getUserMedia error: NotFoundError getUserMedia错误: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 ? 有人在UWP WebView使用getUserMedia吗?

You need allow PermissionRequest in PermissionRequested event handler. 您需要在PermissionRequested事件处理程序中允许allow PermissionRequest

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 除了处理PermissionRequested事件的应用程序外,用户还必须为请求位置或媒体功能的应用程序批准标准系统对话框,以便启用这些功能

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 . 对于WinJS应用程序更新 ,您可以参考此文档

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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