淘先锋技术网

首页 1 2 3 4 5 6 7

使用mediaDevices.getUserMedia方法,iOS环境前后摄像头都没有问题,但安卓环境无论怎么设置,都是调用前置摄像头。

navigator.mediaDevices.enumerateDevices().then(function (devices) {

var userMediaConstraints = {

audio: false,

video: {

facingMode: {exact : 'environment'},

}

}

navigator.mediaDevices.getUserMedia(userMediaConstraints).then(function success(stream) {

let status = true;

LayaAir3D.video.srcObject = stream;

LayaAir3D.video.play();

var interval = setInterval(function () {

if (!LayaAir3D.video.videoWidth) {

return;

}

laya.utils.Browser.document.body.appendChild(LayaAir3D.video);

clearInterval(interval);

}, 1000 / 50);

});

}).catch(function (error) {

onError({

message: error.message

});

});