Not yet rated

Problem

I have multiple versions of the same video, at different bitrates. I want to stream the best video possible for the viewer, given the viewer's connection speed.

Solution

When streaming with Flash Media Server, utilize the native functionality inside of OSMF, with the DynamicStreamingResource class.

Detailed explanation

This solution not only requires a bit of code (which you see below) but also requires access to a Flash Media Server, which I assume you already have (either installed on your dev machine or server, or leased through an FMS hosting provider, such as Influxis). Currently, natively in OSMF, dynamic streaming only works with RTMP streaming, not HTTP streaming.
 
You can download the completed code (along with an example on the timeline, not using class files) as the attachment to this post. Of course, you will need to point to your own Flash Media Server.
 
We want to use a DynamicStreamingResource, instead of a regular URLResource.
 
A DynamicStreamingResource includes a property, called streamItems, which you use to point to a vector of DynamicStreamingItems. Each DynamicStreamingItem defines one version of the video you wish to play -- you include the filename of the video, as well as the minimum bandwidth required to view that version of video).
 
 
So you would change your code that looks something like this:
 
        var resource:URLResource = new URLResource("my.flv");  
var videoElement:VideoElement =  new VideoElement(resource);   
 
  
To code that looks more like this:
 
        var resource : DynamicStreamingResource = new DynamicStreamingResource ( RTMP_URL ) ;
var vector : Vector.<DynamicStreamingItem> = new Vector.<DynamicStreamingItem> ( 3 ) ;
vector [ 0 ] = new DynamicStreamingItem ( "2012_high" , 1500 ) ; 
vector [ 1 ] = new DynamicStreamingItem ( "2012_low" , 400 ) ; 
vector [ 2 ] = new DynamicStreamingItem ( "2012_medium" , 600 ) ; 
resource.streamItems = vector ;
videoElement = new VideoElement( resource ) ;
 
  
 
 
 
 
 
 
 
 
 

 


+
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