By David Hassoun
 
By John Crosby
 
Created
26 July 2010
 

Requirements

 
Prerequisite knowledge

Basic knowledge of ActionScript 3 and Adobe Flash Builder or Adobe Flash Professional is recommended for this tutorial.
 

 
User level

Intermediate
 

 
Required products

 
Sample files

This article is an introduction to the RealEyes OSMF Player Sample (REOPS) that provides developers, designers, and/or implementers with the proper knowledge to customize and deploy a video solution based on the Open Source Media Framework (OSMF).
 
We provide here only a brief introduction into the visual and technical capabilities and implementation parameters of this new sample. Future articles will dive deeper into the how REOPS uses the OSMF to build a robust media player solution. For now we will concentrate on getting you up and running with OSMF and the REOPS project.
 

 
Getting started with the REOPS

The base of the RealEyes OSMF Player Sample (REOPS) offers an excellent starting point for creating a robust video player utilizing the Open Source Media Framework (OSMF) from Adobe. The REOPS project is meant to be a building block for developers as well as a visual representation to illustrate the capabilities and "how to" of the OSMF (see Figure 1).
 
RealEyes OSMF Player Sample project interface
Figure 1. RealEyes OSMF Player Sample project interface
The REOPS project includes a very extensible and robust control bar skinning solution and templates to help customize the control bar, as well as full-screen support, closed captioning from an external file, and OSMF dynamic plug-in support. The REOPS project can be used to deploy easily customized video players that support progressive video playback, video-on-demand streaming, live streaming and dynamic streaming. What is more, all of these features are configurable from an external XML file.
 
The sample contains the following resources:
 
  • Flash plug-in file (MXP) for easy install of Flash Professional component and the skin template files
  • Flash implementation example for progressive, streaming, and dynamic streaming—including closed captioning for the basic streaming sample, and manual bit-rate switching for the dynamic streaming sample
  • Flash Builder project archive file for the source code and base application setup
All the files for the REOPS project can be found at the Google Code page: http://code.google.com/p/reops/. There are both downloads and SVN access available there.
 
 
REOPS player code
Download the ZIP file accompanying this article (reops_pt1.zip) or you can download the most current version of the code from the Google Code page above. The REOPS project is an ActionScript 3 project. The following describes the main structure of the REOPS project (see also Figure 2):
 
  • REOPS.as: Main application file
  • assets: Contains the following directories:
    • data: Default XML configuration file as well as additional configuration samples for: progressive, streaming, and dynamic streaming
    • skins: Sample skins for the REOPS player
  • com.realeyes.osmfplayer: Main package for the REOPS classes (we'll cover details of the major classes in this and future articles)
  • libs: Contains SWC libraries used in the project
Structure of the REOPS project
Figure 2. Structure of the REOPS project
 
Download the OSMF code
The REOPS project comes with the OSMF.swc file, but you may want to look at the actual OSMF code for yourself. You can get the code in a couple of ways:
 
 
OSMF files
The source files are organized into the following directories (see also Figure 3):
 
  • apps: Sample applications you can use to get familiar the OSMF.
  • docs: ASDocs for the framework classes. This will be in the SVN checkout; you can download the ASDocs from the download page as well.
  • framework: The actual framework code with accompanying test code.
  • libs: Libraries that are used with the samples and tests delivered with the OSMF code.
  • OSMF.SWC: The compiled code to use with your projects. This will be in the downloaded zip file. If you check out the project from SVN, you will need to compile the project to get the osmf.swc file.
  • plugins: Sample OSMF plug-ins built for the OSMF.
Structure of the REOPS source files
Figure 3. Structure of the REOPS source files

 
Setting up the REOPS

Now that you have downloaded the code, you can set up Flash Builder and/or Flash Professional to start working with the project files. The following sections will give you the details to get REOPS working in both environments.
 
 
Setting up the projects in Flash Builder
First, import the REOPS project. Make sure you have downloaded and expanded REOPS.zip or checked out the project code from the Google Code repository:
 
  1. In the Flash Builder main menu, select File > Import.
  2. In the Import dialog box, select General > Existing Projects into Workspace in the tree list and click Next (see Figure 4).
Selecting an import source
Figure 4. Selecting an import source
  1. In the next step of the Import dialog box, click the Browse button next to the Select root directory option and browse to the Flash Builder project archive file or the REOPS project directory of your SVN working copy (see Figure 5).
Browsing for the REOPS project
Figure 5. Browsing for the REOPS project
  1. Select the REOPS project from the Projects list and click Finish. The REOPS project should be successfully set up.
  2. To test the REOPS player, from Flash Builder's main menu select Run > Run As > Web Application. You should see the REOPS player start in the browser and play the sample video.
  3. If you open the REOPS.as file in the default (root) package, after line 100 you will see additional configuration paths that you can use to test the different types of media playback:
    • PlayerConfig_Progressive.xml: For progressive video
    • PlayerConfig_Streaming.xml: For streaming video
    • PlayerConfig_DynStreams.xml: For dynamic streaming video
Note: Later we will show you how to override the default configuration path using FlashVars.
 
 
Setting up the project in Flash Professional
The first thing to do when getting set up is to install the REOPS.mxp file. The MXP file is an Adobe extension file and will automatically install the assets into Flash Professional. Simply double-click the MXP, and as long as you have the Adobe Extension Manager installed (which is installed by default with Flash), it should launch automatically and ask you to verify the user agreement.
 
After you accept, the extension should be installed and you should be prompted to restart Flash if it is already open. In the Adobe Extension Manager, after the extension is installed, it should be selected in the main display list, and you should see the install notes indicating what was installed and where (see Figure 6).
 
Reviewing the installation of REOPS in the Adobe Extension Manager
Figure 6. Reviewing the installation of REOPS in the Adobe Extension Manager
If you simply use the UI Component from Flash Professional Components panel in a FLA file, there will be no outside code dependencies, as the necessary classes are all compiled into the component (see Figure 7).
 
Reviewing the REOPS component in the Components panel
Figure 7. Reviewing the REOPS component in the Components panel
Besides a skin SWF file containing the visual controls, the only external dependency when using the UI Component is the required external XML configuration file. That XML file, along with the skin, will need to be deployed with the player SWF file after it is compiled from the FLA file. The path for the configuration file can be set from the Component Inspector (see Figure 8).
 
Inspecting the configpath in the Component Inspector panel
Figure 8. Inspecting the configpath in the Component Inspector panel
Although there are no external code dependencies, the OSMF and the Closed Caption application used by the REOPS component require two compiler configuration constants to be defined for the FLA source file.
 
To set these constants:
 
  1. Open the publish settings dialog box by selecting File > Publish Settings.
  2. From the Publish Settings panel, select the Flash tab near the top (see Figure 9).
Inspecting the Flash tab in the Publish Settings dialog box
Figure 9. Inspecting the Flash tab in the Publish Settings dialog box
  1. Click the ActionScript 3.0 Settings button near the top of the Flash tab's contents.
  2. Within the ActionScript 3.0 Settings panel, select the Config Constants tab.
  3. Inside the tab, add two variables by clicking the + icon button. The first should have a name of CONFIG::LOGGING and a value of false. The second should have a name of CONFIG::FLASH_10_1 and also a value of false. The end result of the panel should look like Figure 10.
Adding the compiler options
Figure 10. Adding the compiler options
If you want to use code base directly in Flash Professional and not through the precompiled component, once you have downloaded the REOPS source code and OSMF source code, you can add those to your application or environment class paths in Flash. You will still need the Config Constants set above.
 

 
Understanding the configuration file

When REOPS starts up, it loads an external XML configuration file. This file should contain configuration data for the following:
 
  • The initial media the player will play
  • Layout specifics for the player skin and controls
  • Any dynamic plugins that REOPS will load
The REOPS XML configuration is made up of all or some of the following XML nodes:
 
  • The <player> node (required): The top-level node that provides some of the basic settings the player needs to know about: width, height, scaleMode, autoPlay, and hasCaptions.
  • The <mediaElement> node (required): Contains the initial media that the player will play. Children of this node can be of the following types:
    • The <mediaElement> node represents an explicit piece of media (video, audio, image, or other media file)
    • The <metaData> node allows the configuration to specify data that will be added to the MediaElement's resource (we will cover more on the resource object later)
    • The <serial> and <parallel> nodes allow for multiple <mediaElement> child nodes and will create a SerialElement or ParallelElement for playback
  • The <skin> node (required): Provides the path to the skin SWF for the Player as well as additional element data for layout and functionality:
    • The <skinElement> node provides data for different skin elements such as the control bar and loading icons
  • The <plugin> node: Provides a list of dynamic plugins that will be loaded via OSMF's PluginLoader. Static plugins are compiled into the REOPS player and will be addressed in a later article.
Quite a few sample XML configuration files are provided in the REOPS project download. If you are using the Flash Builder archive or SVN checkout, look in the assets/data folder. If you are using the MXP, you can look in the following folder:
 
  • Windows: [active user applications directory]AdobeFlash CS4enConfigurationOSMF_SamplesOSMF_Samplesconfigs
  • Mac OS: ~/Library/Application Support/Adobe/Flash CS4/en/Configuration/OSMF_Samples/configs/
Feel free to open them up and explore the different configurations. Take a look at PlayerConfig.xml to become more familiar with how the XML configuration provides data to the REOPS player.
 
Open the PlayerConfig_Streaming.xml file. You will see all of the major XML nodes previously mentioned. Some of the values in this example may differ, but the main idea should be clear. First, look at the <player> node:
 
<player width="640" height="480" scaleMode="stretch" isLive="false" autoPlay="true" updateInterval="250" hasCaptions="true">
Here the player node sets the width, height, and scaleMode attributes of the player. It lets the player know that it will be not be playing live video. The video will play as soon as it is loaded (autoPlay="true") and have closed captioning (hasCaptions="true").
 
 
A note about closed captioning
If the hasCaptions attribute is set to true, the CaptioningPlugin is loaded by the player and will look for metadata specifying where to load the captioning data from. The metadata is set on the <mediaElement> node of a child of the <mediaElement> node and is something that we will cover in a future article.
 
Now look at the <mediaElement> node:
 
<mediaElement> <mediaElement> <id>akamai10yearf8512K</id> <mimeType>video/x-flv</mimeType> <streamType>recorded</streamType> <deliveryType>streaming</deliveryType> <media url="rtmp://www.server.com/app/filename" width="800" height="600" /> <metaData namespace="http://www.osmf.org/captioning/1.0"> <value key="uri" type="class" class="org.osmf.utils.URL"> <url><![CDATA[http://mediapm.edgesuite.net/osmf/content/test/captioning/akamai_sample_caption.xml]]></url> </value> </metaData> </mediaElement> </mediaElement>
The XML snippet above shows a single streaming FLV that has a closed captioning file associated with it. This bit of XML is based on the initial F4M specification from the OSMF project but has been expanded to fit the needs of the REOPS player. Here are the nodes to pay attention to:
 
  • The <media> node: This specifies the RTMP path of the FLV file as well as the width and height attributes.
  • The <metaData> node: This node and its children specify data that is added to the MediaElement that is created when this data is loaded. It provides the path to the closed caption file to load for the media when it plays.
The <skin> node provides the path to the skin SWF file that will be used to set the appearance of the player controls:
 
<skin path="assets/skins/RE_Skin.swf"> <skinElement id="controlBar" elementClass="com.realeyes.osmfplayer.controls.ControlBar" initMethod="initControlBarInstance" scaleMode="NONE" hAdjust="0" vAdjust="0" vAlign="BOTTOM" autoPosition="true" draggable="true" autoHide="true" /> </skin>
You can also provide child <skinElement> nodes to further enhance and adjust the look and functionality of the player's controls. The skinning system will be covered in greater detail in a future article.
 
The <skin> node above loads the RE_Skin.swf file and provides the initial data for the ControlBar class specified by the elementClass attribute.
 
Finally, there is the <plugins> node (the reosmf_config.xml file doesn't contain a <plugins> node). The <plugins> node can have a list of <plugin> children that provide the REOPS player with a list of URLs from which to load dynamic plugins. The REOPS player handles passing these plugins to OSMF's PluginLoader object. Plugins are a large subject on their own, and we will be sure to provide some more detail in a future article.
 
 
Overriding the default XML configuration path
You can also set the XML configuration path via FlashVars. The default XML configuration path is relative to the player SWF file and will look for the assets/data/reosmf_config.xml file. You can override this location by providing a configPath FlashVar and setting it to the path for the XML configuration you wish to load. This would looks something like the following when using SWFObject:
 
var flashvars = { configPath: "assets/data/PlayerConfig_Progressive.xml" }; ... swfobject.embedSWF( "REOPS.swf", "flashContent", "640", "480", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);

 
Creating custom skins for the sample

The REOPS project offers a very powerful, extensible, and easily custom-branded skinning solution. The skinning process is similar to the Flex Component Kit (FCK) for Flash-based skinning. REOPS skinning has support for easy template generation directly from Flash Professional when the provided MXP file been installed, and even includes some top-notch skins designed by Juan Sanchez, illustrating some of the creative possibilities and freedom of the skinning system.
 
Check out Juan's blog post about the design process he used and the implementation with the REOPS project. Figure 11 shows three skins designed by Juan.
 
file
file
Custom skins by Juan Sanchez: Core (top), Formula (middle), and Lunar (bottom)
Figure 11. Custom skins by Juan Sanchez: Core (top), Formula (middle), and Lunar (bottom)
The skin shown in Figure 12 was designed as a full template reference implementation by RealEyes.
 
RE-Skin by David Hassoun, using elements from the Lunar skin
Figure 12. RE-Skin by David Hassoun, using elements from the Lunar skin
All the above skins are installed as Flash templates with the REOPS Flash Extension (MXP). They are accessed in the initial start splash screen > Create from Template > OSMF_Skins or via File > New > Templates (tab on top) > OSMF_Skins (see Figure 13).
 
Selecting RE_Skin from available templates
Figure 13. Selecting RE_Skin from available templates
Aside from offering a graphic and component-based skinning system similar to the FCK, including timeline-driven states that include support for animated states and transitions, the REOPS skinning system has some very powerful and useful capabilities that many other skinning systems may lack. Some of the key differentiators for skinning are self-contained code and functionality and a progressive componentization layout system.
 
Since the skins use a compiled clip for the required code, they have the ability to be compiled or transferred to any other machine or designer/developer without the need to pass along any code or libraries, unless code extension has been applied.
 
The progressive componentization starts with all the pieces of the skin broken into their simplest form (generally graphics that have a high potential of reuse, such as icons), then utilizes combinations of the graphics to create the basic components such as play/pause buttons. At this point, Flash MovieClip timelines come into play for state management (up, over, down, disabled, selectedUp, selectedOver, selectedDown, selectedDisabled). The "selected" states are used for toggle buttons such as volume mute/on, and play/pause. Then the components are laid out into composition skin elements such as the ControlBar or the LoadingIndicator. These components offer the freedom to lay out the buttons and controls any way the design calls for; layout is done within the stage of a MovieClip or via ActionScript 3. The latter is possible if code is extended, as might be desired for more complex solutions. This process of allowing the whole skin element component to be constructed in the skin itself offers some interesting benefits, one of which is very valuable to the design phase itself. While the design is going on, the skin template FLA file can be compiled at any time and the skin element components can be seen in a functional and relatively complete state. This affords the designer/developer uncompromised control over the functional and visual integration of the ControlBar without setting up complex test harnesses.
 
The skin elements are applied to the display within the REOPS application after the skin SWF file is loaded in at runtime. The configuration file defines which elements to apply, not by what is on the stage of the FLA file and seen when the SWF file is run, but rather by the class references for the skin elements in the library of the FLA. The full class paths for the desired skin elements must be defined in the configuration file within the player > skin > skinElement > elementClass node. There is one skinElement node for each skin element component you wish to apply. For instance, if you wanted to apply a ControlBar, a LoadingIndicator, and a ClosedCaptionField, you would have three skinElement nodes. As an example, the default elementClass for the ControlBar in the template is com.realeyes.osmfplayer.controls.ControlBar. This can be found in the FLA file by right-clicking the ControlBar component in the Library and selecting Properties. If you do not see the Class field, make sure you are in the Advanced view, which is selected by a button labeled Advanced on the bottom right of the Basic Symbol Properties panel. If you are in the Advanced view, simply copy the value from the Class field and put it in the elementClass node. This is also where you could apply a custom class that extends the default noted above with additional custom functionality you create, thus offering a very powerful and standard way to add new functionality to your skin elements.
 
Customizing the visual elements of the skins is rather straightforward. The recommended approach is to adjust the graphical symbols such as the button background, icons, and other such pieces, like progress bars. Then, within the example components, which should provide the first level of componentization, adjust the states and transitions as you desire. All the sample elements within the design portion of the FLA file have already been applied with the proper instance names to assist with the next step.
 
The next step is to add or remove any controls or components within the skin element components such as the ControlBar and adjust the positioning as desired. As long as all the subcomponents have the proper instance names, which they all do by default, then they should function as would be expected when utilized within the REOPS application.
 
Additional UI components can be added to the skin elements such as the ControlBar. If their code and functionality is self-contained, then no special changes should be required. If they need to be integrated more closely with the ControlBar functionality and the REOPS, then you will likely have to extend some of the base classes and reapply the new classes to the components in the library. This will be covered in more depth in a future article to help with such cases as wanting to add a share overlay activated by a ControlBar button.
 

 
Deploying the sample

To deploy the REOPS player to your web server, you will need to upload the following files:
 
  • The player SWF file: REOPS.swf
  • The configuration file: resomf_config.xml
  • The skin SWF file specified in the configuration file: assets/skins/RE_Skin.swf
  • The hosting page: index.html
  • The swobject.js file: http://code.google.com/p/swfobject/
The index.html page should embed the player, and if the config XML file path is different from the default path (assets/data/resomf_config.xml), you also need to set the configPath FlashVar with the actual configuration file path.
 
Here's some sample index.html code using SWFObject:
 
<html> <head> <title>REOPS Sample</title> <script type="text/javascript" src="swfobject.js"></script> <script type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> var params = {}; params.quality = "high"; params.bgcolor = "#FFFFFFF"; params.allowscriptaccess = "sameDomain"; params.allowfullscreen = "true"; var attributes = {}; attributes.id = "REOPS"; attributes.name = "REOPS"; attributes.align = "middle"; // Set the config path here var flashvars = { configPath: "path/to/reosmf_config.xml" }; swfobject.embedSWF( "REOPS.swf", "flashContent", 640, 480, "10.0.42", "playerProductInstall.swf", flashvars, params, attributes ); </script> </head> <body> <div id="flashContent"></div> </body> </html>

 
Where to go from here

The REOPS project is just beginning. This base and the future enhancements to the REOPS project should supply an excellent starting point for your own OSMF-based media players, or be used out of the box: simply select one of the existing skin templates or create your own. With what the OSMF project offers, the REOPS project is already able to take advantage of the impressive capabilities it provides to give you a good starting point and stand as an example for some of the solutions that are possible with OSMF.
 
Although the skinning system has the least direct association with the OSMF, its initial capabilities provide a familiar process with enhanced benefits associated with the visual delivery and user interactions. A key principle of the skinning system is its extensibility; a later article in this series will delve more into the how-to of extending the visual side of the REOPS samples.The extensibility of the external configuration system is also worth noting. Already, the basics offered have many uses, but as the REOPS project continues, additional support and capabilities will be added to the external configuration capabilities. Integrating the REOPS sample with application server data services instead of the flat XML format used would be a relatively easy task—and that is just the beginning.
 
We are looking forward to providing a series of articles using the REOPS project to dive deeper into the OSMF. We will discuss real-world solutions and ways to extended the current REOPS project with functionality from the OSMF project as it nears its 1.0 release.
 
Here are a few of the concepts and ideas that we will be covering in future articles:
 
  • HTTP streaming
  • Live DVR
  • DRM protection with Adobe Flash Access 2.0
  • External playback API for episode/playlist user selection:
    • ExternalInterface integration for JavaScript
    • ActionScript 3 API
  • Advertising plug-in integration (VAST/MAST):
    • In play
    • Overlay
    • Outside regions
  • Tracking plug-in integration:
    • Generic JavaScript invokers
    • Google analytics
In Part 2: Building and configuration, we show you how to build a very simple OSMF player to get familiar with the building blocks of the OSMF.
 
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.