16 December 2011
To get the most out of this article, you should have a basic familiarity with building RIAs using Flash Builder.
Additional required other products
Intermediate
In this article, you'll learn how to create a simple video player that streams Adobe HTTP Dynamic Streaming (HDS) video to Internet-connected televisions, set-top boxes, and other devices. Playing video content on devices requires the AIR for TV (A4TV) 2.5.1 or later runtime. This article describes how to configure Adobe Flash Builder to develop and compile a simple player for A4TV using the Open Source Media Framework (OSMF).
The A4TV runtime requires developers use the proper AIR namespace in their application descriptor file. OSMF facilitates player development for consuming HDS content that cannot be consumed by the popular FLVPlayback or VideoDisplay components. The sample project described in this article uses the following:
For the purposes of this article, you'll use the Flash Builder 4.5 development environment. If you prefer to use Adobe Flash Professional, see my companion article, Creating a simple OSMF video player for AIR for TV using Flash Professional.
Follow these steps to set up your environment:
Flash Builder 4.5 uses the Flex 4.5 SDK by default. The minimum namespace requirement for AIR applications by the Flex 4.5 SDK is AIR 2.6. Since A4TV 2.5.1 requires the AIR 2.5 namespace to run properly, you must use the Flex 3.6 SDK—which has a minimum requirement of AIR 1.5 namespace. Then it is necessary to overlay the AIR 2.5 SDK on the Flex 3.6 SDK to ensure the proper functionality for A4TV 2.5.1 is included when the project is compiled.
Follow these steps to set up AIR 2.5 SDK on the Flex 3.6 SDK:
Note: If you are working on a Mac, be advised that copying a directory over another with the same filename will replace the original directory. Take care to copy only the individual files from the AIR 2.5 SDK into the corresponding directories in the Flex 3.6 SDK to ensure that you do not overwrite the directories.
The AIR 2.5 runtime adds Stage Video support for AIR applications. OSMF build 1.6 automatically enables Stage Video whenever it is available for performance improvements using hardware rendering and decoding of H.264 video. The Flex 3.6 SDK does not support OSMF, so it is necessary to import the OSMF 1.6 SWC file. Follow these steps:
Next, configure your project to use the Flex 3.6 SDK and OSMF 1.6 SWC file:
Now set the compiler directive to require Adobe Flash Player 10.2:
-target-player=10.1
Next, set the application profile to TV in the launch configuration:
At this point, you've finished setting up the development environment. In the next section, you'll learn how to create the OSMF video player.
To build this sample project, you'll use the OSMF MediaPlayerSprite (MPS) class. MPS is a wrapper class that provides access to the core functionality of the MediaPlayer, MediaContainer, and MediaFactory classes. The code calls for the URL to a manifest file (.f4m) in order to play HDS content; however, you can also use URLs for progressive download or RTMP streaming from Flash Media Server (FMS).
Follow these steps to create the video player:
private var tvURL:URLResource = new URLResource($url_to_HDS_manifest.f4m);
private var player:MediaPlayerSprite = null;
Note: Replace the $url_to_HDS_manifest.f4m above with the full path to your manifest file, e.g. http://mediapm.edgesuite.net/osmf/content/test/manifest-files/dynamic_Streaming.f4m.
addEventListener(Event.ADDED_TO_STAGE, init);
init function:private function init(event:Event):void
{
}
init function body:stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.HIGH;
player = new MediaPlayerSprite();
player.resource = tvURL;
player.mediaPlayer.autoPlay = true;
var layout:LayoutMetadata = new LayoutMetadata();
layout.scaleMode = ScaleMode.LETTERBOX;
layout.height = Capabilities.screenResolutionY;
layout.width = Capabilities.screenResolutionX;
player.media.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
addChild(player);
After making these changes, the final version of the code should look like this:
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.osmf.layout.LayoutMetadata;
import org.osmf.layout.ScaleMode;
import flash.system.Capabilities;
import org.osmf.media.MediaPlayerSprite;
import org.osmf.media.URLResource;
public class tvPlayer extends Sprite
{
private var tvURL:URLResource = new URLResource("http://mediapm.edgesuite.net/osmf/content/test/manifest-files/dynamic_Streaming.f4m");
private var player:MediaPlayerSprite = null;
public function tvPlayer()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
public function init(event:Event):void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.HIGH;
player = new MediaPlayerSprite();
player.resource = tvURL;
player.mediaPlayer.autoPlay = true;
var layout:LayoutMetadata = new LayoutMetadata();
layout.scaleMode = ScaleMode.LETTERBOX;
layout.height = Capabilities.screenResolutionY;
layout.width = Capabilities.screenResolutionX;
player.media.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
addChild(player);
}
}
}
After completing the steps provided in this article, you should have successfully created a simple, full-screen, skinless, Stage Video–enabled video player for AIR for TV devices using the OSMF MediaPlayerSprite class in Flash Builder 4.5.
If you'd like to research further, experiment with this sample project by extending this code to add functionality. You can also skin the video player and deploy it on AIR for TV–enabled devices.
To learn more about working with OSMF, see the following resources:

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License