Hello everybody!
Currently, I'm working on the implementation of a qr-code scanner for my web application. After some tests on multiple devices, I've noticed that I have to set the focusMode constraint to get a camera that has the ability to auto-focus the environment.
I'm able to directly select the camera on my debug device by directly setting the deviceId in the constraints like this:
let stream = await navigator.mediaDevices.getUserMedia({
video: {
deviceId: "332d34c91861f97ba8f0e11f446da4566a1803539764dd67c1dfe036ef32fd97"
}
});
Which I can call stream.getVideoTracks()[0].getCapabilities()
on to get the capabilities.
{
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}
}
Copied from the Chromium console log.
So I tried the following constraints via Brave (based on Chromium) remote debugging on my Samsung Galaxy A51, of which none worked:
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"}}]
}
});
I don't know if the structure is correct and I'm not quite sure how to find that out.
Does anybody know how to use the focusMode
constraint to get a device that has a continuous focus mode?