Why is getUserMedia throwing a [object NavigatorUs

2019-02-16 14:52发布

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

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.

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.

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

Edit 2: This error is also occurring on other websites that try to access my microphone through webrtc. Traditional Flash implementation still works.

Chrome seems to be throwing out an error message at regular intervals while open.

[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

NavigatorUserMediaError {code: 1, PERMISSION_DENIED: 1}

4条回答
Explosion°爆炸
2楼-- · 2019-02-16 15:16

This can happen in two situations and I've experienced both in 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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-16 15:36

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

查看更多
ゆ 、 Hurt°
4楼-- · 2019-02-16 15:36

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.

More detials https://webrtchacks.com/safari-webrtc/

查看更多
放荡不羁爱自由
5楼-- · 2019-02-16 15:42

NavigatorUserMediaError {code: 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.

查看更多
登录 后发表回答