Last active
August 29, 2015 14:10
-
-
Save meistermeier/7107b128166fe54e3e4c to your computer and use it in GitHub Desktop.
simple in browser webcam capturing
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 lang="en"> | |
<meta charset="UTF-8"> | |
<title>Simple Video Capture</title> | |
<style type="text/css"> | |
#videoElement { | |
width: 70%; | |
} | |
</style> | |
</head> | |
<body> | |
<video id="videoElement" autoplay></video> | |
<div id="log"></div> | |
<script type="text/javascript"> | |
(function () { | |
var errorCallback = function (error) { | |
document.getElementById('log').innerText = "Error while capturing: " + error.code; | |
}; | |
var video = {video: true}; | |
var videoElement = document.getElementById("videoElement"); | |
if(navigator.getUserMedia) { | |
navigator.getUserMedia(video, function(stream) { | |
videoElement.src = stream; | |
videoElement.play(); | |
}, errorCallback); | |
} else if(navigator.webkitGetUserMedia) { | |
navigator.webkitGetUserMedia(video, function(stream){ | |
videoElement.src = window.webkitURL.createObjectURL(stream); | |
videoElement.play(); | |
}, errorCallback); | |
} | |
else if(navigator.mozGetUserMedia) { | |
navigator.mozGetUserMedia(video, function(stream){ | |
videoElement.src = window.URL.createObjectURL(stream); | |
videoElement.play(); | |
}, errorCallback); | |
} | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment