Skip to content

Instantly share code, notes, and snippets.

@AhnMo
Created December 16, 2017 05:46
Show Gist options
  • Save AhnMo/b0cd0b6416c45606bcc52d2723a1edea to your computer and use it in GitHub Desktop.
Save AhnMo/b0cd0b6416c45606bcc52d2723a1edea to your computer and use it in GitHub Desktop.
HTML5 Camera Example
<!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