Starting with Open Source Media Framework – OSMF

Open Source Media FrameworkThe Open Source Media Framework – OSMF (former Strobe Media Framework) is a set of components pre-programmed for you to use multimedia in their applications, enables easy deployment of resources that aims to enrich the user experience when it comes to content Multimedia web.

The Open Source Media Framework – OSMF – allows easy deployment of resources that is aimed at enriching the user experience when it comes to multimedia content for web.

Among the resources that can be easily implemented with OSMF include:

  • Video Ad Serving Template(VAST).
  • Media Abstract Sequencing Template (MAST).
  • Media RSS (MRSS).
  • Distribution Format Exchange Profile (DFXP).
  • Synchronized Multimedia Integration Language (SMIL).

Let’s make a first example of a simple player with OSMF in the coming articles, we add more features.
Create a project type ActionScript Project in Flash Builder or a new class ActionScript 3.0 in Flash Professional CS5. We will give the name “MyPlayerOSMF” extending the Sprite class
[ACTIONSCRIPT3]
package
{
import flash.display.Sprite;

[SWF(width=”640″, height=”360″, backgroundColor=”0x000000″,frameRate=”25″)]
public class MyPlayerOSMF extends Sprite
{
public function MyPlayerOSMF()
{
}
}
}
[/ACTIONSCRIPT3]
We have our skeleton, we understand some of the classes OSMF. The most important classes that we need to know to create multimedia players are:

  • MediaPlayer – It is the engine of your player. This class roughly corresponds to a current media player. It has methods and properties to control interface user actions such as play, pause, seek, and stop.
  • MediaElement – Media such as video, audio, image, text and so on. This class represents nothing and everything one can touch MediaPlayer.
  • MediaFactory – converts an url to object so it can be played by the player. The class DefaultMediaFactory instantiates objects of the correct type MediaElement particular video, audio, image or other supported media types as input.
  • MediaPlayerSprite – Provides MediaContainer instances of the class, class and class MediaPlayer DefeaultMediaFactory. The class MediaPlayerSprite provides the easiest way to create a media player with OSMF.

Let some url’s to load videos using progressive downloading and streaming.
[ACTIONSCRIPT3]
private static const VIDEO_RTMP:String = “rtmp://cp67126.edgefcs.net/ondemand/mediapm/strobe/content/test/SpaceAloneHD_sounas_640_500_short”;
private static const VIDEO_HTTP:String = “http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv”;
[/ACTIONSCRIPT3]
We start with an instance of class MediaFactory convert url to MediaElement object and the class will be responsible for creating the necessary element in accordance with what is loaded, video, image or swf. Then we use the MediaPlayer class which contains the basis for controlling the player, has the autoplay = true by default.
[ACTIONSCRIPT3]
package
{
import flash.display.Sprite;

import org.osmf.media.DefaultMediaFactory;
import org.osmf.media.MediaElement;
import org.osmf.media.MediaFactory;
import org.osmf.media.MediaPlayer;
import org.osmf.media.URLResource;

[SWF(width=”640″, height=”360″, backgroundColor=”0x000000″,frameRate=”25″)]
public class MyPlayerOSMF extends Sprite
{
private static const VIDEO_RTMP:String = “rtmp://cp67126.edgefcs.net/ondemand/mediapm/strobe/content/test/SpaceAloneHD_sounas_640_500_short”;
private static const VIDEO_HTTP:String = “http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv”;

private var mediaFactory:MediaFactory;
private var mediaElement:MediaElement;
private var mediaPlayer:MediaPlayer;
private var mediaContainer:MediaContainer;

public function MyPlayerOSMF()
{
mediaFactory = new DefaultMediaFactory();
mediaElement = mediaFactory.createMediaElement(new URLResource(VIDEO_RTMP));

mediaPlayer = new MediaPlayer();
mediaPlayer.media = mediaElement;
}
}
}
[/ACTIONSCRIPT3]
Our player is almost ready, let’s add an instance of the class MediaContainer to enter our player on stage. Following is the complete code.
[ACTIONSCRIPT3]
package
{
import flash.display.Sprite;

import org.osmf.containers.MediaContainer;
import org.osmf.layout.LayoutMetadata;
import org.osmf.media.DefaultMediaFactory;
import org.osmf.media.MediaElement;
import org.osmf.media.MediaFactory;
import org.osmf.media.MediaPlayer;
import org.osmf.media.URLResource;

[SWF(width=”640″, height=”360″, backgroundColor=”0x000000″,frameRate=”25″)]
public class MyPlayerOSMF extends Sprite
{
private static const VIDEO_RTMP:String = “rtmp://cp67126.edgefcs.net/ondemand/mediapm/strobe/content/test/SpaceAloneHD_sounas_640_500_short”;
private static const VIDEO_HTTP:String = “http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv”;

private var mediaFactory:MediaFactory;
private var mediaElement:MediaElement;
private var mediaPlayer:MediaPlayer;
private var mediaContainer:MediaContainer;

public function MyPlayerOSMF()
{
mediaFactory = new DefaultMediaFactory();
mediaElement = mediaFactory.createMediaElement(new URLResource(VIDEO_RTMP));

var layout:LayoutMetadata = new LayoutMetadata();
layout.width = 640;
layout.height = 360;
mediaElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);

mediaPlayer = new MediaPlayer();
mediaPlayer.media = mediaElement;

mediaContainer = new MediaContainer();
mediaContainer.addMediaElement(mediaElement);

addChild(mediaContainer);
}
}
}
[/ACTIONSCRIPT3]
See the player in operation:
[SWF]http://www.leonardofranca.com.br/wp-content/uploads/2010/09/MyPlayerOSMF.swf,640,360[/SWF]

To learn more:
Open Source Media Framework Blog
http://www.adobe.com/devnet/video/articles/osmf_overview.html
http://www.adobe.com/devnet/flash/articles/video_osmf_streaming.html
http://mediapm.edgesuite.net/osmf/swf/ExamplePlayer.swf

Was this article helpful? feel free to make a donation and help keep the blog in the air
ActionScript 3.0, Flash Media Server, Flash Platform, OSMF , , ,

5 comments


  1. Pingback: Leonardo França » Starting with Open Source Media Framework – OSMF | Media Brasil

  2. Pingback: Leonardo França » Starting with Open Source Media Framework – OSMF | Media Brasil

  3. Pingback: Leonardo França » Starting with Open Source Media Framework – OSMF | Mídia Global

  4. Pingback: Leonardo França » Starting with Open Source Media Framework – OSMF | Media Brasil

Leave a Reply