as3 determine if camera access was denied
Asked Answered
A

3

8

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.

Actinoid answered 23/1, 2012 at 3:32 Comment(0)
E
6

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.

Endbrain answered 23/1, 2012 at 3:40 Comment(0)
S
4

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 !? ...
    }
}
Succinic answered 11/8, 2013 at 14:43 Comment(0)
C
1

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

Coralyn answered 24/11, 2014 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.