Capturing Video

Must Read

Low Interest Student Loan Consolidation – Consolidate Student Loan With Low Interest Rate

Loan Consolidation is done with the help of private institutions as well as by the Federal Government. In the...

Recent Obama Changes Favor Student Loan Borrowers More Than Ever

Federal student loans are backed by U.S. Government. They are not based on credit histories of borrowers, since most...

CSS3 Transitions

Interaction invitations are important to good user experience design, and CSS has supported the :hover pseudoclass for some time...

The native video camera can be used to capture video within AIR.

Video and the CameraUI Class

You can use the native camera within AIR to capture video. Your application needs to have permission. In Flash Professional, select File→AIR Android settings→Permissions→ Camera. In Flash Builder, add the following permission:

[code]<uses-permission android:name=”android.permission.CAMERA”/>[/code]

The class is an addition to the ActionScript language to support the device’s native camera application. It is a subclass of the EventDispatcher class and is only supported on AIR for mobile.

This object allows you to launch the native camera application to shoot a video while your AIR application moves to the background.

When you use the native camera, it comes to the foreground, your AIR application moves to the background, and NativeApplication Event.DEACTIVATE is fired. Make sure you don’t have any logic that could interfere with the proper running of your application, such as exiting. Likewise, when the native camera application quits and your AIR comes back to the foreground, Event.ACTIVATE is called.

The first step is to verify that your device supports access to the camera by checking the CameraUI.isSupported property. Note that, as of this writing, Android does not support the front camera natively, and therefore neither does AIR:


if (CameraUI.isSupported == false) {
trace(“no camera accessible”);


If it is supported, create an instance of the CameraUI class.

Register your application to receive camera events. A MediaEvent.COMPLETE is dispatched after a picture is taken, an Event.CANCEL if no media is selected, and an ErrorEvent if there is an error in the process:


var cameraUI:CameraUI = new CameraUI();
cameraUI.addEventListener(MediaEvent.COMPLETE, onComplete);
cameraUI.addEventListener(Event.CANCEL, onCancel);
cameraUI.addEventListener(ErrorEvent.ERROR, onError);


Call the launch function and pass the type MediaType.VIDEO as a parameter. This will launch the camera in video mode automatically:


var cameraUI:CameraUI = new CameraUI();
function onError(event:ErrorEvent):void {


The camera application is now active and in the foreground. The AIR application moves to the background and waits.

Once the event is received, the camera application automatically closes and the AIR application moves back to the foreground.

Video capture on Android requires a lot of memory. To avoid having the Activity Manager terminate the application, the capture setting is restricted to low resolution by default, which requires a smaller memory buffer.

MPEG-4 Visual, Android low-resolution video, is not supported by AIR. Therefore, captured videos cannot be played back in AIR. The native application can be used to play back the recorded videos.

Currently, this functionality should only be used for capturing and not viewing unless you use the native application in the Gallery. The video is saved in a 3GP format that AIR does not support. Trying to play it back will just display a white screen.

In the following example, I provide the code for playback in AIR in case this is resolved in the future.

On select, a MediaEvent object is returned:


var videoURL:String;
var connection:NetConnection;
function onComplete(event:MediaEvent):void {
videoURL =;
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
function onStatus(event:NetStatusEvent):void {
switch( {
case “NetConnection.Connect.Success” :
case “NetStream.Play.StreamNotFound” :
trace(“video not found ” + videoURL);
function connectStream():void {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
var video:Video = new Video();
function onAsyncError(event:AsyncErrorEvent):void {
trace(“ignore errors”);


The Camera Class

The device’s camera, using the class, can be attached to a Video object in the AIR application. You can use this approach to simulate a web cam or for an Augmented Reality project.

The hardware orientation of the camera is landscape, so try to make your application’s orientation landscape too by changing the aspectRatio tag in your application descriptor:


The setMode function is used to determine the video’s resolution:


var camera:Camera = Camera.getCamera();
if (camera != null) {
camera.setMode(stage.stageWidth, stage.stageHeight, 15, true);
var video:Video = new Video(camera.width, camera.height);
video.x = 100;
video.y = 100;


Note that frames are only captured when the application is in the foreground. If the application moves to the background, capturing is paused but will resume automatically when the application moves to the foreground again.

You can query for the camera properties. Here are a few queries which may be helpful in your development:




Documentation and Tutorials

Development around video is constantly evolving. The following two resources are among those that will help you to stay informed:

  • The Open Source Media Framework (http://www.opensourcemediaframework .com/resources.html) helps developers with video-related products. It is a good place to find code samples, tutorials, and other materials.
  • Lisa Larson-Kelly specializes in web video publishing and, more recently, mobilepublishing. She offers free tutorials and a newsletter on the latest technology (


  1. Hi, I have tried to use the Camera class on Galaxy S (Android 2.2) but almost all its properties are “-1” (width, height, fps is 0 etc), but Camera.muted == false and also bandwidth returns a number.
    Using AIR 3.3 (tried debug mode, captive-runtime, still the same problem). App is ok on desktop.

    Any idea?



Please enter your comment!
Please enter your name here

Latest News

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits,...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

High Key Lighting Techniques for Professional Photographers

I’ve written many times about high key lighting techniques and how to achieve them. The term “high key” is a bit misleading. As I’ve...

More Articles Like This