【问题标题】:Webcam Access for Custom Filters:vTypeError: URL.createObjectURL: Argument 1 is not valid for any of the 1-argument overloads自定义过滤器的网络摄像头访问:vTypeError:URL.createObjectURL:参数 1 对任何 1 参数重载均无效
【发布时间】:2022-08-05 21:29:18
【问题描述】:

我目前正在尝试通过 WesBos 的 30 天 JavaScript 来提高我的 JS 技能。 (如果真的很有趣!)我目前在第19天,这是关于使用JS访问网络摄像头,然后使用CSS添加效果。

我成功地设置了本地服务器,到目前为止,这是我的代码:

 function getVideo() {
        navigator.mediaDevices.getUserMedia({video: true, audio: false})
        .then(localMediaStream => {
            console.log(localMediaStream);
            video.src = window.URL.createObjectURL(localMediaStream);
            video.play();
        })
        .catch(err => {
            console.error(`Web camera access is not enabled. To resolve, reload the page and allow 
    access.`, err);
        });
    }
    
    getVideo();

但是,我收到此错误:

    TypeError: URL.createObjectURL: Argument 1 is not valid for any of the 1-argument overloads.
    getVideo http://localhost/19-webcam-fun/scripts.js:12
    promise callback*getVideo http://localhost/19-webcam-fun/scripts.js:10
    <anonymous> http://localhost/19-webcam-fun/scripts.js:27

Idk 如果这有帮助,但 console.log(localMediaStream) 会导致以下结果:


    MediaStream { id: \"{97c3d27e-404e-4d14-b1d2-2a9ebbf09137}\", active: true, onaddtrack: null, 
    onremovetrack: null }
    ​
    active: true
    ​
    id: \"{97c3d27e-404e-4d14-b1d2-2a9ebbf09137}\"
    ​
    onaddtrack: null
    ​
    onremovetrack: null
    ​
    <prototype>: MediaStreamPrototype { getAudioTracks: getAudioTracks(), getVideoTracks: 
    getVideoTracks(), getTracks: getTracks(), … }

如果有人能帮助我更好地理解这一点,我将不胜感激!谢谢!

    标签: javascript getusermedia createobjecturl


    【解决方案1】:

    尝试:

    video.srcObject = localMediaStream;

    如果你在火狐上

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      相关资源
      最近更新 更多