下面是我的代码,我正在使用下面的插件制作qr代码扫描程序(用于移动设备)
支持几乎Chrome,Mozilla FireFox,Opera,移动设备中的MS EDGE,但我试图在所有最新设备中实现默认浏览器(android-主要是三星设备)也可以使用它而不是后置摄像头(后置摄像头) )它采用前置摄像头(面向用户),因为我根据开发人员Mozilla组编写了代码
{ facingMode: { exact: "environment" } }
这是我的代码
navigator.mediaDevices.getUserMedia({ video: { facingMode: { exact: "environment" } } }).then(function(stream) {
video.srcObject = stream;
video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen
video.play();
requestAnimationFrame(tick);
localStream = stream;
})
.catch(function(err) {
console.log(err);
/* handle the error */
});
答案 0 :(得分:0)
您可以使用facingMode分别为前置或后置摄像头选择“用户”或“环境”。
使用
anony.AnonymizeInPlace(testfile);
如上所述,您已尝试通过删除navigator.getUserMedia({video: { facingMode: { exact: "environment" } } },
successCallback, errorCallback);
来尝试拨打以下电话:
exact
来自https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
答案 1 :(得分:0)
最后,我找到了解决问题的方法,您需要使用navigator.mediaDevices.enumerateDevices并获取设备ID并将其分配给getUserMedia,但可能会引起浏览器兼容性问题,我也使用条件< / p>
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
var videoDevices = [0,0];
var videoDeviceIndex = 0;
devices.forEach(function(device) {
if(device.kind == "videoinput") {
videoDevices[videoDeviceIndex++] = device.deviceId;
}
});
var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if(navigator.userAgent.indexOf("Firefox") !== -1){
console.log("Firefox")
var constraints = {facingMode: videoDevices[1] };
} else if(isSafari && iOS){
console.log("Safari")
var constraints = { facingMode: { exact: "environment" } };
} else {
console.log("other browser")
var constraints = {deviceId: { exact: videoDevices[1] } }
}
return navigator.mediaDevices.getUserMedia({ video: constraints });
}).then(function(stream) {
video.srcObject = stream;
video.setAttribute("playsinline", true);
video.play();
})
.catch(function(err) {
//use this to display the error
console.log(err);
});
答案 2 :(得分:0)
应该(第18行):
var constraints = {facingMode: videoDevices[1] };
是
var constraints = {deviceID: {exact: videoDevices[1]} };
ps:已验证三星S4仍然存在该问题