Skip to content

Instantly share code, notes, and snippets.

@arisetyo
Created November 29, 2012 04:09
Show Gist options
  • Save arisetyo/4166764 to your computer and use it in GitHub Desktop.
Save arisetyo/4166764 to your computer and use it in GitHub Desktop.
webcam access
<video autoplay></video>
<script type="text/javascript">
function hasGetUserMedia() {
// Note: Opera is unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
if(hasGetUserMedia()) console.log("Good to go!");
else alert("boohoo... getUserMedia() is not supported in your browser.. :(");
var onFailSoHard = function(e) { console.log("oh no you don't!", e) };
// example: using Webkit vendor
navigator.webkitGetUserMedia({video: true, audio: false}, function(localMediaStream) {
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(localMediaStream);
}, onFailSoHard);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment