javascript 当我在 Chrome 中单击“允许”时,为什么 getUserMedia 会抛出 [object NavigatorUserMediaError]?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17793599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is getUserMedia throwing a [object NavigatorUserMediaError] when I click "Allow" in Chrome?
提问by Big Duck
Recently, I started getting errors when trying to access the client's mic through my website. When Chrome asks whether to allow the site to access the user's microphone, [object NavigatorUserMediaError]
is produced whether they click "allow" or "deny." This has been happening regardless of whether or not a microphone is actually plugged into the computer (which is running Ubuntu 12.04).
最近,我在尝试通过我的网站访问客户的麦克风时开始出现错误。当 Chrome 询问是否允许网站访问用户的麦克风时,[object NavigatorUserMediaError]
会产生他们是否点击“允许”或“拒绝”。无论麦克风是否实际插入计算机(运行 Ubuntu 12.04),这种情况都会发生。
Further testing through Firefox showed that this is not specific to Chrome. The problem only started after I had done a live-input demo and then logged out of the computer. I tried making a bare bones demo of accessing the microphone, and it ran into the same problem.
通过 Firefox 进行的进一步测试表明,这并非特定于 Chrome。问题仅在我完成实时输入演示然后退出计算机后才开始。我尝试制作一个访问麦克风的简单演示,但遇到了同样的问题。
var getVideo = false, getAudio = true;
navigator.getUserMedia || (navigator.getUserMedia = navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia || navigator.msGetUserMedia);
function init() {
if(navigator.getUserMedia) {
navigator.getUserMedia({video:getVideo, audio:getAudio}, onSuccess, onError);
} else {
alert('getUserMedia failed.');
}
}
function onSuccess() {
console.log("Yay");
}
function onError(err) {
console.log("Noo " + err);
}
This is rather puzzling as it had worked perfectly up until the point where I logged out and then logged back in and tried to test it again.
这相当令人费解,因为它一直运行良好,直到我注销然后重新登录并尝试再次测试它。
I am hosting the web code locally, through Jetty and Eclipse. I am accessing it by typing localhost:8080/my-program
into the web browser.
我通过 Jetty 和 Eclipse 在本地托管 Web 代码。我通过localhost:8080/my-program
在 Web 浏览器中输入内容来访问它。
Edit: After the error occurs, the icon of a camera shows up in the chrome address bar, saying that Chrome is accessing my microphone and listing two possible microphones, "Default" and "Built-in Audio Analog Stereo."
编辑:发生错误后,Chrome 地址栏中会显示摄像头的图标,表示 Chrome 正在访问我的麦克风并列出两个可能的麦克风,“默认”和“内置音频模拟立体声”。
Edit 2: This error is also occurring on other websites that try to access my microphone through webrtc. Traditional Flash implementation still works.
编辑 2:此错误也发生在其他尝试通过 webrtc 访问我的麦克风的网站上。传统的 Flash 实现仍然有效。
Chrome seems to be throwing out an error message at regular intervals while open.
Chrome 似乎在打开时定期抛出错误消息。
[361:362:0725/095320:ERROR:audio_output_device.cc(186)]
Not implemented reached in virtual void
media::AudioOutputDevice::OnStateChanged(media::AudioOutputIPCDelegate::State)
Edit 3: I was able to clarify the error message a bit more
编辑 3:我能够进一步澄清错误消息
NavigatorUserMediaError {code: 1, PERMISSION_DENIED: 1}
回答by Bruce
** One Browser at a Time **
** 一次一个浏览器 **
I've encountered this situation when I am testing with multiple browsers open. It would appear that only one browser can access the media at a time.
我在打开多个浏览器的情况下进行测试时遇到过这种情况。一次似乎只有一个浏览器可以访问媒体。
ie When I've got my page open in Chrome, and the video/audio is working, then Firefox won't work, and when I've got it working in Firefox, then Chrome doesn't work.
即当我在 Chrome 中打开我的页面并且视频/音频正常工作时,Firefox 将无法工作,而当我在 Firefox 中工作时,Chrome 将无法工作。
回答by nakib
This can happen in two situations and I've experienced both in Ubuntu 12.04:
这可能发生在两种情况下,我在 Ubuntu 12.04 中都遇到过:
You have clicked Deny once and then the browser saves that setting, always returning error when asked for media access in that page. (This does not seem to be your case as you get the question from browser, but you just have to go to the address bar, click in the camera icon and change the option to ask again).
Your browser is not having access to the media devices and as in any computer without cameras nor microphones, even if you press Allow, you will get an error event as it cannot give you any streams. Try to check the browser settings to see if you can choose the selected camera. I've experienced this and the list was empty. To solve this I had to reboot the machine and Chrome started showing the list of devices again.
您单击了拒绝一次,然后浏览器保存该设置,在该页面中要求媒体访问时总是返回错误。(当您从浏览器收到问题时,这似乎不是您的情况,但您只需转到地址栏,单击相机图标并更改选项以再次询问)。
您的浏览器无法访问媒体设备,就像在任何没有摄像头或麦克风的计算机中一样,即使您按“允许”,您也会收到错误事件,因为它无法为您提供任何流。尝试检查浏览器设置,看看是否可以选择所选的相机。我经历过这种情况,但清单是空的。为了解决这个问题,我不得不重新启动机器,Chrome 再次开始显示设备列表。
回答by tobler
NavigatorUserMediaError {code: 1, PERMISSION_DENIED: 1}
NavigatorUserMediaError {代码:1,PERMISSION_DENIED:1}
This means your browser settings are not allowing you to access the camera. Go into your browser settings -> under website settings you'll find a list of webpages that you have blocked from accessing your device.
这意味着您的浏览器设置不允许您访问相机。进入您的浏览器设置 -> 在网站设置下,您将找到已阻止访问您的设备的网页列表。
回答by Ivy.Xie
getUserMedia only works on https; no exception for localhost (i.e http://localhost). Safari also does not ever seem to allow getUserMedia from within an iFrame. I always get a “Trying to call getUserMedia from a document with a different security origin than its top-level frame” error. This makes using sites like codepen and jsfiddle impossible.
getUserMedia 仅适用于 https;本地主机也不例外(即http://localhost)。Safari 似乎也不允许从 iFrame 中获取 getUserMedia。我总是收到“试图从安全来源与其顶级框架不同的文档中调用 getUserMedia”错误。这使得使用 codepen 和 jsfiddle 等网站变得不可能。
More detials https://webrtchacks.com/safari-webrtc/