我在用QuaggaJS打开正确的相机时遇到了问题,在一些设备上,自拍相机是打开的,但在其他设备上,背面的相机是打开的。如何将标准摄像头设置为对后置摄像头开放?因为用你的自拍相机扫描条形码并不那么容易.
这就是我到目前为止所尝试的:
inputStream: {
type : "LiveStream",
constraints: {
width: {min: 640},
height: {min: 480},
facingMode: "environment",
aspectRatio: {min: 1, max: 2}
}
},在初始化过程中,我已将面向模式设置为环境,但自拍相机仍处于打开状态.
也许在chrome中也有一个设置,你可以在那里改变它?但我可以找到它.
发布于 2019-03-24 04:10:35
我在一些智能手机上正在做的事情和工作如下:
var backCamID = null;
var last_camera = null;
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
if( device.kind == "videoinput" && device.label.match(/back/) !== null ){
backCamID = device.deviceId;
}
if( device.kind === "videoinput"){
last_camera = device.deviceId;
}
});
if( backCamID === null){
backCamID = last_camera;
}
})
.catch(function(err) { });并在约束中放置摄像机ID而不是facingMode
deviceId: backCamID发布于 2019-03-01 21:22:50
因为QuaggaJS只允许使用“环境”或“用户”作为facingMode。您可以创建一个选择元素来选择其中一个元素。
HTML:
<select id="videoSource">
<option value="enviroment" selected>Back</option>
<option value="user">Front</option>
</select>JS:
var _scannerIsRunning = false; // set to true at the end of startScanner()
document.getElementById("videoSource").addEventListener("change", function () {
if (_scannerIsRunning) {
Quagga.stop();
}
startScanner(); // put your init function here
}, false);将facingMode替换为select的值
facingMode: document.getElementById("videoSource").valuehttps://stackoverflow.com/questions/54323699
复制相似问题