as3 determine if camera access was denied

♀尐吖头ヾ 提交于 2020-01-03 08:27:06

问题


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.


回答1:


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.




回答2:


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 !? ...
    }
}



回答3:


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



来源:https://stackoverflow.com/questions/8966912/as3-determine-if-camera-access-was-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!