Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switch camera using MediaDevices.getUserMedia() in webrtc

I am trying navigator.MediaDevices.getUserMedia() webrtc to switch the device camera during the call. This functionality is working fine on the desktop browser but on mozilla android it is not working. Here is my code that i am using .

var front=false;

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

}

any idea about this??

like image 692
john Avatar asked Nov 30 '16 14:11

john


2 Answers

Phone hardware typically doesn't allow opening both the front and back camera at the same time. Change your code to stop() the existing stream before getting the other camera.

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

like image 187
jib Avatar answered Oct 05 '22 00:10

jib


use the last version of adapter.js and see if NotReadableerror is happening, it seems that Chrome for android cannot release front camera hardware to switch to rear by using stream.getVideoTracks()[0].stop(); I think it could be a bug

like image 36
carloseme Avatar answered Oct 04 '22 23:10

carloseme