Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC switch back to front camera with gUM not streaming on Android/Chrome

On Samsung Galaxy S2 Android 6.0.1 + Chrome v55, when I getUserMedia on page load, the video track acquired appears live.

enter image description here

When I select the back camera from my camera select, I trigger another time my gUM with constraints to use that exact facing back cameraId, the video track is ended, I have a black rectangle instead of a stream.

enter image description here

var constraints = {
    video: {
        deviceId: {
            exact: defaultVideoDeviceId
        }
    },
    audio: true
};

gUM wrapper

function gUM(constraints, callback) {
    console.debug("WebRTC constraints", constraints);

    // Stopping streaming before starting the new one
    if (window.streams.local) {
        window.streams.local.getTracks().forEach(function(track) {
          track.stop();
        });
    }

    navigator.mediaDevices.getUserMedia(constraints)
        .then(stream => {
            console.debug("New MediaStream > Tracks", stream.getTracks());
            window.streams.local = stream;
            callback && callback(stream);
        })
        .catch(err => {
            console.log("Raised error when capturing:", err);
        });
}

If I switch back to front, it acquires a new MediaStream and it plays the video.

like image 454
zabumba Avatar asked Feb 15 '17 16:02

zabumba


1 Answers

I'm facing a similar problem too.

My test is a bit different since I'm trying to make a GUM of the back camera while I have a GUM a media stream active that is using the front camera.

I tested in several android devices and only the Xiaomi MI Mix 2 with the MIUI beta 875 with android 8.1 works. This can be because that rom uses the new camera2 android api, or because the Mi Mix 2 camera hardware allows the usage of both the back and the front camera at the same time.

The annoying thing is that sometimes, on certain devices, the GUM doesn't fail, but hangs indefinitely.

Maybe listening to the MediaStreamTrack.onended event after the track.stop() method call, can help to understand when resources are completely free so as you can try a new GUM with different constraints.

Please let me know if you discovered something.

Simone

like image 127
Simone Mazzoni Avatar answered Sep 29 '22 11:09

Simone Mazzoni