Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigator.getusermedia

Tags:

html

I was playing around with the html5 new specifications, precisely the webcam functionalities.

By following this tutorial. I was getting the following error:

Native web camera streaming (getUserMedia) is not supported in this browser. 

which was taken by this if statement:

if (navigator.getUserMedia)

now, I am sure that navigator.getUserMedia is enabled in my browser, as these examples here work perfectly

so, I modified the code in the if, with the following:

if (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia)

but now, I am getting a javascript error:

Uncaught TypeError: Object #<Navigator> has no method 'getUserMedia' 

at this line here:

navigator.getUserMedia('video', successCallback, errorCallback);

which doesn't really make sense! it IS working on the last link i posted!

Any ideas?

Thanks in advance.

like image 210
john smith Avatar asked Nov 28 '22 17:11

john smith


1 Answers

If you're testing for navigator.getUserMedia, navigator.webkitGetUserMedia, navigator.mozGetUserMedia and navigator.msGetUserMedia then you have no guarantee that navigator.getUserMedia() is available. It could be that or any one of the other three. You could try something like this (from getUserMedia.js):

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

if ( !! navigator.getUserMedia_) {
    navigator.getUserMedia_('video', successCallback, errorCallback);
    //The rest of your code
like image 125
robertc Avatar answered Dec 22 '22 12:12

robertc