Created
June 26, 2014 04:07
-
-
Save jbonhag/1a9336b5e5e6050b7b76 to your computer and use it in GitHub Desktop.
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
<video style="display:none;" autoplay></video> | |
<img src=""> | |
<canvas width="800" height="600" style="display:none;"></canvas> | |
<script> | |
var video = document.querySelector('video'); | |
var canvas = document.querySelector('canvas'); | |
var ctx = canvas.getContext('2d'); | |
var localMediaStream = null; | |
var errorCallback = function(e) { | |
console.log('Reeeejected!', e); | |
}; | |
navigator.getUserMedia = navigator.getUserMedia || | |
navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia || | |
navigator.msGetUserMedia; | |
function snapshot() { | |
if (localMediaStream) { | |
console.log('snap'); | |
ctx.drawImage(video, 0, 0); | |
var img = new Image(); | |
img.src = canvas.toDataURL('image/png'); | |
document.body.insertBefore(img, document.body.firstChild); | |
} | |
} | |
setInterval(snapshot, 1000); | |
navigator.getUserMedia({video: true}, function(stream) { | |
var video = document.querySelector('video'); | |
video.src = window.URL.createObjectURL(stream); | |
localMediaStream = stream; | |
}, errorCallback); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment