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() {
oldStream.getVideoTracks()[0].stop();
navigator.mediaDevices.getUserMedia({audio: true, video: {deviceId: 'rear camera device ID'}).then(function(newStream){
// this never runs
}).catch(function(err){
console.log(err); // Cannot connect camera
});
}
Is there something else that I need to do to switch cameras on mobile? Is this even possible?
Please login or Register to submit your answer