Created
December 6, 2011 16:44
-
-
Save tomayac/1438890 to your computer and use it in GitHub Desktop.
navigator.getUserMedia Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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. 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> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment