how to make getUserMedia() work on all browsers

后端 未结 5 428
执念已碎
执念已碎 2020-11-29 22:39

I learn about web-rtc, it says that you can capture video-cam , i used demo , well this worked on chrome only..

when i open it on firefox i get mess

5条回答
  •  [愿得一人]
    2020-11-29 23:04

    Since Safari 11 is out, this works everywhere (tested on recent versions of Chrome, Firefox and Safari 11):

    var constraints = {audio: false, video: true};
    var video = document.querySelector("video");
    
    function successCallback(stream) {
      video.srcObject = stream;
      video.play();
    }
    
    function errorCallback(error) {
      console.log("navigator.getUserMedia error: ", error);
    }
    
    navigator.mediaDevices.getUserMedia(constraints)
      .then(successCallback)
      .catch(errorCallback);
    

提交回复
热议问题