如何在打包的应用程序中为Chrome OS或Chrome扩展程序启用相机和麦克风? [英] How to enable camera and microphone in packaged application for Chrome OS or Chrome extension?

查看:139
本文介绍了如何在打包的应用程序中为Chrome OS或Chrome扩展程序启用相机和麦克风?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试以下场景:我在单独的窗口中调用视频群聊网页,但应用程序无权访问麦克风和摄像头-按钮为红色,并且消息提示环聊无法使用所选的麦克风/摄像头".

I'm testing scenario where I call a hangouts web page in separate window but application doesn't have access to microphone and camera - buttons are red and message says that "Hangouts can't use the selected microphone/camera".

我已包含在权限"audioCapture""videoCapture"中.

I have included in permissions "audioCapture" and "videoCapture".

要使其正常工作必须做什么?

What has to be done to make it work?

在允许媒体应用访问摄像头和麦克风后-我可以在环聊设置中看到这一点,但是图像和语音不会通过环聊传输给其他参与者.我必须为流媒体设置一些内容吗?

After allowing media app has access to camera and microphone - I can see that in settings of hangouts but picture and voice are not transmitted over the hangouts to other participants. Is there something I have to set for streaming media?

我已经有这段代码:

navigator.webkitGetUserMedia({ audio: true, video: true },
            function (stream) {
                mediaStream = stream;
            },
            function (error) {
                console.error("Error trying to get the stream:: " + error.message);
            });    

推荐答案

如果您需要为嵌入<webview>的页面提供音频/视频,仅要求"audioCapture"/"videoCapture"权限是不够的.

If you need to provide audio/video for a <webview>-embedded page, requiring "audioCapture"/"videoCapture" permissions is not enough.

要使用这些选项,页面需要浏览器的权限.在普通的Chrome浏览器中,您会看到一个信息栏,允许用户允许/拒绝请求.

To use those, the page requests permission to the browser. In normal Chrome you'll see an infobar allowing the user to allow/deny the request.

<webview>不显示这些元素,而是引发事件,由应用决定是否允许/拒绝它:

<webview> does not show those elements, instead it raises an event and it's up to the app to allow/deny it:

permissionrequest

permissionrequest

访客页面需要从嵌入程序请求特殊权限时触发.

Fired when the guest page needs to request special permission from the embedder.

以下示例代码将授予来宾页面访问webkitGetUserMedia API的权限.请注意,使用此示例代码的应用程序本身必须指定audioCapture和/或videoCapture清单权限:

The following example code will grant the guest page access to the webkitGetUserMedia API. Note that an app using this example code must itself specify audioCapture and/or videoCapture manifest permissions:

webview.addEventListener('permissionrequest', function(e) {
  if (e.permission === 'media') {
    e.request.allow();
  }
});

这篇关于如何在打包的应用程序中为Chrome OS或Chrome扩展程序启用相机和麦克风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆