Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

as3 determine if camera access was denied

How can I determine if access to the camera and mic were denied in Flash?

I can get the camera and mic, but I need to know if the user denied access.

like image 428
Lee Loftiss Avatar asked Jan 23 '12 03:01

Lee Loftiss


3 Answers

Attach a status event listener and check if the camera is muted, see docs:

Dispatched when a camera reports its status. Before accessing a camera, the runtime displays a Privacy dialog box to let users allow or deny access to their camera. If the value of the code property is "Camera.Muted", the user has refused to allow the SWF file access to the user's camera. If the value of the code property is "Camera.Unmuted", the user has allowed the SWF file access to the user's camera. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#event:status

flash.media.Microphone has the same thing too.

like image 114
ToddBFisher Avatar answered Nov 03 '22 13:11

ToddBFisher


Cause if you set "Remember" in the Settings Panel (right-click), there will no be the popup and so no notification of status change.

So, in order to know if your camera is allowed (and microphone if need), you can check the muted attribut :

var camera:Camera = Camera.getCamera();
if (camera.muted)
{
    camera.addEventListener(StatusEvent.STATUS, handleCameraStatus, false, 0, true);
}
else
{
    camAllowed = true;
    handleWebcam();
}

and in your status handler

private function handleCameraStatus(e:StatusEvent):void
{
    witch (e.code)
    {
        case 'Camera.Muted':
        {
            camAllowed = false;
            trace("Camera muted");
            break;
        }
        case 'Camera.Unmuted':
        {
            camAllowed = true;
            trace("Camera unmuted");
            handleWebcam();
            break;
        }
    }
}

(you do the same for the microphone if need)

then, when you call your method to handle

private function handleWebcam()
{
    if (camAllowed && micAllowed)
    {
        // Do what you need when all is OK
    }
    else
    {
        // Either wait for the 2 status to switch to true, either you got a problem !? ...
    }
}
like image 35
LE GALL Benoît Avatar answered Nov 03 '22 12:11

LE GALL Benoît


There is also an issue, when user has denied camera access for this site forever via global flash player settings. In that case camera.muted === true but there is no security dialog and therefore no StatusEvent. There are some ways to detect this, here: Detecting user's camera settings

like image 1
Vladimir Demidov Avatar answered Nov 03 '22 13:11

Vladimir Demidov