如何允许自动访问摄像头
How to allow the access automatically to the 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) {
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 );
我运行我的应用程序,它的工作,但在此之前,摄像头被打开,我有访问权限窗口,所以我想如果有任何解决方案,让我打开网络摄像头没有问。
很明显,你不能在未经同意的情况下打开别人的摄像头并开始录制。
在本地,您可以通过设置策略来打开特定功能,而无需询问某些供应商(如Chrome)。我在评论
相关文章:
- 是否可以在系统/电脑浏览器中访问手机摄像头
- 我的Javascript项目正在访问网络摄像头,但没有显示任何内容
- 如何使用Javascript访问网络摄像头
- 无需Flash即可访问网络摄像头
- 如何检测chrome摄像头访问对话框打开
- Chrome-允许访问网络摄像头
- 无法通过Lumia 520(运行Windows Phone 8.1预览版)的应用程序访问摄像头
- 如何从firefox插件访问笔记本摄像头?
- 无法访问网络摄像头(Javascript)
- 如何通过Internet Explorer(11)访问网络摄像头
- 如何从HTML5访问网络摄像头
- IPhone摄像头访问手机网页
- 通过http访问浏览器中的摄像头
- 如何通过javascript访问网络摄像头
- ([javaScript]在iOS中通过HTML5浏览器访问摄像头
- 如何允许自动访问摄像头
- 反应原生访问手机摄像头
- 通过javascript/jquery访问网络摄像头
- 尝试在html5中访问网络摄像头:Firefox工作,Chrome和Opera don't
- vline-webrtc:记忆允许访问摄像头