Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何允许自动访问网络摄像头_Javascript_Html_Webcam - Fatal编程技术网

Javascript 如何允许自动访问网络摄像头

Javascript 如何允许自动访问网络摄像头,javascript,html,webcam,Javascript,Html,Webcam,我正在尝试使用以下JS代码开发一个可以访问我的网络摄像头的网页: (function( $ ){ $.fn.html5_qrcode = function(qrcodeSuccess, qrcodeError, videoError) { 'use strict'; var height = this.height(); var width = this.width(); if (height == null) { height = 250; } if (width == null)

我正在尝试使用以下JS代码开发一个可以访问我的网络摄像头的网页:

(function( $ ){

$.fn.html5_qrcode = function(qrcodeSuccess, qrcodeError, videoError) {
'use strict';

var height = this.height();
var width = this.width();

if (height == null) {
  height = 250;
}

if (width == null) {
  width = 300;
}

var vidTag = '<video id="html5_qrcode_video" width="' + width + 'px" height="' +   height   + 'px"></video>' 
var canvasTag = '<canvas id="qr-canvas" width="' + (width - 2) + 'px" height="' + (height - 2) + 'px" style="display:none;"></canvas>' 

this.append(vidTag);
this.append(canvasTag);



var video = $('#html5_qrcode_video').get(0);
var canvas;
var context; 
var localMediaStream;

$('#qr-canvas').each(function(index, element) {
  canvas = element;
  context = element.getContext('2d');   
});



var scan = function() {
  if (localMediaStream) {
    context.drawImage(video, 0, 0, 307,250);

    try {
      qrcode.decode();
    } catch(e) {
      qrcodeError(e);
    }

    setTimeout(scan, 500);

  } else {
    setTimeout(scan,500);
  }
}//end snapshot function

window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia ||      navigator.mozGetUserMedia || navigator.msGetUserMedia;

var successCallback = function(stream) {
    video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
    localMediaStream = stream;

    video.play();
    setTimeout(scan,1000);
}

// Call the getUserMedia method with our callback functions
if (navigator.getUserMedia) {
    navigator.getUserMedia({video: true}, successCallback, videoError);
} else {
    console.log('Native web camera streaming (getUserMedia) not supported in this  browser.');
    // Display a friendly "sorry" message to the user
}

qrcode.callback = qrcodeSuccess;

}; // end of html5_qrcode
})( jQuery );
(函数($){
$.fn.html5\u qrcode=函数(qrcodeSuccess、qrcodeError、videoError){
"严格使用",;
var height=this.height();
var width=this.width();
如果(高度==null){
高度=250;
}
如果(宽度==null){
宽度=300;
}
var vidTag=''
var canvasTag=“”
这个.append(vidTag);
本附录(canvasTag);
var video=$('#html5_qrcode_video')。获取(0);
var帆布;
var语境;
var-localMediaStream;
$(“#qr画布”)。每个(函数(索引,元素){
画布=元素;
context=element.getContext('2d');
});
var scan=函数(){
if(本地媒体流){
drawImage(视频,0,0,307250);
试一试{
qrcode.decode();
}捕获(e){
qrcoderror(e);
}
设置超时(扫描,500);
}否则{
设置超时(扫描,500);
}
}//结束快照功能
window.URL=window.URL | | | | | | | window.mozURL | | | window.msURL;
navigator.getUserMedia=navigator.getUserMedia | | navigator.webkitGetUserMedia | | navigator.mozGetUserMedia | | navigator.msGetUserMedia;
var successCallback=函数(流){
video.src=(window.URL&&window.URL.createObjectURL(stream))| | stream;
localMediaStream=stream;
video.play();
设置超时(扫描,1000);
}
//使用回调函数调用getUserMedia方法
if(navigator.getUserMedia){
getUserMedia({video:true},successCallback,videoError);
}否则{
console.log('本机网络摄像头流媒体(getUserMedia)在此浏览器中不受支持');
//向用户显示友好的“抱歉”消息
}
qrcode.callback=qrcodeSuccess;
};//html5代码的结尾
})(jQuery);

我运行我的应用程序,它可以工作,但在打开摄像头之前,我已经有了访问权限窗口,因此我想知道是否有任何解决方案允许我在未经询问的情况下打开网络摄像头。

显然,您不能在未经同意的情况下打开人们的网络摄像头并开始录制


通过设置策略,您可以在本地打开特定功能,而无需向Chrome等供应商询问。我在评论中添加了一些链接

否。这是不可能的,我很高兴获得更多信息,google for'sandbox javascript'@user1444393好吧=]对于大多数部分,这是不可能的,可能在本地与特定供应商合作。例如,请参见中的设置chrome://policy ,我希望这就是你当时在哪里寻找的。对不起,如果我是鲁迪人,你可以在这里找到一个示例文件,它允许为网络摄像头预设许可。您需要编辑//“VideoCaptureAllowedUrls”:false和//“VideoCaptureAllowedUrls:[”,“http://[*.]example.edu/”]我提到它将是“我的网络摄像头”,而不是单个摄像头D此外,对于开发二维码扫描应用程序的开发人员来说,你认为每次我启动手机应用程序时,我都会问用户的迁移情况吗?@user1444393在浏览器中做某件事和通过本机手机应用程序做某件事有很大区别,本机应用程序通常在安装时收集权限。但是正如我提到的,如果你只想在本地设置permission,这可以在Chrome中完成=]谢谢你的回复,但是你能澄清我应该在哪个文件中编辑吗?