Not yet rated

Problem

I have multiple pieces of media that I wish to display/playback, one after the other, in a prescribed order.

Solution

Use the SerialElement in OSMF to group your media together for concurrent display.

Detailed explanation

 With OSMF, the MediaPlayer class can play back any type of MediaElement -- even what we might call 'complex' media elements.
 
One specific type of such 'complex' media elements is called the SerialElement, which can be used to have the same MediaPlayer instance, playback multiple MediaElement instances, consecutively (one after another, in a pre-determined order).
 
Then, as one media completes playback, the next one will automatically begin.
 
The source files (for Flash CS4 and CS5) are attached to this post. Obviously, you will need to change the constants, MEDIA_URL and MEDIA_URL2 to point to media that exists on your computer.
 
 
        //create a new DefaultMediaFactory
mediaFactory = new DefaultMediaFactory(); 
//use the mediaFactory to create two new MediaElement objects
mediaElement1 = mediaFactory.createMediaElement(new URLResource(MEDIA_URL)); 
mediaElement2 = mediaFactory.createMediaElement(new URLResource(MEDIA_URL2)); 
//create a new SerialElement
serialElement = new SerialElement ( ) ; 
//create a new MediaPlayer instance
mediaPlayer = new MediaPlayer(); 
//set the mediaPlayer not to begin playback by default
mediaPlayer.autoPlay = false; 
//set the media property of the mediaPlayer to the serialElement
mediaPlayer.media = serialElement; 
//create a new MediaContainer
mediaContainer = new MediaContainer(); 
//add both MediaElement instances to the serialElement
serialElement.addChild ( mediaElement1 ) ;
serialElement.addChild ( mediaElement2 ) ;
//add the serialElement to the MediaContainer
mediaContainer.addMediaElement(serialElement); 
//add the mediaContainer to the display list
addChild(mediaContainer); 
  
 
 
 

 


+
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