Garmaine Staff asked 2 years ago

I can't figure this out properly, or if it's even possible to switch cameras.

I've tried stopping the video track before calling getUserMedia a second time, hoping that stopping the video track would turn the front camera off so the rear camera can turn on, but it just doesn't work.

var oldStream; // the old stream from getUserMedia

Function SwitchCamera() {


    navigator.mediaDevices.getUserMedia({audio: true, video: {deviceId: 'rear camera device ID'}).then(function(newStream){

        // this never runs

        console.log(err); // Cannot connect camera


Is there something else that I need to do to switch cameras on mobile? Is this even possible?