Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [71]

By Root 2587 0


Hardware is improving quickly, but each device’s architecture is a little different. If you want to target the high end of the market, you can add such comments when submitting your applications to the Android Market.

In addition to your encoding settings, there are some best practices to obey for optimal video playback. They are all simple to apply:

Do not put anything on top of or behind the video, even if it is transparent. This would need to be calculated in the rendering process and would negatively affect video playback.

Make sure your video window is placed on a full pixel (no half-pixel boundaries).

Do not use bitmap caching on the video or any other objects on the stage. Do not use filters such as drop shadows or pixel benders. Do not skew or rotate the video. Do not use color transformation or objects with alpha.

Do not show more than one video at the same time.

Stop all other processes unless they are absolutely necessary. If you use a progress bar, only call for progress update using a timer every second, not on the enter frame event.

Playing Video

You can play videos running from your device or loaded remotely.

Embedded Video


You can embed a video in your application using Flash Professional. Embedded video will appear in the library as a symbol. Create a MovieClip and add the video content to it. You can then control its playback by calling the standard MovieClip navigation methods.

Using this approach is simple, but it has disadvantages. The video is compiled into the application and adds to its size. Also, it is always loaded in memory and cannot be removed.

As an alternative, you can embed the video in an external .swf file which you load using the Loader class.

External Video


You can package the video with your application. It is placed in the application directory. The application will not display until all of the assets are loaded. You can also serve the video from a remote web server. The code is identical in both cases.

For the latter, add some buffering logic. We will come back to this topic later in this chapter.

Progressive Video


To load video locally, you need to know the path of the file in your application directory.

NetConnection creates a connection with the local filesystem when calling its connect method. Pass a null parameter in its construction to indicate that it is not streaming.

Within the connection, NetStream opens the channel between AIR and the local filesystem. Pass the connection object as a parameter in its construction, and use its play method to receive video data. Note that this object needs its client property defined as well as the onMetaData method to prevent a runtime error.

The Video object displays the video data.

In this example, the Video object dimensions are hardcoded:

import flash.net.NetConnection;

import flash.net.NetStream;

import flash.media.Video;

import flash.events.NetStatusEvent;

var connection:NetConnection;

var video:Video;

video = new Video();

video.width = 480;

video.height = 320;

connection = new NetConnection();

connection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionEvent);

connection.connect(null);

function netConnectionEvent(event:NetStatusEvent):void {

event.target.removeEventListener(NetStatusEvent.NET_STATUS,

netConnectionEvent);

if (event.info.code == "NetConnection.Connect.Success") {

var stream:NetStream = new NetStream(connection);

stream.addEventListener(NetStatusEvent.NET_STATUS, netStreamEvent);

var client:Object = new Object();

client.onMetaData = onMetaData;

stream.client = client;

// attach the stream to the video to display

video.attachNetStream(stream);

stream.play("someVideo.flv");

addChild(video); }

}

function onMetaData(info:Object):void {}

WARNING

At the time of this writing, video.smoothing is always false. This is consistent with AIR runtime default settings, but does not provide the best video experience. Setting video.smoothing to true does not change it.

SD card


You can play videos from the SD card. Playback is

Return Main Page Previous Page Next Page

®Online Book Reader