getUserMedia() not supported in chrome

前端 未结 3 1844
既然无缘
既然无缘 2020-11-30 12:16

I am trying to access my webcam using the getUserMedia() using my own website that run using my own ip address.

it was working fine until i tried my website again. i

3条回答
  •  借酒劲吻你
    2020-11-30 13:03

    Chrome finally implemented the new navigator.mediaDevices.getUserMedia() method, but they added a security that will prevent the calls from unsecure address (non https or non localhost servers)

    You will call it like this :

    var video = document.querySelector('video');
    navigator.mediaDevices.getUserMedia({video:true}).then(function(mediaStream){
        window.stream = mediaStream;
        video.src = URL.createObjectURL(mediaStream);
        video.play();
    });
    

    Or you can use the official webRTC polyfill adpater.js library.

    var constraints = { video: true, audio: true };
    
    navigator.mediaDevices.getUserMedia(constraints)
      .then(stream => video.srcObject = stream)
      .catch(e => console.error(e));
    

提交回复
热议问题