问题
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 had tried the other demo site and the error given was getUserMedia is not supported.
Chrome version v47.0.2526.80m 32bits
I am able to access the webcam if i enter localhost instead of my ipadress. it also work in firefox.
回答1:
Chrome is requiring secure origins (HTTPS) for getUserMedia.
Starting with Chrome 47, getUserMedia() requests are only allowed from secure origins: HTTPS or localhost.
https://developers.google.com/web/updates/2015/10/chrome-47-webrtc?hl=en
回答2:
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));
来源:https://stackoverflow.com/questions/34215937/getusermedia-not-supported-in-chrome