Download APP

All In One APP (Download For)

Copyright © 2024
Mritunjoy Tech (OPC) Pvt Ltd

Mritunjoy Mushahary

How to open webcam in HTML and Javascript?

Hi I would like to know how to open webcam on browser using HTML and Javascript.

1 Answers

28 Nov 2024

Read Answers

Share

Mritunjoy Mushahary

Here is the code:

index.html

<!DOCTYPE html>
<html>
<head> 
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div id="videos">
        <video class="video-player" id="user-1" autoplay playsinline></video>
        <video class="video-player" id="user-2" autoplay playsinline></video>
    </div>

    <script src="main.js"></script>
    
</body>

</html>

main.js

let localStream;
let remoteStream;

let init = async () => {
    localStream = await navigator.mediaDevices.getUserMedia({video:true,audio:false})
    document.getElementById('user-1').srcObject = localStream
}

init()


style.css


#videos{

display: grid;

grid-template-columns: 1fr 1fr;

gap:2em;

}

.video-player{

background-color: black;

width: 100%;

}

Best Answer

Please Login to Read More.

logo
  • Join and Learn by reading others Q&A and Books.
  • Join and Get Updates about activities nearby you.
  • Join and Take your Business Online For FREE.
  • Join and Meet with People nearby you.

Home

Market

Services

Courses

Search

More