<html>
<body>
<video id="video" autoplay=""style='width:640px;height:480px'></video>
<button id='picture'>PICTURE</button>
<canvas id="canvas" width="640" height="480"></canvas>
<script>
var video=document.getElementById("video");
var context=canvas.getContext("2d");
var errocb=function(){
console.log("wrong");
}
if (navigator.getUserMedia) { // 标准的API
navigator.getUserMedia({ "video": true }, function (stream) {
video.src = stream;
video.play();
}, errocb);
} else if (navigator.webkitGetUserMedia) { // WebKit 核心的API
navigator.webkitGetUserMedia({ "video": true }, function (stream) {
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errocb);
}
</script>
</body>
</html>
以上代码在新版chrome(47.0.2526.80)可以通过本地地址访问摄像头,比如localhost/video.html。
但是不能通过IP地址访问,比如192.168.1.100/video.html。
而其它低版本的chrome工作都是正常的。
请问 这个问题如何解决呢?
https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins
I also encountered the same problem. The previous version of Chrome would pop up a prompt by default, but this version directly refused to open the camera. Although I turned on the camera in the privacy settings, there was no prompt.
Is it necessary to use HTTPS for security reasons?
I encountered this problem yesterday. I searched a lot of information on the Internet and found that it was a problem with chrome settings. Open Settings-Advanced Settings-Privacy Settings (directly to chrome://settings/content) and find the camera. Let’s talk about the default options of mobiola video. .. Just select your device (select from the drop-down box), haha
I also encountered this problem. Now Google doesn’t even support getUserMedia. Is it necessary to use https?
It seems to be a feature added by Chrome for security. You can access the camera using https connection