热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jQuerywebcam/flash:如何检测网络摄像头是否处于活动状态?-jQuerywebcam/flash:Howtodetectifwebcamisactive?

ImusingthisjQuerywebcamplugininawebsiteImworkingon.Ifyougotothewebsite,youllno

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.

我在我正在研究的网站上使用这个jQuery网络摄像头插件。如果你去网站,你会发现它使用闪存,你必须点击'接受'才能使它工作。

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

我想确定网络摄像头是否处于活动状态(打开)。我怎么能用Javascript / jquery做到这一点?

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

换句话说,我在if语句中替换了什么?

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

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

我远非Javascript和jquery的专家,所以真正的代码将非常感激。

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.

此外,如果有人可以告诉我如何捕获网络摄像头被激活的事件,也将非常感激。如果你无法弄清楚,不要担心。

4 个解决方案

#1


4  

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; } 
    }
});

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:

我们无法测试不活动是否为真(即静音=== true)但现在我们可以测试webcam.started是true还是undefined / false:

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

How to capture the event

如何捕捉事件

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

除了调试事件之外,本身没有事件。你可以做一个......

First do the following:

首先执行以下操作:

$("#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(); } 
        } 
    }
});

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

接下来为我们的新活动webcam.onStarted添加一个功能:

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

#2


0  

You could use the method .getCameraList() to get all cameras available.

您可以使用方法.getCameraList()来获取所有可用的摄像头。

onLoad The onLoad callback is called as soon as the registration of the interface is done. In the example above, I use the callback to get a list of all cameras available:

onLoad完成接口注册后立即调用onLoad回调。在上面的示例中,我使用回调来获取所有可用摄像头的列表:

onLoad: function() {
    var cams = webcam.getCameraList();
    for(var i in cams) {
        jQuery("#cams").append("
  • " + cams[i] + "
  • "); } }

    #3


    0  

    I think you will need to use the ExternalInterface API to tell the Javascript on your page when the privacy setting has been agreed to.

    我认为在同意隐私设置时,您需要使用ExternalInterface API来告知您网页上的Javascript。

    However I don't know if you will be able to get to the "image information" you want because flash has control of the camera, so the Javascript will only be able to tell flash to "capture" and image through the ExternalInterface, you will probably have to use flash (ActionScript) to send the image data to a webservice before the Javascript on the page can do anything with it.

    但是我不知道你是否能够获得你想要的“图像信息”,因为flash可以控制相机,所以Javascript只能通过ExternalInterface告诉flash“捕获”和图像,你可能必须使用flash(ActionScript)将图像数据发送到Web服务,然后页面上的Javascript才能对其执行任何操作。

    HTML5 has an that might suffice, instead of the flash implementation.

    HTML5有一个,这可能就足够了,而不是flash实现。

    #4


    0  

    Not sure about all these plugins etc. This works for me, though we're still testing:

    不确定所有这些插件等。这对我有用,虽然我们仍在测试:

    webcamActive = false;
    webcamActive = $("#video").attr('src');
    

    推荐阅读
    author-avatar
    每天还贷的飞鱼
    这个家伙很懒,什么也没留下!
    PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有