Why does Javascript getUserMedia work only with Firefox?

advertisements

I'm having trouble getting this code to work with browsers other than Firefox. The code is supposed to access the webcam. I can't find the problem. It does not work with chrome, internet explorer, Safari. It only works with Firefox. Does anyone have any answers why? How can I correct this code?

Here is the code:

<html>
<head>
<script>

function loading()
{
 var video = document.querySelector('#forVid');
navigator.getUserMedia = navigator.getUserMedia ||navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||navigator.msGetUserMedia || navigator.oGetUserMedia;

   if (navigator.getUserMedia)
   {
     var thevid = {video: true, audio: false};
     navigator.getUserMedia(thevid, handleVideo, forError)
   }

function handleVideo(localmediastream)
   {
      video.src = window.URL.createObjectURL(localmediastream);
   }

function forError(e)
    {
        // nothing
    }

}

</script>
</head>
<body onload = "loading()">

<video id = "forVid" style="position:absolute; top:0; left:50;"autoplay="true" height="600" width="600">

</body>
</html>


Because this API has very less browser's support. Following link lists all Supported and Unsupported browsers for this API.

http://caniuse.com/#feat=stream