Skip to content

Instantly share code, notes, and snippets.

@agracey
Created November 7, 2022 17:28
Show Gist options
  • Save agracey/35704c28aa6293bc2c86bde6af40b7c6 to your computer and use it in GitHub Desktop.
Save agracey/35704c28aa6293bc2c86bde6af40b7c6 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Display Webcam Stream</title>
<style>
#container {
margin: 0px auto;
width: 100%;
height: 100%;
border: 0px #333 solid;
}
#videoElement {
width: 100%;
height: 100%;
background-color: #666;
}
</style>
</head>
<body>
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
var video = document.querySelector("#videoElement");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err0r) {
console.log("Something went wrong!");
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment