Switch camera using MediaDevices.getUserMedia () in webrtc

I am trying navigator.MediaDevices.getUserMedia () webrtc to switch the deviceโ€™s camera during a call. This functionality works fine on a desktop browser, but on mozilla android it does not work. Here is my code that I use.

var front=false; var myConstraints = { video: { facingMode: (front? "user" : "environment")} }; navigator.mediaDevices.getUserMedia(myConstraints).then(function(stream) { } 

any idea about this ??

+5
source share
3 answers

Phone hardware usually does not allow front and rear cameras to be opened at the same time. Change your code to stop() existing stream before receiving another camera.

See my answer to a similar question for a working example.

+4
source

use the latest adapter.js and see if a NotReadableerror occurs, it seems that Chrome for android cannot release the front camera equipment to switch to the rear using stream.getVideoTracks () [0] .stop (); I think it might be a mistake

+1
source
 Webcam.set({ width: 490, height: 450, image_format: 'jpeg', jpeg_quality: 90, constraints: { facingMode: { exact: 'environment' } } }); 

This code works for all browsers.

 constraints: {facingMode: { exact: 'environment' }} 

Above the line is responsible for opening the rear camera, set limits: null to open the front camera. You can also customize this code by using the "switch camera" method

+1
source

Source: https://habr.com/ru/post/1260593/


All Articles