Avg. Rating 5.0

Problem

I want to streaming my video file to my OSMF-based Flash video player, without using Flash Media Server (FMS), using Flash CS4 or CS5.

Solution

Tell OSMF (in ActionScript) to use an HTTPStreamingNetLoader instead of a regular NetLoader. All the rest of your code should work just fine.

Detailed explanation

Here is the completed code, which you can download (along with an example on the timeline, not using class files), as the attachment to this post.

Of course, you will need to replace the MEDIA_URL constant with the proper path to your video file.

package

{ 
    //flash imports
    import flash.display.Sprite; 
    //osmf imports
    import org.osmf.containers.MediaContainer; 
    import org.osmf.elements.VideoElement; 
    import org.osmf.media.MediaPlayer; 
    import org.osmf.media.URLResource; 
import org.osmf.net.httpstreaming.HTTPStreamingNetLoader ;

    public class MyPlayer extends Sprite 
    { 

private const MEDIA_URL : String = "http://myserver.com/my.flv" ;

        public function MyPlayer() 
        { 
            // Create the container class that displays the media. 
             var container:MediaContainer = new MediaContainer(); 
//add the MediaContainer instance to the stage
            addChild(container); 

            // Create the resource to play and point it to the FLV
            var resource:URLResource = new URLResource( MEDIA_URL ); 
             
            // Create the MediaElement 
            var videoElement:VideoElement =  new VideoElement( resource , new HTTPStreamingNetLoader ( ) ); 
//add the VideoElement to our container class
            container.addMediaElement(videoElement); 
             
            //create the MediaPlayer instance
            var mediaPlayer:MediaPlayer = new MediaPlayer(); 
            // Set the MediaElement on a MediaPlayer.  
//Because autoPlay defaults to true, playback begins immediately
mediaPlayer.media = videoElement; 
        } 
    } 
}
HTTP Streaming.zip
[HTTP Streaming in OSMF - Source Files]

+
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.

Report abuse

Related recipes