banner art

switch element

The switch element specifies alternative media elements that can be used if one or more of the current media elements fails. The server evaluates the child elements within the switch element in the order they are listed in order to identify a valid element that can be successfully accessed and streamed. When the server identifies and streams a valid element, the other elements within the switch element are ignored. After the selected element stops streaming, the server continues to stream the portion of the playlist after the switch element.

The switch element is useful for implementing content rollover in a server-side playlist. You can configure content rollover by using the switch element with multiple live sources and stored files to provide fault tolerance for your stream.

The following example illustrates a flaw in the way the switch element is often used to provide fault tolerance. This sample playlist uses a switch element to reference streams from two alternative encoders:

<?wsx version="1.0"?>
<!---This playlist contains an error. Do not use.--->
<smil>
   <switch>
	<media id="media1" src="http://encoder1:8080"/>
	<media id="media2" src="http://encoder2:8080"/>
   </switch>
   <media id="media3" src="Alternate.wmv"/>
</smil>

In this playlist, the switch element is the first active element. First, the server attempts to connect to the media element named media1. If the server cannot establish a connection to media1, the server attempts to connect to media2. If the server cannot establish a connection to media2, the switch element ends, and the server plays media3 instead. Although that is the expected server behavior, the end user will probably not receive the full sequence because switching delays may cause a time-out condition in the player. This playlist does not result in a fault-tolerant broadcast for two primary reasons:

Because of these potential problems, it is best to add the Fast Streaming modifier WMReconnect to the encoder URLs. In this example, the modifier prevents the Fast Reconnect feature from attempting to reconnect to the encoder and enables the playlist to switch to Alternate.wmv while the server attempts to connect to the second encoder. The following example playlist provides fault tolerance and prevents client time-outs during the switch to the other encoder:

<?wsx version="1.0"?>
<!---This example shows the use of a switch element with a WMReconnect modifier.--->
<smil>
   <switch>
	<media id="media1" src="http://encoder1:8080?WMReconnect=0"/>
	<media id="media2" src="Alternate.wmv"/>
   </switch>
   <switch>
	<media id="media3" src="http://encoder2:8080?WMReconnect=0"/>
	<media id="media4" src="Alternate.wmv"/>
   </switch>
</smil>

In this example, if the server connects to media1 and that connection ends or fails, the server will not attempt to reconnect to the source. Instead it immediately plays the file Alternate.wmv and then attempts to connect to media3. If the repeatCount or repeatDur attribute of the smil element is set to Indefinite, then the server continually tries to connect to the encoders until one of the encoders is back online. You can use this type of playlist syntax to maintain connections with both players and distribution servers during a broadcast.

Attributes

Attributes modify the properties of a playlist element. You can use the following optional attributes with a switch element.

Name Description
syncEvent Specifies a string used to trigger the beginning or end of an element in a wrapper playlist. For more information, see syncEvent attribute.
id Specifies a name for the switch element that can be referenced by other elements. For more information, see id attribute.

You can use the switch element in combination with a client-side playlist (a Windows Media metafile with an .asx file name extension) in order to provide a higher level of fault tolerance. For example, assume that the following .asx file refers to publishing points that reference the playlist from the previous example:

<ASX version="3.0">
  <TITLE>MyServer Rollover</TITLE>
  <ENTRY>
	<REF HREF="mms://server1/pubpoint1" />
	<REF HREF="mms://server2/pubpoint1" />
	<REF HREF="mms://server3/pubpoint1" />
  </ENTRY>
</ASX>

The previous example .asx file provides clients with alternative servers in case the client is unable to establish a connection with the primary server. After the client successfully connects to a server, the server-side playlist provides encoder rollover.

Note Image Note

Related topics


© 2005 Microsoft Corporation. All rights reserved.