0

I am trying to implement getUserMedia to use webcam. But the code is not working in local machine. I have checked it on chrome 43 on Firefox 31.

In Firefox, it is prompting request to share and after sharing in console log it is showing a message "Failure:HARDWARE_UNAVAILABLE"

In chrome it is not even asking for the permission to access webcam and no error messages or logs in console.

The same code when tried in jsfiddle is working fine and the browser able to access the camera and working fine. The following is the code:

<!DOCTYPE html>
<head>
    <title>HTML5 User Media Try Out</title>
<script>
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; ;
    if (navigator.getUserMedia) {
        navigator.getUserMedia({video: true},loadVideo,fail);
    } else {
        console.log("User Media not defined in this browser");
    }
    function loadVideo(stream) {
        document.getElementById("video").src = window.URL.createObjectURL(stream);
    }
    function fail(failError) {
        console.log("Failure:" + failError);
    }
</script>
</head>
<body>
    <video id="video" width="640" height="480" autoplay="true"></video>
</body>
</html>

The above code is not working locally. But the same code when used in JSFiddle is just fine.

JSFiddle link: http://jsfiddle.net/7wzw7u3u/

Please help on this issue.

Pranav
  • 446
  • 2
  • 6
  • Unlikely to be causing the issue but you have an extra semicolon after your `navigator.getUserMedia` declaration – Guy Jun 19 '15 at 09:57
  • 4
    By "local machine" do you mean accessing the code using `file:///` protocol by opening a .html file in the browser? If yes it could mean security restrictions, you should fire up a local webserver. If no and it's on http://localhost it's possible you've denied access for this domain in the past. – pawel Jun 19 '15 at 09:58
  • If it doesn't work locally, run it on a HTTP server – CodingIntrigue Jun 19 '15 at 09:58
  • Thanks guys.. it worked after installing on server – Pranav Jun 19 '15 at 13:01

0 Answers0