Many phones and tablets have two cameras. How can I select the front-facing camera on a device?
You can check the .position property of a Camera and then check to see if it matches the FRONT constant defined in CameraPosition.FRONT
/**
* Gets the front facing camera of a device
*
* @return The front facing camera of the device or null if no such camera is avialable
*/
public function getFrontCamera():Camera
{
//First check if the device supports a camera
if (Camera.isSupported == false)
{
return null;
}
var numCameras:int = Camera.names.length;
var frontCam:Camera;
//Loop through all the available cameras on the device
for (var i:int = 0; i < numCameras; i++)
{
frontCam = Camera.getCamera(Camera.names[i]);
//If the camera.position property matches the constant CameraPosition.FRONT we have found
//the front camera
if (frontCam.position == CameraPosition.FRONT)
{
break;
}
//Make sure the camera object is set to null
frontCam = null;
}
//Return the found camera
return frontCam;
}
+