switch camera using MediaDevices.getUserMedia() in webrtc

自古美人都是妖i 提交于 2019-11-27 07:48:30

问题


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??


回答1:


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.




回答2:


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




回答3:


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

                }   
    });

This code is working for all browsers.

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

Above line is responsible to open rear camera, set constraints : null to open front camera. you can also adjust this code by implementing "switch camera" button method



来源:https://stackoverflow.com/questions/40891009/switch-camera-using-mediadevices-getusermedia-in-webrtc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!