JQuery webcam / flash: how to determine if a webcam is active?

I am using this jQuery webcam plugin on the website I'm working on. If you go to the site, you will notice that it uses a flash, and you need to click "accept" to make it work.

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

In other words, what can I replace here in the if statement?

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

I am far from a professional in javascript and jquery, so the real code will be much appreciated.

Also, if someone can tell me how to capture a webcam activation event, it would also be very appreciated. If you cannot understand this, do not worry about it.

+5
source share
4 answers

Add the debugfollowing function to the webcam function.

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

We cannot verify that the inaction is true (i.e. muted === true), but now we can verify that or / webcam.startedis significant :trueundefinedfalse

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

How to record an event

There is no event as such, except an event debug. You can do 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(); } 
        } 
    }
});

Then add the function to our new event webcam.onStarted:

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

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

onLoad the onLoad callback is called immediately after registration the interface is completed. In the above example, I use callback to get a list of available cameras:

onLoad: function() {
    var cams = webcam.getCameraList();
    for(var i in cams) {
        jQuery("#cams").append("<li>" + cams[i] + "</li>");
    } 
}
0
source

, ExternalInterface API, JavaScript , .

, " ", , - , JavaScript flash- "" ExternalInterface, , , flash (ActionScript) -, javascript - .

HTML5 <input type="file" accept="image/*" capture="camera" id="capture">, , -.

0

.. , :

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

All Articles