Skip to content

Instantly share code, notes, and snippets.

@vrcosta
Created January 15, 2017 19:42
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 vrcosta/ccaaccc808eaa6f10bb96d190e7220ae to your computer and use it in GitHub Desktop.
Save vrcosta/ccaaccc808eaa6f10bb96d190e7220ae to your computer and use it in GitHub Desktop.
var webcamStream = null,
video = document.getElementById('player');
// try go get them all
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
document.getElementById('play').addEventListener('click', function(e) {
navigator.getUserMedia({
video: true
},
function(stream) {
webcamStream = stream;
// Stream the data
// webcamStream is a blob which you can get an URL for with createObjectURL
video.src = window.URL.createObjectURL(webcamStream);
video.play();
},
function(error) {
console.log('Video capture error: ' + error.code);
});
});
document.getElementById('stop').addEventListener('click', function(e) {
video.pause();
webcamStream.stop();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment