我正在使用以下代码访问可用的网络摄像头,检查focusMode是否在其功能之列,如果是,将focusMode从“连续”更改为“手动”。这种方法在Ubuntu 22.04上使用Chrome时有效,但在Windows 11中的Chrome上无效。我还没有在其他地方测试过。
class Streamer {
constructor() {
this.video = document.createElement("video")
this.canvas = document.getElementById("canvas")
this.constraints = { video: { width: { ideal: 1280}, height: { ideal: 720 } } }
}
getMedia () {
navigator.mediaDevices.getUserMedia(this.constraints)
.then((mediastream) => {
this.video.srcObject = mediastream
this.videoTrack = mediastream.getVideoTracks()[0]
this.capabilities = this.videoTrack.getCapabilities()
this.settings = this.videoTrack.getSettings()
console.log("capabilites:\n", this.capabilities)
if (this.capabilities.focusMode) {
this.videoTrack.applyConstraints({advanced:[{focusMode: "manual"}]})
console.log("focusMode set to ", this.settings.focusMode)
}
})
.catch ((err) => console.error(err))
}
1条答案
按热度按时间brc7rcf01#
将键表示为字符串解决了这个问题,并且在两个平台上都有效。