我在一个正在研究的网站上使用this jQuery webcam plugin.如果你去网站,你会注意到它使用闪存,你必须点击’接受’才能使它工作.
我想确定网络摄像头是否处于活动状态(打开).我怎么能用javascript / jquery做到这一点?
换句话说,我在if语句中替换了什么?
function capture_image(){ if(webcam.muted == true) {alert("hey");}
@H_502_12@我远非javascript和jquery的专家,所以真正的代码将非常感激.
此外,如果有人可以告诉我如何捕获网络摄像头被激活的事件,也将非常感激.如果你无法弄清楚,不要担心.
最佳答案
将以下功能添加到网络摄像头的调试选项中.
$("#camera").webcam({ width: 320,// other options etc. debug: function(type,message) { if (message === "Camera started") { window.webcam.started = true; } } });
@H_502_12@我们无法测试不活动是否为真(即静音=== true)但现在我们可以测试webcam.started是true还是undefined / false:
function capture_image(){ if( !webcam.started ) { alert("hey,camera not started"); } }
@H_502_12@如何捕捉事件
除了调试事件之外,本身没有事件.你可以做一个……
首先执行以下操作:
$("#camera").webcam({ width: 320,string) { if (string === "Camera started") { window.webcam.started = true; if (window.webcam.onStarted) { window.webcam.onStarted(); } } } });
@H_502_12@接下来为我们的新事件webcam.onStarted添加一个功能:
window.webcam.onStarted = function () { alert("Whey,the webcam started"); };
@H_502_12@