Tony Jose
Tony Jose

Reputation: 1664

jpegcam, disable capture button after deny access

In my php project i have used jpegcam, http://code.google.com/p/jpegcam/ & When we are loading web cam capture page its asking for flash player permissions "allow or deny", even if i denied the option capture button is enabled.I want to disable capture button when it loads & enable only if the user allows the permissions!

So how to check that user has allowed or denied webcam access in privacy settings dialog box to the site? ! Guys, any help would be appreciated.. :)

Upvotes: 5

Views: 1174

Answers (1)

Dave
Dave

Reputation: 46259

ActionScript's Camera.muted property is what you need. The source you linked to creates a private Camera object named camera. You can make it public or add a new method to check its muted property;

final public function has_access( ) : Boolean {
    return !camera.muted;
}

Typically you would hide/disable the button until muted becomes false (it's very unlikely it will become true again; the user would have to manually open the settings box and disable access).

You can also use a listener to avoid constantly checking this value;

final public function add_access_listener( myFunc : Function ) : void {
    camera.addEventListener( "status", myFunc ); // StatusEvent.STATUS
}

Which would be used like this:

myWebcam.add_access_listener( myAccessFunc );
function myAccessFunc( ev : StatusEvent ) : void {
    if( ev.code == "Camera.Unmuted" ) {
        // video became available, enable button
    } else {
        // video became unavailable, disable button
    }
}
// remember that the user could have granted persistent permission
// (i.e. the status will be unmuted without actually changing)
if( myWebcam.has_access( ) ) {
    // video is already available, enable button
} else {
    // video is not yet available, disable button
}

To avoid any possible memory leaks, you should also also call removeEventListener if you ever remove the camera, but the library doesn't seem to be designed to do that anyway (and doesn't remove its own listeners).

Upvotes: 0

Related Questions