Working with playlists

About playlists

A playlist is a list of streams to play in a sequence. The server handles the list of streams as a continuous stream and provides buffering, so that the viewer experiences no interruption when the stream changes. You can use both client-side ActionScript and Server-Side ActionScript to create playlists.

Adobe Evangelist Jens Loeffler has written an Adobe DevNet article that uses client-side and server-side playlists to edit live streams into a highlight reel.

Create a client-side playlist


There is a bug that impacts client-side playlists that are missing their first item. The first time a user plays such a playlist, the playlist skips the item and plays. Every subsequent time a user plays the playlist, the playlist does not play.

This playlist uses the names of streams that are stored on the server. To change the playlist, you need to change the code in your application client.


Use the MediaPlayer sample,, written in ActionScript 3.0.

  1. Create a NetConnection object, connect to the server, and add a netStatus event handler.

  2. Create a NetStream object and listen for netStatus events:

     private function createPlayList(nc:NetConnection):void { 
         stream = new NetStream(nc); 
         stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
         stream.client = new CustomClient(); 
  3. Attach the NetStream object to a Video object:

         video = new Video(); 
  4. Define a series of play() methods on the NetStream object:
 "advertisement", 0, 30 );  "myvideo", 10, -1, false );  "bikes", 0, -1, false );  "parade", 30, 120, false); 
  5. Listen for NetStream event codes in your netStatus event handler:

     private function netStatusHandler(event:NetStatusEvent):void 
         case "NetStream.Play.Stop": 
             trace("The stream has finished playing"); 
         case "NetStream.Play.StreamNotFound": 
             trace("The server could not find the stream");  

This playlist plays these streams:

  • A recorded stream named advertisement.flv, from the beginning, for 30 seconds

  • The recorded stream myvideo.flv, starting 10 seconds in, until it ends

  • The recorded stream bikes.flv, from start to end

  • The recorded stream parade.flv, starting 30 seconds in and continuing for 2 minutes

Swap streams in a playlist

Flash Player 10 and Adobe Media Server 3.5

[adoberuntime]Flash Player 10 and Adobe Media Server 3.5[/adoberuntime]

Swapping streams means to exchange one stream for another. While stream switching occurs at keyframes, swapping streams occurs at the stream boundary. Swapping streams is, therefore, useful with playlists. One use case is with playlists that contain content with advertising segments. After collecting statistics about usage patterns, you can swap one advertisement for another.

Use the NetStream.play2() method with the transition mode SWAP to swap streams in a playlist. The NetStream.play2()method takes a NetStreamPlayOptions object as a parameter. In the NetStreamPlayOptions object, specify the old stream, the stream to switch to, and the kind of transition to use—in this case, NetStreamPlayTransitions.SWAP.

For example, suppose a playlist is set to play Stream A, Stream B, and Stream C, in that order.“streamA”, 0, -1, true);"streamB", 0, -1, false);"streamC", 0, -1, false); 

While Stream A plays, and before the server begins sending Stream C, you determine that you want to play Stream Z instead of Stream C. To perform this transition, use code like the following sample:

var param:NetStreamPlayOptions = new NetStreamPlayOptions(); 
param.oldStreamName = “streamC”; 
param.streamName = “streamZ”; 
param.transition = NetStreamPlayTransitions.SWAP 

The SWAP transition differs from the SWITCH transition. The call to swap streams must occur before the server delivers the old stream (in this example, streamC). If streamC is already in play, the server does not swap the content and sends a NetStream.Play.Failed event. If the server has not yet delivered streamC, the server swaps the content. The result is that streamA, streamB, and streamZ play.

When the server swaps to a stream with different content, the client application resets the buffer. The server swaps the stream at the start of the new stream, ensuring an uninterrupted experience.

Create a server-side playlist

A server-side playlist is a list of media played in sequence over a Server-Side ActionScript Stream object. A playlist can contain both live and recorded media.

A server-side playlist plays over a live stream (the Stream object). You can record the stream as an FLV or F4V file as it plays. If a playlist contains only FLV files, you can record it as an FLV file or as an F4V file. Otherwise , record it as an F4V file.

The following code creates a server-side playlist of two live streams and one recorded stream:

// Start the playlist when the application loads. 
// This is a live playlist, it is not recorded. 
application.onAppStart = function(){ 
    this.myStream = Stream.get("serverplaylist"); 
    // Play a live stream for 30 seconds."liveStream1”, -1, 30); 
    // Play a recorded stream in full after liveStream1 plays."mp4:recordedStream1.f4v", 0, -1, false); 
    // Play another live stream for 30 seconds after recordedStream1 plays."liveStream2", -1, 30, false) 

To play the playlist, call"serverplaylist") on the client. To play the playlist smoothly, set the client-side NetStream.bufferTime property to at least 1 second. (The default value is 0.1 seconds.)

To add media to a playlist, call and pass false for the reset parameter. When you pass false, the media doesn’t start playing until the media currently playing has stopped.

The following server-side code plays two recorded media files consecutively and records them to the file “playlist.f4v”. Each media file plays in its entirety. To play the playlist, call"mp4:playlist.f4v") on the client.

application.onAppStart = function(){ 
    this.clientStream = Stream.get("mp4:playlist.f4v"); 
    this.clientStream.record();"mp4:british.mp4", 0, -1);"mp4:shadows.mp4", 0, -1, false); 
[adobebyline]The following example was provided by Jens Loeffler on his blog[/adobebyline]

Use a server-side playlist to export a highlight clips during a DVR-enabled live event. Build the playlist (for example, an opening clip, then a selected part of the live event, then a section of an archived clip), and record it as an .f4v file. To play the highlight reel, just point your streaming player to the exported .f4v file.

application.myStream = Stream.get("mp4.highlights.f4v"); 
     if (application.myStream){ 
        application.myStream.record();"mp4:titles.f4v", 0, 15);"livesmith", -1, 30, false);"mp4:smitharchive.mp4", 0, 30, false);"mp4:closing.f4v", 0, 15, false); 

To play this example, the client calls"mp4:highlights.f4v").

To play a server-side playlist, set the client-side NetStream.bufferTime property to at least 1 second. (The default value is 0.1 seconds.)

Adobe logo

Sign in to your account