Skip to content

Instantly share code, notes, and snippets.

@sheminusminus
Created March 31, 2018 08:32
Show Gist options
  • Save sheminusminus/70549332d926ae0ea93f4c31764a3920 to your computer and use it in GitHub Desktop.
Save sheminusminus/70549332d926ae0ea93f4c31764a3920 to your computer and use it in GitHub Desktop.
webcam access
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>cam</title>
</head>
<body>
<script>
const video = document.createElement('video');
video.height = '500';
video.width = '500';
video.autoplay = 'true';
document.body.appendChild(video);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true}, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
}
function videoError(e) {
console.log(e);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment