search

Home  >  Q&A  >  body text

html5 - 新版chrome不能访问摄像头

<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工作都是正常的。
请问 这个问题如何解决呢?

迷茫迷茫2787 days ago1209

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 12:05:07

    https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 12:05:07

    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?

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 12:05:07

    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

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 12:05:07

    I also encountered this problem. Now Google doesn’t even support getUserMedia. Is it necessary to use https?

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 12:05:07

    It seems to be a feature added by Chrome for security. You can access the camera using https connection

    reply
    0
  • Cancelreply