Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
Multiple USB Webcams in a single HTML page using JavaScript

I'm trying to show up to 4 different USB Webcams in a single HTML page using JavaScript, here's the code I made:

<html>
<body>

<style>
    .webcamBox {
        width: 500px;
        height: 350px;
        background-color: grey;
    }
</style>

    <video autoplay="true" id="webcam1" class="webcamBox"></video>
    <video autoplay="true" id="webcam2" class="webcamBox"></video>
    <video autoplay="true" id="webcam3" class="webcamBox"></video>
    <video autoplay="true" id="webcam4" class="webcamBox"></video>

</body>
</html>

<script>

if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  console.log("enumerateDevices() not supported.");
}

var i = 0 ;
var webcam = document.getElementsByClassName("webcamBox");

navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    if (device.kind == "videoinput") {          
        if (navigator.mediaDevices.getUserMedia) {
            console.log("ID: "+device.deviceId);
            navigator.mediaDevices.getUserMedia({  
                video: { deviceId: { exact: device.deviceId } }
            })
            .then(function (stream) {
                console.log(i+"] Webcam is working") ;
                webcam[i].srcObject = stream;
                i++ ;
            })
            .catch(function (err0r) {
                console.log(i+"] Webcam error") ;
                i++ ;
            });
        }   
    }
  });
})
.catch(function(err) {
  console.log(err.name + ": " + err.message);
});

</script>

The only browser able to find and print the device id is Firefox, this code doesn't work on Chrome.

Everything seems to work, but I can show only 2 webcams at the same time. I tried to change USB webcams but nothing's changed, Firefox shows different webcams but always just 2 at the same time.

Are there some limitations, maybe something related to performance, or am i doing something wrong?

How can i make this work?

Thanks in advance

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda