Skip to content

Instantly share code, notes, and snippets.

@tomayac
Created December 6, 2011 16:44

Revisions

  1. tomayac revised this gist Dec 6, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion getUserMedia.html
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,9 @@
    <h1>See yourself?</h1>
    If your browser supports
    <span style="font-family:monospace;">navigator.getUserMedia()</span>
    you should see yourself below.
    you should see yourself below. If you don't see yourself, try
    downloading the
    <a href="http://labs.opera.com/news/2011/10/19/">Opera Labs</a> browser.
    <div>
    <video id="sourcevid" autoplay controls></video>
    </div>
  2. @invalid-email-address Anonymous created this gist Dec 6, 2011.
    36 changes: 36 additions & 0 deletions getUserMedia.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <html>
    <head>
    <title>navigator.getUserMedia() Demo</title>
    </head>
    <body>
    <h1>See yourself?</h1>
    If your browser supports
    <span style="font-family:monospace;">navigator.getUserMedia()</span>
    you should see yourself below.
    <div>
    <video id="sourcevid" autoplay controls></video>
    </div>
    <script type="application/javascript">
    (function() {
    // Assign the <video> element to a variable
    var video = document.getElementById('sourcevid');

    // Replace the source of the video element with the stream from the camera
    if (navigator.getUserMedia) {
    navigator.getUserMedia('video', successCallback, errorCallback);
    function successCallback(stream) {
    video.src = stream;
    }
    function errorCallback(error) {
    console.error('An error occurred: [CODE ' + error.code + ']');
    return;
    }
    } else {
    console.log('Native web camera streaming (getUserMedia) is not ' +
    'supported in this browser.');
    return;
    }
    })();
    </script>
    </body>
    </html>