Created
September 6, 2012 01:21
-
-
Save thisgeek/3649563 to your computer and use it in GitHub Desktop.
navigator.getUserMedia() demo
This file contains 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>HTML5 Webcam Test</title> | |
</head> | |
<body> | |
<h1><code>navigator.getUserMedia()</code></h1> | |
<video autoplay controls></video> | |
<p> | |
<button id="capture">Capture video</button> | |
<button id="stop">Stop</button> | |
</p> | |
<script src="webvideo.js"></script> | |
</body> | |
</html> |
This file contains 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
(function() { | |
var video, localMediaStream; | |
window.URL = window.URL || window.webkitURL; | |
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia || navigator.msGetUserMedia; | |
video = document.querySelector('video'); | |
document.querySelector('button#capture').addEventListener('click', function () { | |
navigator.getUserMedia({audio: true, video: true}, function(stream) { | |
localMediaStream = stream; | |
video.src = window.URL.createObjectURL(stream); | |
}, function(e) { | |
console.log(e); | |
}); | |
}); | |
document.querySelector('button#stop').addEventListener('click', function(e) { | |
video.pause(); | |
localMediaStream.stop(); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment