Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flash Developer Center /

Mastering OSMF – Part 1: Working with the Flash Platform

by David Hassoun

David Hassoun
  • david.realeyes.com

by John Crosby

John Crosby
  • john.realeyes.com

Content

  • Getting started with the Strobe Media Playback player
  • Walkthrough 1: The simplest player
  • Walkthrough 2: Separating control
  • Walkthrough 3: Handling different media
  • Where to go from here

Created

22 February 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flash Professional OSMF playback templates video

Requirements

Prerequisite knowledge

You should be familiar with the Flash Platform, building applications in Flash Professional or Flash Builder, using ActionScript 3, and concepts related to playing video using Flash.

User level

Intermediate

Required products

  • Flash Professional (Download trial)
  • Flash Builder (Download trial)
  • Open Source Media Framework

Sample files

  • mastering-osmf-pt1.zip (8825 KB)

This article begins a three-part series of hands-on development with Open Source Media Framework (OSMF). These articles provide a wide view of OSMF—what it has to offer and how to use it. It is geared towards developers or designers who have some development expertise and want to understand better how to take control of the power and benefits that OSMF has to offer.

Part 1 gets you started with the basics of OSMF and working with different media. Download, configure, and play back media with the Strobe Media Playback player—a precompiled, ready-to-deploy SWF file that is configured via the HTML source and the FlashVars.

Here's what we cover in the subsequent walkthroughs:

  • Creating a very simple media player using OSMF and the MediaPlayerSprite class
  • Breaking out the main control objects of an OSMF media player and learning how to manage them independently
  • Extending the player to handle different kinds of media using a MediaFactory class and the generic MediaElement class

Getting started with the Strobe Media Playback player

Start by downloading, configuring, and playing back media with the Strobe Media Playback player. The Strobe Media Playback player is a precompiled, ready-to-deploy SWF file that is configured via the HTML source and the FlashVars. Table 1 lists the currently supported FlashVars.

Table 1. Currently supported FlashVars in the Strobe Media Playback player

Name Value Description
src   Location of the media file
loop true, false * Restart media when complete
autoPlay true, false * Automatically start media
controlBarPosition bottom *, none, over Position of the control bar
backgroundColor   Background color of the player
streamType liveOrRecorded *, live, recorded, dvr Media stream type. The DVR functionality only works if streamType = dvr. Otherwise you would only see the recorded part (if the mode is recorded) or the live part (if mode is live OR if mode is liveOrRecorded).
autoHideControlBar true, false * Auto-hide the control bar
scaleMode letterbox, none, stretch, zoom Controls how the media should be scaled

* Default value.

As we go through the steps, we'll show you the basic use of some of the most common configuration properties, including loading dynamic plugins and basic namespaces for their metadata.

Downloading the Strobe Media Playback player

Follow these steps to download the player and open it in its default configuration:

  1. Download the mastering-osmf-pt1.zip file at the top of this page.
  2. Unzip the contents of the player to a directory of your web server.
  3. The ZIP file contains two versions of Strobe Media Playback: one version compiled for Flash Player 10.0 and another version compiled for Flash Player 10.1. The 10.1 version is required for DRM and HTTP Streaming. You must have Flash Player 10.1, or later, installed for the 10.1 version of the player to work correctly.
  4. Open the StrobeMediaPlayback.html file for your version [/10.0/StrobeMediaPlayback.html or /10.1/StrobeMediaPlayback.html] in a browser. You should see the OSMF logo video play (see Figure 1).
Strobe Media Playback player playing the OSMF logo video.
Figure 1. Strobe Media Playback player playing the OSMF logo video.

Configuring the Strobe Media Playback player

Follow these steps to configure the player:

  1. Save the StrobeMediaPlayback.html file as a new file named StrobeMediaPlayback_config.html and then open this file in a text editor.
  2. Locate the autoHideControlBar property and change this from false to true .
  3. Update the controlBarPosition property from bottom to over .
  4. Open StrobeMediaPlayback_config.html in a browser. Now the control bar should be hidden until you roll over the player and it should now be positioned over the video that is playing (see Figure 2).
Control bar visible on rollover.
Figure 2. Control bar visible on rollover.
  1. Return to the StrobeMediaPlayback_config.html file.
  2. Locate the JavaScript that sets the value of the parameters variable. This is where the Strobe Media Playback player is configured.
  3. Notice that the src attribute is set to an HTTP path—currently, the media player is loading and playing a progressive video.
  4. Update the source value to rtmp://cp67126.edgefcs.net/ondemand/mediapm/osmf/content/test/akamai_10_year_f8_512K or another streaming URL of your own.
  5. Save the file and run it in a browser. The new video should play without any issues (see Figure 3).
fig03
Figure 3. Completed Strobe Media Playback sample.
  1. Be sure to check out Using_Strobe_Media_Playback.pdf included in mastering-osmf-pt1.zip for additional configuration settings.

Dynamic streaming with Strobe Media Playback

The Strobe Media Playback player also supports dynamic streaming. If the source is set to the URL for an F4M file, you can specify multiple streams and Strobe will switch between the streams as the user's bandwidth fluctuates in order to use the most efficient stream for the amount of bandwidth available. F4M is an XML file in a particular format, for which you can find the specifications on the OSMF website.

  1. Open the StrobeMediaPlayback_config.html again and switch the src attribute in the HTML to "http://mediapm.edgesuite.net/osmf/content/test/manifest-files/ dynamic_Streaming.f4m" .
  2. Save the file and open it up in a browser. The new video should play and adjust for any bandwidth changes (see Figure 4).
Strobe Media Playback: dynamic streaming.
Figure 4. Strobe Media Playback: dynamic streaming.

It is also possible to do dynamic streaming using a SMIL file as the source. However, this requires you to load in the SMIL plug-in, which is available from the OSMF SVN repository. Fortunately, loading plug-ins with Strobe is the next subject we'll cover.

Configuring plug-ins

The following section illustrates how to configure the Strobe Media Playback player to load in an external plug-in from a remote location. It requires the use of a local or remote web server to properly test due to local FlashPlayer security:

  1. Return to StrobeMediaPlayback_config.html and add the following key value pairs to the parameters object:
plugin_simple: "http://osmf.realeyes.com/plugins/simple/ SimpleOSMFPlugin.swf" simple_namespace: "http://osmf.realeyes.com/plugins/simple" simple_message: "The plugin has loaded."

The code should look something like this:

var parameters = { id: "1" , src: "http://mediapm.edgesuite.net/osmf/content/test/ logo_animated.flv" , autoPlay: "true" , width: "638" , height: "400" , autoHideControlBar: "true" , controlBarPosition: "over" , plugin_simple: "http://osmf.realeyes.com/plugins/simple/SimpleOSMFPlugin.swf" , simple_namespace: "http://osmf.realeyes.com/plugins/simple" , simple_message: "The plugin has loaded." };

Note: Plug-ins are configured by first naming the plug-in as 'plugin_simple'. (The '_' character separates the plug-in name definition as well as the property name for the value to be sent to the plug-in.)

  1. This configures the player to load SimpleOSMFPlugin.swf. When the plug-in loads, it calls the JavaScript alert method via ExternalInterface and passes the message defined by the plugin_simple property.
  2. Save the file and run it in the browser (see Figure 5).

Note: To load plug-ins, the StrobeMediaPlayback_config.html must be loaded from an "http://" URL, not directly from your file system. This is due to Flash Player cross-domain security. The video should play back after the JavaScript alert has appeared and OK is clicked to clear the alert.

Loading the plug-in
Figure 5. Loading the plug-in

The Strobe Media Playback component offers a powerful out-of-box solution that is easy to configure and deploy. Sometimes that's just not enough, however, and tighter integration to an existing application or in-depth customizing is required. In these cases, building a custom player might be your best solution. In the next section, you'll learn how to create a simple media player using OSMF to play back progressive, streaming FLV, and H.264 media.

Walkthrough 1: The simplest player

In this walkthrough, you will create a very simple media player using the OSMF and the MediaPlayerSprite object. The purpose is to see how to create the simplest form of an OSMF player and play back progressive, streaming FLV, and H.264 media.

Objectives

  • Create the simplest form of a OSMF media player.
  • Use the MediaPlayerSprite object to handle the heavy lifting and keep the component implementation simple.
  • Simply and directly create a URLResource and VideoElement.
  • Play back progressive and RTMP streaming media using the same player.
  • Play back a streaming H.264 MPEG based file by applying the proper path prefix.

Setup

Follow these steps to set up the player:

  1. Open the file WT01_SimplestPlayer.as in the {SAMPLES_PROJECT}/src directory.

Note: This file has been provided as a starting point for these walkthroughs.

  1. Set the class file as the application file to compile. There are two different ways of doing this, depending on which program you are using to build your application:
  • Flash Builder: Right-click WT01_SimplestPlayer.as and select Set as Default Application from the context menu that appears. This adds the project to the list of compilable applications. A blue dot on the file icon indicates that the file is the default application file.
  • Flash Professional: Open OSMF_SampleTemplate.fla and save it as WT01_SimplestPlayer.fla. Change the document class for the file (in the Properties panel) to WT01_SimplestPlayer.

Building the simplest player

Follow these steps to build the player:

  1. Under the "DECLARATION" comment, create a public variable named playerSprite that is typed as a MediaPlayerSprite object:
public var playerSprite:MediaPlayerSprite;
  1. Locate the initPlayer method. This method is called when the media player starts up.
  2. Inside the initPlayer method, set the playerSprite property equal to a new MediaPlayerSprite object:
playerSprite = new MediaPlayerSprite();
  1. Create a local variable named resource that is typed as a URLResource object. Set this equal to a new URLResource object and make sure you pass the static const variable PROGRESSIVE_PATH as the only parameter to the constructor:
PROGRESSIVE_PATH as the only parameter to the constructor: playerSprite = new MediaPlayerSprite(); var resource:URLResource = new URLResource( PROGRESSIVE_PATH );
  1. Set the media property of the playerSprite object equal to a new VideoElement object, passing the resource variable as the only parameter to the constructor:
playerSprite = new MediaPlayerSprite(); var resource:URLResource = new URLResource( PROGRESSIVE_PATH ); playerSprite.media = new VideoElement( resource );
  1. Call the addChild method, passing it the playerSprite :
playerSprite = new MediaPlayerSprite(); var resource:URLResource = new URLResource( PROGRESSIVE_PATH ); playerSprite.media = new VideoElement( resource ); addChild( playerSprite );
  1. The completed initPlayer method should look like this:
protected function initPlayer():void { playerSprite = new MediaPlayerSprite(); var resource:URLResource = new URLResource( PROGRESSIVE_PATH ); playerSprite.media = new VideoElement( resource ); addChild( playerSprite ); }
  1. Save the file and run WT1_SimplestPlayer.as as a web application. The player should start up and play the progressive A Faery's Tale video (see Figure 6).
The simplest player, playing a progressive video
Figure 6. The simplest player, playing a progressive video
  1. Change the path that is passed to the URLResource constructor to be STREAMING_PATH . Notice that this path starts with "rtmp://" and does not have a file extension. Save the file and run it as a web application. Now the Akamai Anniversary video should play (see Figure 7). The same code used for the progressive video playback works great for streaming media.
The simplest player, playing a streaming video
Figure 7. The simplest player, playing a streaming video
  1. Update the path that is passed to the URLResource constructor to be STREAMING_MP4_PATH. Make note of the "mp4:" that is part of this path and that this path does have a file extension. When this version is run, the streaming H.264 Elephants Dream video should play (see Figure 8).
The simplest player, playing an H.264 video
Figure 8. The simplest player, playing an H.264 video

With OSMF, building a simple player with a lot of power is easy, but rarely is it enough just to show video. Often, finer-tuned control of the media loading and display process is needed. The next walkthrough will show how to separate some of the OSMF internals to provide greater control and understanding of the moving parts within a media player.

Walkthrough 2: Separating control

In this walkthrough, you will break out the main control objects of an OSMF media player. You will learn about the different components available to create an OSMF experience and how they can be managed independently instead of using the all-in-one MediaPlayerSprite object. In the end, it all works the same; but now there are separate instances to control the connection, playback, and visual display.

Objectives

This walkthrough will demonstrate the use of the following objects:

  • NetLoader: To manage the external connection/loading for the VideoElement or MediaElement
  • MediaPlayer: A non-visual item to manage the playback and control of a MediaElement
  • MediaContainer: The visual container for managing the display and layout of a MediaElement

Setup

Follow these steps to set up the player:

  1. Open the file WT02_SeparatingControl.as in the {SAMPLES_PROJECT}/src directory.
  2. Set the class file as the application file to compile. There are two different ways of doing this, depending on which program you are using to build your application:
  • Flash Builder: Right-click WT02_SeparatingControl.as and select Set as Default Application from the context menu that appears. This adds the project to the list of compilable applications. A blue dot on the file icon indicates that the file is the default application file.
  • Flash Professional: Open OSMF_SampleTemplate.fla and save it as WT02_SeparatingControl.fla. Change the document class for the file (in the Properties panel) to WT02_SeparatingControl.

Breaking out the control objects

Follow these steps to break out the main control objects:

  1. Remove the public var playerSprite and replace it with two variables: player , typed as a MediaPlayer object, and container , typed as a MediaContainer object:
public var player:MediaPlayer; public var container:MediaContainer;
  1. Inside the initPlayer method, remove the line that created the playerSprite object as well as the other playerSprite references—including the addChild method. The initPlayer method should look similar to this:
protected function initPlayer():void { var resource:URLResource = new URLResource( STREAMING_MP4_PATH ); }
  1. Under the declaration of the resource variable, create a new local variable named netLoader and set it equal to a new NetLoader object. The NetLoader object enables you to have more control over the connection made to load the media.
var resource:URLResource = new URLResource( STREAMING_MP4_PATH ); var netLoader:NetLoader = new NetLoader();
  1. Create a VideoElement object named element and pass the VideoElement's constructor the resource and netLoader variables as parameters:
var resource:URLResource = new URLResource( STREAMING_MP4_PATH ); var netLoader:NetLoader = new NetLoader(); var element:VideoElement = new VideoElement( resource, netLoader );

Now, when the VideoElement is created, it will use your explicit NetLoader.

  1. Set the player property equal to a new instance of the MediaPlayer object. Make sure to pass the element variable to the constructor:
var element:VideoElement = new VideoElement( resource, netLoader ); player = new MediaPlayer( element );
  1. Set the container property equal to a new instance of the MediaContainer object, and then call the addMediaElement method on the container property, passing it the element variable:
var element:VideoElement = new VideoElement( resource, netLoader ); player = new MediaPlayer( element ); container = new MediaContainer(); container.addMediaElement( element );
  1. Call the addChild method and pass the container property to the addChild method. The completed initPlayer method should look like this:
protected function initPlayer():void { var resource:URLResource = new URLResource( STREAMING_MP4_PATH ); var netLoader:NetLoader = new NetLoader(); var element:VideoElement = new VideoElement( resource, netLoader ); player = new MediaPlayer( element ); container = new MediaContainer(); container.addMediaElement( element ); addChild( container ); }
  1. Save and run the application. The Elephant's Dream video should play just as in Walkthrough 1. What this walkthrough has done is expose the control elements—NetLoader, MediaPlayer, and MediaContainer—of the media playback application.

Separating out the different controllers within a media player opens up the door to truly taking control of the capabilities of the player and the user experience when customization is needed. Toward that same goal, it lays the foundation for extending the implementation to take fuller advantage of the power of OSMF. Taking what has been completed already and adding support for any of the media supported by Flash Player (images, audio, video, and other SWFs) is the next step in harnessing the power of OSMF.

Walkthrough 3: Handling different media

In this walkthrough, you will extend the media player so it can handle different types of media. This will show you how to use a MediaFactory and the generic MediaElement so the player can handle any of the supported media types without having to know what kind of media is being loaded. This way the player isn't tied to a VideoElement, for instance, that won't be able to play a SWF file or a dynamic multi-bitrate stream.

Objectives

  • Gain a better understanding of specific media element types and their limitations when explicitly created.
  • Implement support for the media playback application to handle different types of media (SWF, video, and audio) through the use of a MediaFactory.
  • Use an F4M external XML-based file to define and load the appropriate content.
  • Implement HTTP Dynamic Streaming via the use of an F4M file.

Setup

Follow these steps to set up the player:

  1. Open the file WT03_HandlingDifferentMedia.as in the {SAMPLES_PROJECT}/src directory.
  2. Set the class file as the application file to compile. There are two different ways of doing this, depending on which program you are using to build your application:
  • Flash Builder: Right-click WT03_HandlingDifferentMedia.as and select Set as Default Application from the context menu that appears. This adds the project to the list of compilable applications. A blue dot on the file icon indicates that the file is the default application file.
  • Flash Professional: Open OSMF_SampleTemplate.fla and save it as WT03_HandlingDifferentMedia.fla. Change the document class for the file (in the Properties panel) to WT03_HandlingDifferentMedia.

In this start file we added two additional paths for media: one that is a SWF file and another that is an F4M file for Dynamic Streaming. Try to play the SWF file in the media player's current state.

Handling different types of media

  1. Change the variable that is being passed to the URLResource constructor from STREAMING_MP4_PATH to LOCAL_SWF .
  2. Save and run the application. Nothing should happen because the VideoElement object doesn't know how to deal with a SWF file.

Using the MediaFactory object

  1. Create a new class property named mediaFactory and typed as a DefaultMediaFactory object:
public var player:MediaPlayer; public var container:MediaContainer; public var mediaFactory:DefaultMediaFactory;
  1. Inside the initPlayer method, remove the line that creates the netLoader object. Replace that line with a line that sets the mediaFactory property equal to a new instance of a DefaultMediaFactory object:
var resource:URLResource = new URLResource( LOCAL_SWF ); mediaFactory = new DefaultMediaFactory();
  1. Replace the code that sets the element variable with code that calls the createMediaElement method on the mediaFactory property—you will need to pass the resource variable to the createMediaElement method. You will also need to change the variable type from VideoElement to MediaElement.

Note: The MediaFactory will generate the appropriate MediaElement for the content dynamically for you, thus abstracting the content type from the player capabilities.

Before:

var element:VideoElement = new VideoElement( resource, netLoader );

After:

var element:MediaElement = mediaFactory.createMediaElement( resource );
  1. Save the file and run the application. This time the SWF file—a looping fade-in of the OSMF logo with text below it—should appear (see Figure 9).
Loading a SWF file by using MediaFactory instead of VideoElement
Figure 9. Loading a SWF file by using MediaFactory instead of VideoElement
  1. Replace the LOCAL_SWF variable passed to the URLResource constructor with the DYNAMIC_STREAMING variable. This should play the dynamic stream defined by the loaded F4M file (see Figure 10).
Dynamic stream defined by the loaded F4M file
Figure 10. Dynamic stream defined by the loaded F4M file
  1. The Flash Media Manifest contains information about a Flash media asset such as location of the media, multi-bitrate information, and additional metadata. The OSMF parses this XML-based file to create a DynamicStreamResource.

Note: If you'd like to see how to manually define a dynamic streaming resource, a sample has been provided in the DynamicStreamSample.as file.

Where to go from here

In this tutorial, you learned many of the basics of working with the Open Source Media Framework. Understanding how to implement a media player and the core parts that can be separated to enhance the control and leverage the full spectrum media type support is just the first step on the path to mastering OSMF.

Part 2: Creating and customizing your player focuses on building the UI with the help of OSMF, and extending the media experience with compositions to handle more in-depth use cases and start to really let the power of OSMF shine.

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Mastering OSMF – Part 2: Creating and customizing your player
  • Using the Flash OSMF Media Player template
  • Mastering OSMF – Part 3: Working with plug-ins
  • Web video template: Media presentation with details
  • Web video template: Showcase website for personal video
  • Webcam Motion Detection: Using the BitmapData API in Flash 8
  • RealEyes OSMF Player Sample – Part 1: Setup and deployment
  • Customizing the FLVPlayback component
  • Producing audio for the web using Soundbooth and Flash
  • Exploring the Flash video templates and tutorials

Flash User Forum

More
04/23/2012 Auto-Save and Auto-Recovery
04/23/2012 Open hyperlinks in new window/tab/pop-up ?
04/21/2012 PNG transparencies glitched
04/01/2010 Workaround for JSFL shape selection bug?

Flash Cookbooks

More
02/13/2012 Randomize an array
02/11/2012 How to create a Facebook fan page with Flash
02/08/2012 Digital Clock
01/18/2012 Recording webcam video & audio in a flv file on local drive

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement