Server-Side Playlists

Microsoft Silverlight will reach end of support after October 2021. Learn more.

For Silverlight, a server-side playlist (SSPL) is a sequence of media assets (either audio or video) that allows server administrators to control the sequence of media viewed by users. This playlist can be created statically or dynamically. A server-side playlist used to serve media to Silverlight can be used only for streaming (either on-demand or broadcast); it cannot be used to serve downloaded media. Silverlight uses .wsx configuration files to specify an SSPL that can be served to the client via the MediaElement object. Some advantages of using an SSPL include the following:

  • Because the server seamlessly switches between the media files in a playlist, you can customize the viewer experience by combining multiple digital media files into what will appear to the end user to be a single content stream. This minimizes bandwidth spikes by decreasing the number of times that clients must connect to retrieve content.

  • When users connect to a site before a live broadcast has started, you can provide media that plays in a loop while users wait for the live broadcast to begin.

  • You can use the server object to specify dynamically what media files to stream. In other words, you can edit the playlist even while a client is viewing a stream identified by the playlist.

  • You can gain additional control over playback of your media. For example, you can play only a portion of a media file, and you can specify a certain file to play if another file fails to load.

To use a server-side playlist in your Silverlight application, you must create a .wsx file on your server, publish it, and then connect your client (via MediaElement) to the published stream that represents the .wsx file.

NoteNote:

Silverlight does not support all the tags and functionality offered by .wsx files. For details, see Integrate a Playlist into Silverlight later in this topic.

Creating a .wsx File

A .wsx file is an XML file that defines what you want your playlist to contain and how it should behave. The following .wsx file example specifies three media files to be played, one after the other.

<?wsx version="1.0"?>
<smil>
  <seq id="sq1">
   <media id="video1" src="clip1.wmv" />
   <media id="video2" src="clip2.wmv" />
   <media id="video3" src="clip3.wmv" />
  </seq>
</smil>

A variety of elements and attributes are supported by .wsx files to provide greater control over media playback than simply playing one video after the other. For example, you can use the clipBegin and clipEnd attributes to serve up a portion of a video. The following example shows how to specify a 15-second portion of a video file to be played.

...
  <media id="video1" src="clip1.wmv" clipBegin="15s" clipEnd="30s" />
...

Silverlight supports a subset of the playlist elements and attributes defined by Windows Media. The following table shows the playlist elements and attributes supported by Silverlight. For more information, see the Windows Media 9 Series Playlist Reference in the MSDN Library.

Element & description

Supported attributes

smil - The root of the playlist.

id, repeatDur, dur, repeatCount

switch - Wraps a series of items and allows the server to switch between them if access to one of the items fails.

id

media - Defines an audio or video file in the playlist.

dur, id, repeatCount, repeatDur, role, src (only streaming video or audio)

excl - A time container in which only one media element can be played at a time, but the order in which the elements are played is not restricted.

dur, id, repeatCount, repeatDur

seq - A time container that forces media elements within it to play in the order in which they appear within the seq element.

dur, id, repeatCount, repeatDur

After you have created a playlist file, you may have to configure the server to work with playlists by adding the MIME type for .wsx files.

Integrating a Playlist into Silverlight

To play media in your Silverlight-based application, reference your playlist file using a MediaElement. The .wsx file is used on Windows Media Services (WMS) as the source for the on-demand/broadcast publishing point. For example, if the .wsx file is sample_playlist.wsx and the publishing point is Server:8081/samplePlaylist, then the MediaElement definition would be something like the following.

...
  <MediaElement Source="mms://Server:8081/samplePlaylist" />
...

There are a number of things to keep in mind when using MediaElement with a server-side playlist:

  • MediaOpenedevent. This event is raised when the playlist changes entries. In other words, the event is raised when a new item in the playlist starts playing.

  • MediaEndedevent. This event does not occur when the playlist changes entries; it occurs only after the entire playlist has completed.

  • Pausemethod /CanPauseproperty. For an SSPL presented as a broadcast stream, CanPause is always false, and calling the Pause method does nothing. For an SSPL presented as on-demand content, CanPause is true, and the content can be paused at any frame.

  • Stopmethod. Where playback resumes after calling the Stop method varies depending on whether the playlist is presented as a broadcast stream or as on-demand content. For a broadcast stream, the stream resumes at the point where the Stop method was called. For on-demand content, the stream resumes at the first entry in the playlist.

  • Seeking behavior / CanSeek. Seeking is not supported for either on-demand or broadcast streams in Silverlight 5. CanSeek always returns false for an SSPL.

  • Not All Media Supported. Only Windows Media container files (ASF/WMA/WMV) are supported.