TypeError: 'getUserMedia' called on an object that does not implement interface MediaDevices

前端 未结 1 344
野的像风
野的像风 2021-01-01 03:03

I\'m trying to implement a webcam into a website using a video tag. It works in Chrome, but FireFox and IE return errors in the console. Anyone have any ideas why? Thank you

相关标签:
1条回答
  • 2021-01-01 03:27

    You forgot navigator.mozGetUserMedia for Firefox. IE doesn't have it (though MS Edge does).

    Also, remove navigator.mediaDevices.getUserMedia from that list since it works differently.

    My advice: Skip the prefix mess and try adapter.js, the official WebRTC polyfill. Then use navigator.mediaDevices.getUserMedia exclusively, as everything else has been deprecated.

    Example (use https fiddle in Chrome):

    navigator.mediaDevices.getUserMedia({ video: true, audio: true })
      .then(stream => video.srcObject = stream)
      .catch(e => console.log(e.name + ": "+ e.message));
    <video id="video" width="160" height="120" autoplay></video><br>
    <script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>

    0 讨论(0)
提交回复
热议问题