Created
January 15, 2017 19:42
-
-
Save vrcosta/ccaaccc808eaa6f10bb96d190e7220ae to your computer and use it in GitHub Desktop.
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
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