大家好!
目前,我正在为我的 Web 应用程序实现一个二维码扫描器。在多个设备上进行了一些测试后,我注意到我必须设置 focusMode 约束才能获得能够自动对焦环境的相机。
我可以通过直接在约束中设置 deviceId 来直接选择我的调试设备上的相机,如下所示:
let stream = await navigator.mediaDevices.getUserMedia({
video: {
deviceId: "332d34c91861f97ba8f0e11f446da4566a1803539764dd67c1dfe036ef32fd97"
}
});
我可以调用stream.getVideoTracks()[0].getCapabilities()
它来获得这些功能。
{
aspectRatio: {max: 4000, min: 0.0003333333333333333},
colorTemperature: {max: 7000, min: 2850, step: 50},
deviceId: "332d34c91861f97ba8f0e11f446da4566a1803539764dd67c1dfe036ef32fd97",
exposureCompensation: {max: 2, min: -2, step: 0.10000000149011612},
exposureMode: (2) ["continuous", "manual"],
exposureTime: {max: 1250, min: 0, step: 0},
facingMode: ["environment"],
focusMode: (3) ["manual", "single-shot", "continuous"],
frameRate: {max: 30, min: 0},
groupId: "40f2953f5fae495c7471348c844e919762a3213019b271664d220d0aa617313c",
height: {max: 3000, min: 1},
iso: {max: 4000, min: 20, step: 1},
resizeMode: (2) ["none", "crop-and-scale"],
torch: true,
whiteBalanceMode: (2) ["continuous", "manual"],
width: {max: 4000, min: 1}
}
从 Chromium 控制台日志中复制。
所以我在我的三星 Galaxy A51 上通过Brave(基于 Chromium)远程调试尝试了以下限制,但没有一个有效:
let stream = await navigator.mediaDevices.getUserMedia({
video: {
focusMode: {exact: ["continuous"]}
}
});
let stream = await navigator.mediaDevices.getUserMedia({
video: {
focusMode: "continuous"
}
});
let stream = await navigator.mediaDevices.getUserMedia({
video: {
focusMode: ["continuous"]
}
});
let stream = await navigator.mediaDevices.getUserMedia({
video: {
advanced: [{focusMode: "continuous"}]
}
});
let stream = await navigator.mediaDevices.getUserMedia({
video: {
advanced: [{focusMode: ["continuous"]}]
}
});
let stream = await navigator.mediaDevices.getUserMedia({
video: {
advanced: [{focusMode: {exact: "continuous"}}]
}
});
我不知道结构是否正确,我不太确定如何找到它。
有人知道如何使用focusMode
约束来获得具有连续对焦模式的设备吗?