jQuery网络摄像头/闪光灯:如何检测网络摄像头是否处于活动状态? [英] jQuery webcam/flash: How to detect if webcam is active?

查看:258
本文介绍了jQuery网络摄像头/闪光灯:如何检测网络摄像头是否处于活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我正在使用的网站中使用此jQuery网络摄像头插件.如果您访问该网站,则会发现它使用Flash,并且必须单击接受"才能使其正常工作.

I'm using this jQuery webcam plugin in a website I'm working on. If you go to the website, you'll notice it uses flash, and you have to click 'accept' in order to get it to work.

我想确定网络摄像头是否处于活动状态(打开).如何使用javascript/jquery做到这一点?

I want to determine if the webcam is active (on) or not. How can I do this with javascript/jquery?

换句话说,我在这里的if语句中替换什么?

In other words, what do I substitute in the if statement here?

function capture_image(){
    if(webcam.muted == true) {alert("hey");}

我距离javascript和jquery的专业人士还很远,所以非常感谢您提供真正的代码.

I'm far from a pro in javascript and jquery, so real code would be much appreciated.

此外,如果有人可以告诉我如何捕获网络摄像头被激活的事件,也将不胜感激.如果您无法解决问题,那就不用担心.

Also, if someone could tell me how to capture the event of the webcam being activated, it would also be much appreciated. If you can't figure it out, don't worry about it.

推荐答案

将以下功能添加到网络摄像头的debug选项.

Add the following function to the debug option of the webcam.

$("#camera").webcam({
    width: 320,
    // other options etc.
    debug: function(type, message) { 
        if (message === "Camera started") { window.webcam.started = true; } 
    }
});

我们不能测试是否为非活动状态(即muted === true),但是现在我们可以测试webcam.startedtrue还是undefined/false:

We cannot test for inactivity to be true (i.e. muted === true) but now we can test for webcam.started being true or undefined/false:

function capture_image(){
    if( !webcam.started ) { alert("hey, camera not started"); }
}

如何捕获事件

除了debug事件之外,没有其他事件.你可以做一个...

There is not an event per se, other than the debug event. You could make one...

首先执行以下操作:

$("#camera").webcam({
    width: 320,
    // other options etc.
    debug: function(type, string) { 
        if (string === "Camera started") { 
            window.webcam.started = true; 
            if (window.webcam.onStarted) { window.webcam.onStarted(); } 
        } 
    }
});

下一步,向我们的新事件webcam.onStarted添加一个函数:

Next add a function to our new event webcam.onStarted:

window.webcam.onStarted = function () {
    alert("Whey, the webcam started");
};

这篇关于jQuery网络摄像头/闪光灯:如何检测网络摄像头是否处于活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆