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

182
Visualizações
HTML Video Element sometimes can't play stream from getUserMedia in PWA mode on iOS

I'm trying to capture the camera input and play it in a video element. This code always works on desktop Chrome and Safari. On iOS it always works while in browser mode using Safari.

The problem I'm facing is it will only sometimes not work in standalone PWA mode (saved to Home Screen) for iOS. I'm not getting any errors, and it will happen seemingly randomly. I'll think I fixed it only for it to happen again hours later. Sometimes closing the app and re-opening works, sometimes it takes 10+ tries. I've tried so many different versions of the code, async, promise based, waiting for onload, canplay, etc.

The stream loads and is active (when permissions are granted), the srcObject shows as properly set, but video.play() doesn't work. I tried waiting for the play promise but sometimes it would just never resolve. The video readyState stays at 0. Sometimes the code will work fine though and the video plays the camera stream like normal.

Any help would be greatly appreciated.

navigator.mediaDevices
    .getUserMedia({
        video: {
            width: { min: 640, ideal: 1280, max: 1920 },
            height: { min: 480, ideal: 720, max: 1080 },
            facingMode: 'environment'
        },
        audio: true
    })
    .then((stream) => {
        let video = document.createElement('video');
        video.controls = true;
        video.muted = true;
        video.playsInline = true;
        video.onerror = function (e) {
            console.log(e);
        };
        video.onabort = function (e) {
            console.log(e);
        };
        console.log(stream);
        try {
            video.srcObject = stream;
        } catch (e) {
            console.log(e);
            window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
            video.src = window.URL && window.URL.createObjectURL(stream);
        }
        console.log('source: ', video.src);
        console.log('sourceObj: ', video.srcObject);
        console.log(video);
        //Dirty hack to try and debug, same result, tried waiting for play promise, play() onloaded, play() oncanplay, all same result
        //video state sometimes gets to 4, sometimes stays at 0
        let interval = setInterval(() => {
            console.log(video.isConnected);
            console.log(video.readyState);
            console.log(video);
            console.log(stream);
            //will sometimes just stay at readyState 0
            if (video.readyState === 4) {
                video.play();
                window.clearInterval(interval);
            }
        }, 500);
    });

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