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

Note:

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.

Note:

Use the MediaPlayer sample, MediaPlayer.as, 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(); 
         video.attachNetStream(stream);
  4. Define a series of play() methods on the NetStream object:

         stream.play( "advertisement", 0, 30 ); 
         stream.play( "myvideo", 10, -1, false ); 
         stream.play( "bikes", 0, -1, false ); 
         stream.play( "parade", 30, 120, false); 
         addChild(video);
  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"); 
             break; 
         case "NetStream.Play.StreamNotFound": 
             trace("The server could not find the stream");  
             break; 
     }

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.

ns.play(“streamA”, 0, -1, true); 
ns.play("streamB", 0, -1, false); 
ns.play("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 
ns.play2(param);

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. 
    this.myStream.play("liveStream1”, -1, 30); 
    // Play a recorded stream in full after liveStream1 plays. 
    this.myStream.play("mp4:recordedStream1.f4v", 0, -1, false); 
    // Play another live stream for 30 seconds after recordedStream1 plays. 
    this.myStream.play("liveStream2", -1, 30, false) 
}

To play the playlist, call NetStream.play("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 Stream.play() 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 NetStream.play("mp4:playlist.f4v") on the client.

application.onAppStart = function(){ 
    this.clientStream = Stream.get("mp4:playlist.f4v"); 
    this.clientStream.record(); 
    this.clientStream.play("mp4:british.mp4", 0, -1); 
    this.clientStream.play("mp4:shadows.mp4", 0, -1, false); 
};
[adobebyline]The following example was provided by Jens Loeffler on his blog flashstreamworks.com.[/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(); 
        application.myStream.play("mp4:titles.f4v", 0, 15); 
        application.myStream.play("livesmith", -1, 30, false); 
        application.myStream.play("mp4:smitharchive.mp4", 0, 30, false); 
        application.myStream.play("mp4:closing.f4v", 0, 15, false); 
    } 
};

To play this example, the client calls NetStream.play("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.)

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy