Created
July 4, 2016 18:53
-
-
Save rlemon/4c1d8988a320cc664930f7d9585dc339 to your computer and use it in GitHub Desktop.
html webcam capture example
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 id="video"></video> |
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
// mediaDevices.getUserMedia is not implemented everywhere. this is a shit filler | |
const fillGetUserMedia = _ => { | |
return function getUserMedia(constraints) { | |
const gum = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; | |
if( !gum ) return Promise.reject('your browser is a pos'); | |
return new Promise( (resolve, reject) => { | |
gum.call(navigator, constraints, resolve, reject); | |
}); | |
} | |
}; | |
if( !( 'mediaDevices' in navigator ) ) navigator.mediaDevices = {}; | |
if( !( 'getUserMedia' in navigator.mediaDevices ) ) navigator.mediaDevices.getUserMedia = fillGetUserMedia(); | |
const constraints = { | |
audio: true, | |
video: true, | |
height: 1280, | |
width: 720 | |
}; | |
navigator.mediaDevices.getUserMedia(constraints).then(stream => { | |
video.src = URL.createObjectURL(stream); | |
video.onloadedmetadata = _ => { | |
video.play(); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment