Archive for February, 2011

Configure Flash Media Server for optimum performance

Choppy video. No one likes it. To stream video smoothly, start by tuning Flash Media Server for your situation. Are you streaming on-demand (recorded) or live video? If you’re streaming live, which is more important to you, scale (reaching as many people as possible) or latency (the time elapsed between the live event and when the viewer sees the live event)?

In the Configuration and Administration Guide, FMS engineers provide tuning recommendations for on-demand and live streaming:

Progressive download is dead. Long live on-demand HTTP dynamic streaming. Stream FLV/F4V/MP4 files to Flash over HTTP.

When you view content on YouTube, you don’t have to wait for the content to download to skip ahead to the end of the file. Progressive download is dead, this is on-demand HTTP streaming.

Use Adobe HTTP Dynamic Streaming to serve on-demand video over HTTP on your web site.

  1. Download the File Packager
  2. Download the Apache HTTP Origin Module
  3. Install the HTTP Origin Module to Apache HTTP Server 2.2
  4. Use the File Packager off-line tool to package an FLV, F4V, or MP4 file for HTTP streaming.
  5. Copy the packaged files to the Apache webroot folder.
  6. Play the files in Flash Media Playback or OSMF Sample Player for HTTP Dynamic Streaming.

These are the high-level steps, for the nitty-gritty, check out the On-demand HTTP Dynamic Streaming tutorial.

To stream live media over HTTP to Flash/AIR, use Flash Media Server. Check out the Live HTTP Dynamic Streaming tutorial in the FMS Developer’s Guide.

H/W accelerate your video performance: Flash Player 10.2 StageVideo docs are live

Does your Flash Player application feature a video player? And if so, are you looking for a way to improve the video performance?

For several releases, Flash Player has supported GPU hardware acceleration for decoding H.264 videos. However, the rest of the rendering process still required the CPU. Flash Player 10.2 brings hardware acceleration support full circle by introducing the StageVideo API. Stage video lets you apply hardware acceleration to the entire video decoding and rendering process, thus freeing up CPU and memory resources.

A StageVideo API has previously been available only to AIR 2.5 for TV application developers, and through the Flash 10.1 Beta for Google TV. The StageVideo API in Flash Player 10.2 expands on these existing classes. It adds events for handling behavior in a browser context.

To learn how your application can take advantage of this new feature, see the following documentation:

Remote control input handling in AIR for TV apps

And here’s yet another design consideration for AIR for TV applications.  (This and other tips will be incorporated soon into Adobe online documentation).

Users typically interact with your AIR for TV application using a remote control. The good news is that the way you handle remote control key input is the same way you handle key input from a keyboard on a desktop application. Specifically, handle the event KeyboardEvent.KEY_DOWN.

The keys on the remote control map to ActionScript constants. For example, the keys on the directional keypad on a remote control map as follows:

Remote control’s directional keypad key
ActionScript 3.0 constant
Up Keyboard.UP
Down Keyboard.DOWN
Left Keyboard.LEFT
Right Keyboard.RIGHT
OK or Select Keyboard.ENTER

AIR 2.5 added many other Keyboard constants to support remote control input. For a complete list, see the Keyboard class in the ActionScript 3.0 Reference for the Adobe Flash Platform.

To ensure your application works on as many devices as possible, Adobe recommends the following:

  • Use only the directional keypad keys, if possible.

    Different remote control devices have different sets of keys. However, they typically always have the directional keypad keys.

    For example, a remote control for a Blu-ray player does not typically have a “channel up” and “channel down” key. Even keys for play, pause, and stop are not on all remote controls.

  • Use the Menu and Info keys if the application needs more than the directional keypad keys.

    The Menu and Info keys are the next most common keys on remote controls.

  • Consider the frequent usage of universal remote controls.

    Even if you are creating an application for a particular device, realize that many users do not use the remote control that comes with the device. Instead, they use a universal remote control. Also, users do not always program their universal remote control to match all the keys on the device’s remote control. Therefore, using only the most common keys is advisable.

  • Make sure that the user can always escape a situation using one of the directional keypad keys.

    Sometimes your application has a good reason to use a key that is not one of the most common keys on remote controls. Providing an escape route with one of the directional keypad keys makes your application behave gracefully on all devices.

  • Do not require mouse input.

    Obviously, a television doesn’t have a mouse. However, if you are converting desktop applications to run on televisions, make sure that you modify the application to not expect mouse input. These modifications include changes to event handling and changes to instructions to the user. For example, don’t overlook changing an application’s startup screen if it displays text that says “Click to start”.

For more information on key input handling, see Capturing keyboard input in the ActionScript 3.0 Developer’s Guide. Continue reading…

When to set Stage properties

Speaking of setting AIR for TV Stage properties (which I was speaking of in my last blog entry) ….

I was looking at some sample AIR for TV applications written by a member of the AIR for TV engineering team, and was reminded of something interesting. He sets the stage properties in an event handler that handles the ADDED_TO_STAGE event.

Specifically, in the constructor for his main document class, he writes:

addEventListener(Event.ADDED_TO_STAGE, onStage);

Then in his onStage() event handler, he writes:

private function onStage(evt:Event):void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//remove event listener
removeEventListener(Event.ADDED_TO_STAGE, onStage);
// And more initializations follow
}

It’s tempting, and seemingly logical, to put the Stage property initializations in the constructor of the main document class. But you should wait until you receive the ADDED_TO_STAGE event.  It is possible in some circumstances for the constructor of the main document class  to execute before the object has been added to the stage.  If that occurs, accessing the object’s stage property results in an exception.

For a display object that is not the main document class, this behavior is more obvious. You create a display object, and then you add it to the stage. Therefore, the object’s constructor always executes before you add the object to the stage.  So setting Stage properties in the constructor is certain to fail in these cases.  So that’s another good reason to always wait to access the stage property of any display object until after you’ve received the ADDED_TO_STAGE event.

This programming tip is not specific, by the way, to AIR for TV applications, but applies to any Flash Player or AIR app.