Javascript 无法关闭网络摄像头
我已经编写了一个脚本,它成功地激活了用户的网络摄像头,但在我尝试停止或暂停流时抛出了一个错误 我已经为多部分单页webapp构建了一个原型,它要求用户激活然后停用他们的网络摄像头。这个版本的原型实际上并没有捕获和存储网络摄像头的图像,尤其重要的是用户能够关闭摄像头,这样他们就不会觉得自己被监视了 下面是我的脚本,它使用了一个名为compatibility的webRTC功能检测库。行$video.pause导致以下错误 未捕获类型错误:未定义在Chrome 36.x中不是函数 在devtools中键入$video时,点击return可以得到以下信息 [] 但在执行$video[0]时,pause会显示与上述相同的错误消息 我在想,做一些类似window.URL.revokeObjectURLstream的事情——在我的例子中是compatibility.URL.revokeObjectURLstream——是一种方法,但我想在深入研究之前得到一些建议Javascript 无法关闭网络摄像头,javascript,jquery,getusermedia,Javascript,Jquery,Getusermedia,我已经编写了一个脚本,它成功地激活了用户的网络摄像头,但在我尝试停止或暂停流时抛出了一个错误 我已经为多部分单页webapp构建了一个原型,它要求用户激活然后停用他们的网络摄像头。这个版本的原型实际上并没有捕获和存储网络摄像头的图像,尤其重要的是用户能够关闭摄像头,这样他们就不会觉得自己被监视了 下面是我的脚本,它使用了一个名为compatibility的webRTC功能检测库。行$video.pause导致以下错误 未捕获类型错误:未定义在Chrome 36.x中不是函数 在devtools中
// get it
var smoother = new Smoother(0.85, [0, 0, 0, 0, 0]),
$video = $("#v"),
$local_media = null;
webcam_capture = function(x){
try {
compatibility.getUserMedia({video: true}, function(stream) {
try {
$video.attr('src', compatibility.URL.createObjectURL(stream));
} catch (error) {
$video.attr(src, stream);
}
$('.camera_prompt').removeClass('show')
}, function (error) {
alert("WebRTC not available");
});
} catch (error) {
console.log(error);
}
}
webcam_capture();
// warn - prompt permissions after 6 seconds
capture_error = setTimeout(function(){
typeof $video.attr('src') == "undefined" ?
$('.camera_prompt').addClass('show') :
clearTimeout(capture_error);
},3000)
start_card_capture = function(x){
// open capture sesh
OAO.card_capture_status = true;
// get id of input to focus and class
var id = 'capture_' + x;
$('input#' + id).addClass('focused');
// UI fade in
$('#v, .notification, button.capture').fadeIn();
}
end_card_capture = function(x){
// close capture sesh
OAO.card_capture_status = false;
// UI fade out
$('#v, .notification, button.capture').fadeOut('visible');
}
capture_notify = function(x){
$('#card_capture_form').find('.notification').find('div').text(x)
}
$('.capture').on('click', function(e){
// determine input
var $f = $(this).parent('form')
$i = $f.find('input.focused');
// check input and update the associated label's icon
$i.prop('checked', true).removeClass('focused');
$i.next('label').addClass('captured');
// close UI
if($f.find('label.captured').length < 2){
end_card_capture(e)
}
if($f.find('label.captured').length == 2){
$video.pause();
OAO.sectional_transition('#funding',{y: '0%'}, 1400,100, $(this).parents('section'), { y: '-250%' }, 1000, 100 );
OAO.step = 2;
OAO.progress_bar(OAO.step)
$('#progress_bar_container').removeClass('hidden');
}
});
$('.capture_front, .capture_back').on('click', function(){
// determine which side
$(this).hasClass('capture_front') ?
OAO.card_capture_side = 'front' :
$(this).hasClass('capture_back') ?
OAO.card_capture_side = 'back' :
C('whichsideofthecardamIshooting?');
if(typeof $video.attr('src') !== "undefined"){
// set prop and init capture
capture_notify(OAO.card_capture_side);
start_card_capture(OAO.card_capture_side)
}
});
提前感谢您的帮助如果$v返回[],那么jquery找不到具有该idAlso的元素,Andrew的副本您能给我指出副本吗?另外,$'v'[0]。暂停为Chrome工作在这种情况下?我已经在我的评论中添加了一个链接。暂停视频元素可能不会让所有用户都觉得他们的隐私是安全的;浏览器UI中仍有一部分表示您的页面可以访问麦克风或摄像头,例如Chrome在页面的浏览器选项卡上添加了一个红色圆圈。我现在看到了链接,并且解决了我的问题问题。我先设置localMedia=stream,然后设置localMedia.stop来停止流——如果不清楚的话,这就是我的目标。我从链接的问题中收集到重复的问题和我用来指导的其他参考资料,我发现stream.stop在webkit上不起作用,所以我一开始并不费事。然后我在$'video'之后添加了它作为回退。暂停一下,但它是肯定是放错地方了,因为我还有一个未定义的函数错误。