Skip to content

Instantly share code, notes, and snippets.

@nbw
Created July 30, 2018 23:11
Show Gist options
  • Save nbw/bb5e65c3cae088e12e7587bb1bb2d303 to your computer and use it in GitHub Desktop.
Save nbw/bb5e65c3cae088e12e7587bb1bb2d303 to your computer and use it in GitHub Desktop.
In-browser Webcam Video
// Javascript
navigator.mediaDevices.getUserMedia({
video: {
width: ...,
height: ...,
frameRate: ...
}
}
).then(function(stream) {
let video = document.querySelector('video');
video.srcObject = stream;
video.onloadedmetadata = function(e) {
video.play();
};
}).catch(function(err) {
// deal with an error (such as no webcam)
});
video.addEventListener('play', function() {
// trigger business logic
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment