Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox: navigator.getUserMedia is not a function

I'm playing with browser and audio.

I'm doing this

        var session = {
          audio: true,
          video: false
        };
        var recordRTC = null;
        navigator.getUserMedia(session, initializeRecorder, onError);

But, using latest FF available I got a javascript error, saying that

navigator.getUserMedia is not a function

I copied this code from this blog post: https://blog.groupbuddies.com/posts/39-tutorial-html-audio-capture-streaming-to-nodejs-no-browser-extensions

And similar on latest Chrome:

Uncaught TypeError: undefined is not a function

But I know that this api is supported from both browser

What am I doing wrong?

like image 526
realtebo Avatar asked Mar 11 '15 16:03

realtebo


People also ask

Is getUserMedia deprecated?

getUserMedia() Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.

What does the getUserMedia API connect the browser to?

getUserMedia() is a part of the webRTC media capture API and is used to get access to the camera and the microphone connected to the user device (user computer, smartphone, etc.) from the browser.

What is getUserMedia API?

getUserMedia API This API is used for accessing and controlling the media devices like the camera in our device. It is available in the navigator. mediaDevices object.


2 Answers

It's not supported unprefixed yet. See http://caniuse.com/#search=getusermedia

You'll need to get the browser-specific prefix and use that. As posted in another answer:

navigator.getUserMedia = ( navigator.getUserMedia ||
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia);

This will set navigator.getUserMedia to whatever it detects to be the proper prefixed version.

like image 89
Scimonster Avatar answered Nov 16 '22 01:11

Scimonster


Since navigator.getUserMedia() is deprecated, use this :

navigator.getUserMedia = (
    navigator.getUserMedia ||
    navigator.webkitGetUserMedia ||
    navigator.mozGetUserMedia ||
    navigator.msGetUserMedia
);

if (typeof navigator.mediaDevices.getUserMedia === 'undefined') {
    navigator.getUserMedia({
        audio: true
    }, streamHandler, errorHandler);
} else {
    navigator.mediaDevices.getUserMedia({
        audio: true
    }).then(streamHandler).catch(errorHandler);
}
like image 41
Subin Avatar answered Nov 16 '22 01:11

Subin