Skip to content

Instantly share code, notes, and snippets.

@ToJans
Forked from tomayac/getUserMedia.html
Created December 8, 2011 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToJans/1446486 to your computer and use it in GitHub Desktop.
Save ToJans/1446486 to your computer and use it in GitHub Desktop.
navigator.getUserMedia Test
<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