Created
July 30, 2018 23:11
-
-
Save nbw/bb5e65c3cae088e12e7587bb1bb2d303 to your computer and use it in GitHub Desktop.
In-browser Webcam Video
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
// 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