Answers for "how to make a camera in html"

3

how to add a camera in html

<video autoplay></video>

    <script>
    const constraints = {
      video: true,
    };
    
    const video = document.querySelector("video");
    
    navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
      video.srcObject = stream;
    });
    </script>
Posted by: Guest on December-18-2020
0

how to make a camera in html

<html>
  <head>
    <meta charset="utf-8" />
    <title>camera test.com</title>

    <style>
      #container {
        margin: 0px auto;
        width: 500px;
        height: 375px;
        border: 10px #333 solid;
      }
      #videoElement {
        width: 500px;
        height: 375px;
        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>
Posted by: Guest on September-22-2021

Code answers related to "how to make a camera in html"

Browse Popular Code Answers by Language