我在页面上具有来自摄像机的流的视频标签,我想更改focusMode和focusDistance。
问题是我可以在navigator.mediaDevices.getSupportedConstraints()中看到focusMode和focusDistance,但是我没有看到它们,所以我尝试将它们获取并从实际视频中进行更改,就像这样:
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => handleSuccess(stream, canPlay))
.catch(e => console.log(e))
function handleSuccess(stream, canPlay, video) {
const video = document.getElementById('video');
video.srcObject = stream
const track = stream.getVideoTracks()[0];
track.getCapabilities() // doesn't return focusMode or focusDistance.
}
总的来说,我想做这样的事情:
function onCapabilitiesReady(capabilities) {
if (!capabilities.focusDistance) {
return;
} else {
track.applyConstraints({
advanced : [{focusMode: "manual", focusDistance: 0.3}]
});
}
}