
Adobe AIR for mobile has had consistent camera support since AIR 2.6, and now in AIR 3 (in beta, available on Adobe Labs), we’ve introduced support for front-facing cameras, as well. The introduction of the new position property on Camera along with the constants in the new CameraPosition class (BACK, FRONT, and UNKNOWN) allow you to chose which camera you want to get a reference to before attaching it to a Video object.
To be honest, the API is not quite as elegant as I’d like because making it consistent across platforms (mobile and desktop) meant having to compromise a little intuitiveness, but it’s easy enough to figure out, and most importantly, it’s entirely cross-platform. The code below shows a simple function that will return the requested camera:
// Get the requested camera. If it cannot be found,
// return the device's default camera instead.
private function getCamera(position:String):Camera
{
for (var i:uint = 0; i < Camera.names.length; ++i)
{
var cam:Camera = Camera.getCamera(String(i));
if (cam.position == position) return cam;
}
return Camera.getCamera();
}
For a full working example, check out the demo application called FrontCameraExample on Github (you can also download the FXP file). Keep in mind that AIR 3 is still in beta, so you might find bugs. If you do, here’s how to file them.

Ho Christian,
I’ve been trying to get this to run in my Samsung Galaxy 10.1 tablet with absolutely no luck. I seem to get no results at all with the camera. (I can get the simulator to access the camera just fine). The application runs, I just get a white screen (with the view controls top and bottom) instead of the video. Do you know if there are issues with the Galaxy Tablet (10.1″)?
Thanks!
Thanks for pointing out that i did not un-comment the Android camera permission line in the app descriptor. I just checked in a new version.
Any time, thanks for the example!
Dear Christian,
I’ve got an app that I’m working on the streams the video from the cam (front or back), to a streaming recording server. Something strange, I wanted to ask you about. For the back cam, when you hold the device in portrait mode (right side up), the image is right side up. When I turn it sideways (landscape), image on screen is still right side up. However, on the front cam, holding the device in portrait mode, the video is upside down, while turning to the side (landscape), again works fine (right side up). Only the portrait mode position for from cam is returning the video on screen upside down. Any ideas or suggestions to fix this are greatly appreciated!
with kind regards,
Alex
Hi Alex,
The camera feed from both the front camera and back camera is un-mirrored. I tried with both front and back cameras and I was able to achieve this on Samsung nexus S under the following conditions.
1. The camera app is set to auto orient in the app descriptor
2. The device has a default portrait orientation
3. The front camera is turned on and the device is put in the upside-down portrait orientation. However gingerbread OS does not support all four orientations. So in upside-down portrait, the app is actually in landscape orientation and due to the un-mirrored preview, the camera feed would appear inverted or upside-down.
If you try the above on a Motorola Xoom with Gingerbread then this issue will not exist.
Hope this helps,
Regards
Divij
Dear Divij,
Thank you for your feedback! I have a limited number of devices, and as I haven’t seen this issue on the web, I figured it may be device dependent. I’ll try the settings you suggested and see how it goes. Much appreciated!
with kind regards,
Alex