applyConstraints()在Linux上使用Chrome时更改focusMode,但在Windows上不更改

lp0sw83n  于 2023-03-27  发布在  Go
关注(0)|答案(1)|浏览(97)

我正在使用以下代码访问可用的网络摄像头,检查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))      
    }
brc7rcf0

brc7rcf01#

将键表示为字符串解决了这个问题,并且在两个平台上都有效。

this.videoTrack.applyConstraints({"advanced":[{"focusMode": "manual"}]})

相关问题