1

I have created a web application with camera input. Using the html 5 tools I've managed to display a stream from a mobile device camera in a video element.

Using the video.facingMode I have implemented a switch between user and environment. This solution works well on Android Chrome and IOS Safari, but not properly on Android Firefox.

I've used remote debugging to get the error message that is thrown in the catch:

Error: DOMException: Starting videoinput failed

I have found that this issue might have been caused because there was already an active stream running, so I implemented the track.stop() function ahead of switching to a new video feed, but with no success.

Here is my basic code from my project to give some background on what I made:

function getStream() { 
    const facingMode = Session.get('facingMode');
    const constraints = {
        video: { facingMode: facingMode }
    };
    return navigator.mediaDevices.getUserMedia(constraints).
        then(gotStream).catch(handleError);
}

function gotStream(_stream) {
    stream = _stream
    videoElement.srcObject = stream;
}

function handleError(error) {
    if (stream) {
        stream.getTracks().forEach(track => {
            track.stop();
        });
    }
    console.error('Error: ', error);
}

The getStream function is run after the page is rendered and in the click event to toggle between facing modes.

Timo Frionnet
  • 474
  • 3
  • 16
  • Hi, have you find a workaround it? – Gabrielle Aug 23 '22 at 16:52
  • I transfered this question over to the [firefox github page](https://github.com/mozilla-mobile/fenix/issues/22704#issuecomment-986237647) and it got transferred to [bugzilla](https://bugzilla.mozilla.org/show_bug.cgi?id=1744807). It was stated there that the bug has been fixed, but I'm still having the same issue as before. But haven't had the time yet to try and fix it. Try and restart the conversation in those other posts if you're still experiencing the same issue and perhaps they can help you there. – Timo Frionnet Aug 23 '22 at 18:22

0 Answers0