简体   繁体   English

无法访问网络摄像头(JavaScript)?

[英]Not able to access webcam (Javascript)?

I am learning to use getUserMedia() to access webcam in javascript. 我正在学习使用getUserMedia()来访问javascript中的网络摄像头。 But i am getting an error - Not allowed to load local resource: blob:null/3485f5b8-46c1-4a40-946a-8de2588720f0 但我遇到错误- Not allowed to load local resource: blob:null/3485f5b8-46c1-4a40-946a-8de2588720f0

I searched on the net but they said that i needed an https connection or something, file urls are not allowed, but i didn't completely understand what is going on. 我在网上搜索,但他们说我需要一个https连接或其他东西,不允许使用文件url,但我不完全了解发生了什么。

the code is - 该代码是-

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta content="stuff, to, help, search, engines, not" name="keywords"> <meta content="What this page is about." name="description"> <meta content="Display Webcam Stream" name="title"> <title>Display Webcam Stream</title> <style> #container { margin: 0px auto; width: 500px; height: 375px; border: 10px #333 solid; } #videoElement { width: 500px; height: 375px; background-color: #666; } </style> </head> <body> <div id="container"> <video autoplay="true" id="videoElement"> </video> </div> <script> var video = document.querySelector("#videoElement"); navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia; if (navigator.getUserMedia) { navigator.getUserMedia({video: true}, handleVideo, videoError); } function handleVideo(stream) { video.src = window.URL.createObjectURL(stream); } function videoError(e) { // do something console.log("error"); } </script> </body> </html> 

For privacy and security reasons, Google decided to allow certain features only to "secure" origins, ie getUserMedia is only available on websites using HTTPS. 出于隐私和安全方面的考虑,Google决定仅允许某些功能来“保护”来源,即getUserMedia仅在使用HTTPS的网站上可用。

For more of the reasoning you can read their article on this . 有关更多原因,您可以阅读他们对此的文章

Your code is fine and works fine when used via HTTPS, the easiest way to do that during development is probably jsbin . 您的代码很好,通过HTTPS使用时也可以正常工作,在开发过程中最简单的方法可能是jsbin

If you are trying at chromium, chrome at file: protocol, close all chromium, chrome instances, then re-launch chromium, chrome with --allow-file-access-from-files flag to allow browser access to files at local filesystem. 如果您尝试使用Chrome: file:协议上的chrome,请关闭所有Chrome,chrome实例,然后使用--allow-file-access-from-files标志重新启动Chrome,chrome,以允许浏览器访问本地文件系统中的文件。 See also Jquery load() only working in firefox? 另请参阅Jquery load()仅在firefox中工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM