Not yet rated

Problem

I have multiple pieces of media that I wish to display/playback -- at the same time.

Solution

Use the ParallelElement 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 ParallelElement, which can be used to have the same MediaPlayer instance, playback multiple MediaElement instances, concurrently (at the same time).

Obviously, you will need to adjust the layout of each MediaItem, using LayoutMetadata objects (as seen in this example).

Then, as you playback your media, the playback of both will be tied together (e.g., pause the MediaPlayer instance pauses all MediaElements playing back).

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, size and position two LayoutMetadata objects
layout1 = new LayoutMetadata(); 
layout1.width = 320; 
layout1.height = 240; 
layout1.x = 0; 
layout1.y = 0; 
layout2 = new LayoutMetadata(); 
layout2.width = 320; 
layout2.height = 240; 
layout2.x = 320; 
layout2.y = 240; 
//create a new ParallelElement
parallelElement = new ParallelElement ( ) ; 
//tie each LayoutMetadata object to one of the MediaElement objects
mediaElement1.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout1); 
mediaElement2.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout2); 
//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 parallelElement
mediaPlayer.media = parallelElement; 
//create a new MediaContainer
mediaContainer = new MediaContainer(); 
//add both MediaElement instances to the parallelElement
parallelElement.addChild ( mediaElement1 ) ;
parallelElement.addChild ( mediaElement2 ) ;
//add the parallelElement to the MediaContainer
mediaContainer.addMediaElement(parallelElement); 
//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