Dynamic Streaming in OSMF 10
April 12, 2010 in Technology
I'm writing some new sample files for OSMF in preparation for my presentation, 'Standardize Your Flash with Adobe OSMF,' which I'll be giving on April 27th at FITC Toronto.
Last time I checked (February), OSMF was in Sprint 9 (and I updated my sample files at that time, posted here). Now, it's in Sprint 10, specifically version 0.93. And Adobe appears to have done a lot to lock down the API, which is definitely an exciting and positive development.
But, of course, there are some significant changes since the Sprint 9 OSMF framework -- so even the files I posted just two months ago are no longer valid. So, since I wrote it as one of the sample files for my talk, I figured I would post the code to run dynamic streaming with OSMF v0.93.
Here is a Flash CS4 document class, assuming you already have your OSMF SWC in your library path.
package { import flash.display.Sprite; import org.osmf.media.MediaPlayer; import org.osmf.containers.MediaContainer; import org.osmf.media.URLResource; import org.osmf.net.NetLoader; import org.osmf.elements.VideoElement; import org.osmf.utils.URL; import org.osmf.net.DynamicStreamingResource ; import org.osmf.net.DynamicStreamingItem ; public class MyPlayer extends Sprite { private const RTMP_URL : String = "rtmp://myhost" ; public function MyPlayer() { player = new MediaPlayer ( ) ; container = new MediaContainer ( ) ; addChild ( container ) ; //set the player to play videos only once by default player.autoRewind=false; var resource : DynamicStreamingResource = new DynamicStreamingResource ( RTMP_URL ) ; var vector : Vector.<DynamicStreamingItem> = new Vector.<DynamicStreamingItem> ( 3 ) ; vector [ 0 ] = new DynamicStreamingItem ( "myMovie_high" , 1500 ) ; vector [ 1 ] = new DynamicStreamingItem ( "myMovie_low" , 400 ) ; vector [ 2 ] = new DynamicStreamingItem ( "myMovie_medium" , 600 ) ; resource.streamItems = vector ; videoElement = new VideoElement( resource ) ; player.media = videoElement ; container.addMediaElement ( videoElement ) ; } private var player:MediaPlayer; private var container:MediaContainer; private var videoElement : VideoElement ; } }
Share and enjoy!
-r





Nice! I’ve just started looking at OSMF at work. I’ll be sure to try and catch your session.