在 Aurelia 中:如何将网络摄像头的输出绑定到视频元素的 `srcObject` 属性?

问题描述 投票:0回答:1
javascript aurelia
1个回答
0
投票

好吧,我明白了。我必须使用

ref
属性来引用
attached
处理程序中的 HTML 对象,并且我需要删除
if.bind
,因为它阻止
ref
属性定义
this.video
。然后,我可以从
设置
video.srcObject

HTML

<video id="video" ref="video">Video stream not available.</video>

JS

    attached() {
        let video = this.video

        navigator.mediaDevices
            .getUserMedia({ video: true, audio: false })
            .then((stream) => {
                video.srcObject = stream
                video.play()
            })
            .catch((err) => {
                console.error(`An error occurred:`, err)
            })
    }

© www.soinside.com 2019 - 2024. All rights reserved.