Windows apps
Collapse the table of content
Expand the table of content

switch

banner art
PreviousNext

switch

The switch element provides a series of alternative sources if access to one fails.

Attributes

The following table identifies the optional attributes that are supported by Windows Media Services for the switch element. The predefined system test attributes described in the SMIL 2.0 specification are not supported.

Attribute Description
syncEvent Sends a playlist synchronization event from the shared playlist for a publishing point to all client wrapper playlists.
id Uniquely identifies an element. This value must begin with a letter.

Remarks

The WMS SMIL Playlist Parser plug-in enforces case sensitivity on the switch element.

You can use the switch element to specify a set of alternative elements from which only one can be chosen. The Windows Media server evaluates all media elements in the order they occur in the switch statement and selects the first element that can be streamed. After the selected stream ends, the server exits the switch statement and continues processing the remainder of the playlist.

Example Code

The switch statement is often used to implement failover. However, you must be careful how you use it. The following example illustrates a common implementation that results in high latency and possible timeouts:

<?wsx version="1.0"?>
<!---Bad failover example. 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>

If the server cannot establish a connection to media1, it attempts to connect to media2. However, switching delays may cause the client to time out. This playlist does not result in a fault-tolerant broadcast for two reasons:

  • Switching from one network encoder to another takes a minimum of 20 seconds. This delay may cause some players to time out and disconnect.
  • The Auto Reconnect feature in Windows Media Services creates an additional delay because it transparently attempts to request reconnections to data sources that are interrupted during a broadcast. Thus, in this example, the server will try to reconnect to the first encoder five times before reporting that the encoder is not valid. This process can cause enough delay that clients connected to the broadcast may time out and disconnect.

To avoid these problems, you can use the WMReconnect URL modifier in the src attribute as illustrated in the following example.

<?wsx version="1.0"?>
<smil>
   <switch>
      <media id="media1" src="http://encoder1:8080?WMReconnect=0"/>
      <media id="media2" src="Alternate_1.wmv"/>
   </switch>
   <switch>
      <media id="media3" src="http://encoder2:8080?WMReconnect=0"/>
      <media id="media4" src="Alternate_2.wmv"/>
   </switch>
</smil>

In this example, if the server cannot connect to media1 or the connection fails, it plays the file Alternate_1.wmv and, while playing Alternate_1.wmv, immediately attempts to connect to media3. If it cannot connect to media3, it plays the file Alternate_2.wmv. 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.

  • Note   You can also use the WMNoDataTimeout and WMNoDataTimeout2 URL modifiers to specify the amount of time that will elapse before the server should switch to an alternate content source. The WMNoDataTimeout modifier specifies the timeout period for when the broadcast fails or is interrupted. The WMNoDataTimeout2 modifier specifies the timeout period for when the broadcast is stopped due to user intervention. Use these modifiers in the same manner as the WMReconnect modifier. In the following example, when the Windows Media server detects that the encoder is no longer streaming data, it switches to an alternate content source after 1 second has elapsed:

    <?wsx  version="1.0" encoding="utf-8"?>
  • <smil>
  •    <media src="http://encoder1:8080?WMNoDataTimeout=1000"/>
  •    <media src="http://encoder2:8081"/>
  • </smil>
  • Note   For more information about the SMIL 2.0 Specification, W3C Recommendation, see the W3C Web site.

Web addresses can change, so you might be unable to connect to the Web site or sites mentioned here.

See Also

PreviousNext
Show:
© 2018 Microsoft