Created
December 16, 2017 05:46
-
-
Save AhnMo/b0cd0b6416c45606bcc52d2723a1edea to your computer and use it in GitHub Desktop.
HTML5 Camera 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>HTML5 Camera example</title> | |
</head> | |
<body> | |
<video id="video" width="640" height="480" autoplay></video> | |
<script type="text/javascript"> | |
var video = document.getElementById('video'); | |
// document.querySelector('video'); | |
function hasGetUserMedia() { | |
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia || navigator.msGetUserMedia); | |
} | |
if (hasGetUserMedia()) { | |
navigator.mediaDevices.getUserMedia({ video: true }).then(stream => { | |
video.src = window.URL.createObjectURL(stream); | |
video.onloadedmetadata = function(e) { } | |
video.play(); | |
}, e => alert('Rejected, ', e)); | |
} else { | |
alert('getUserMedia() is not supported in your browser'); | |
} | |
// Reference: https://www.html5rocks.com/ko/tutorials/getusermedia/intro/ | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment