在 UWP WebView 中使用 WebRTC getUserMedia 的问题
Issue with Using WebRTC getUserMedia with UWP WebView
我已经用 WebView
创建了一个基本的 UWP 应用程序。我正在导航到此 URL: https://webrtc.github.io/samples/src/content/getusermedia/gum/ 以测试 getUserMedia()
.
的使用
我得到的错误是:
getUserMedia error: NotFoundError
我还添加了 Capabilities 网络摄像头功能,以便为您的应用启用摄像头设备。但运气不好。
有谁知道这是否可行,以及我是否因此做错了什么?有人在 UWP WebView
中使用 getUserMedia
吗?
您需要在 PermissionRequested
事件处理程序中允许 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
MyWebView.PermissionRequested += MyWebView_PermissionRequested;
private void MyWebView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
{
if (args.PermissionRequest.PermissionType == WebViewPermissionType.Media)
{
args.PermissionRequest.Allow();
}
}
更新
对于 WinJS 应用程序,您可以参考此 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;
}
});
我已经用 WebView
创建了一个基本的 UWP 应用程序。我正在导航到此 URL: https://webrtc.github.io/samples/src/content/getusermedia/gum/ 以测试 getUserMedia()
.
我得到的错误是:
getUserMedia error: NotFoundError
我还添加了 Capabilities 网络摄像头功能,以便为您的应用启用摄像头设备。但运气不好。
有谁知道这是否可行,以及我是否因此做错了什么?有人在 UWP WebView
中使用 getUserMedia
吗?
您需要在 PermissionRequested
事件处理程序中允许 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
MyWebView.PermissionRequested += MyWebView_PermissionRequested;
private void MyWebView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
{
if (args.PermissionRequest.PermissionType == WebViewPermissionType.Media)
{
args.PermissionRequest.Allow();
}
}
更新 对于 WinJS 应用程序,您可以参考此 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;
}
});