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.
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.
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.
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 !? ...
}
}
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
© 2022 - 2024 — McMap. All rights reserved.