代码之家  ›  专栏  ›  技术社区  ›  Akshay komarla

在最新浏览器中引发getusermedia DevicesNotFoundError

  •  2
  • Akshay komarla  · 技术社区  · 7 年前

    我已经在WebRtc上使用getUserMedia()有一段时间了,但自从浏览器的最新更新以来,我一直无法使用它。在以前的版本中效果很好。

    enter image description here

    受影响浏览器的版本 Firefox-57.0.4, 铬-63.0.3239.132

    示例代码:

    navigator.getUserMedia({ "audio": true, "video": false }, function (stream) {
      console.log(stream);
      localStream = stream;
    
    },logError);
    

    如果有人在google示例代码中遇到此错误,请检查此项 https://webrtc.github.io/samples/src/content/getusermedia/gum/

    是否有解决此问题的方法?需要帮助。 谢谢

    1 回复  |  直到 7 年前
        1
  •  8
  •   Akshay komarla    7 年前

    我找到了解决办法。在新版本中,当我们指定约束时 { audio: true, video: true } 无论哪种情况,我们都指定需要存在相应的硬件。否则它会抛出 DevicesNotFoundError .

    这是我使用的代码。我在本地机器上没有摄像头,所以指定的视频是假的。

    navigator.mediaDevices.getUserMedia({ audio: true, video: false})
    .then(function(stream) {
       /* use the stream */ 
    })
    .catch(function(err) {
       /* handle the error */
    });