How to enable camera and microphone in packaged application for Chrome OS or Chrome extension?

喜你入骨 提交于 2020-01-02 07:29:26

问题


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".

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

What has to be done to make it work?

Edit:

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?

I already have this piece of code:

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

回答1:


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

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> does not show those elements, instead it raises an event and it's up to the app to allow/deny it:

permissionrequest

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

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


来源:https://stackoverflow.com/questions/28089359/how-to-enable-camera-and-microphone-in-packaged-application-for-chrome-os-or-chr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!