previous next

Chapter 17: Switching

SMIL switching gives you a powerful way to provide different clips that RealONE Player chooses between based on certain criteria. For example, you can have each RealONE Player select an audio track based on each viewer's language preference. This chapter explains how to set up switch groups to stream different clips to different audiences.

Understanding Switching

SMIL switching is a powerful means to tailor presentations for different audiences without making viewers choose which presentation they wish to view. In cases such as language choice, SMIL switching occurs automatically based on a preference the viewer has set in RealONE Player. In other cases, such as available bandwidth or monitor size, switching is based on an attribute that the viewer does not control. In all cases, however, RealONE Player automatically makes the choice without input from the viewer.

Tip: When you want viewers to choose options themselves, use an <excl> tag, not a <switch> tag. For more on the <excl> tag, see "Creating an Exclusive Group".

Note: The following sections demonstrate switching with clips recorded in different languages. Keep in mind, though, that the same principles apply to switching through other criteria, such as bandwidth or monitor size.

Creating a Switch Group

A switch group starts with a <switch> tag and ends with a </switch> tag. Between these tags, you list multiple options, such as multiple clip source tags, that each contain a test attribute. RealONE Player evaluates the options in the order you list them, choosing the first option that it can play. For example, in the following simple <switch> group, the systemLanguage test attributes cause RealONE Player to choose one of two audio clips based on its language preference:

<switch>
<audio src="french.rm" systemLanguage="fr"/>
<audio src="german.rm" systemLanguage="de"/>
</switch>

Only RealONE Players in which the viewer has selected French (fr) as the language preference will choose the first clip. Only RealONE Players in which the viewer has selected German (de) as the language preference will choose the second clip. A RealONE Player with another language preference will not play either clip: it simply ignores the clips in the <switch> group and proceeds to the next part of the presentation. Hence, a RealONE Player either plays just one clip from a <switch> group, or it plays no clip. But it never plays more than one option.

Adding a Default Option to a Switch Group

To reach the widest audience of viewers, a <switch> group needs to have a default option. Without this option, certain RealONE Players may not play any clips in the group. A default option must satisfy these criteria:

The following example modifies the preceding example to add an English- language clip as the default choice:

<switch>
<audio src="french.rm" systemLanguage="fr"/>
<audio src="german.rm" systemLanguage="de"/>
<audio src="english.rm"/>
</switch>

Note that the English-language clip is listed last and does not include a systemLanguage test attribute, making it the default. In this example, any RealONE Player with a preference set to a language other than French or German will choose the English clip. For example, all RealONE Players with a language preference for Swedish, Korean, English, and so on choose the English-language clip.

Using Inline Switching

It is not always necessary to use a <switch> tag for switching. You can also use inline switching, which adds test attributes to clip source tags in a <par> or <seq> group. When RealONE Player encounters a test attribute, it evaluates the attribute to determine if it should play or skip the clip. In the following example of a parallel group, RealONE Player always plays the Flash clip, and then chooses the French or German audio clip based on its language preference:

<par>
<ref src="cartoon.swf" region="playback"/>
<audio src="french.rm" systemLanguage="fr"/>
<audio src="german.rm" systemLanguage="de"/>
</par>

Choosing Inline Switching or a Switch Group

Although useful in many situations, inline switching cannot provide a default option, making it less powerful than a <switch> group. Consider the following example, which attempts to add a default English-language clip to the preceding example:

<par>
<!-- This is NOT a good example of switching. -->
<ref src="cartoon.swf" region="playback"/>
<audio src="french.rm" systemLanguage="fr"/>
<audio src="german.rm" systemLanguage="de"/>
<audio src="english.rm"/>
</par>

The parallel group shown above will work for every RealONE Player, except those with a French or German language preference! For instance, a RealONE Player with a language preference for French plays the Flash (.swf) clip, the French RealAudio clip, and the English-language clip, which has no systemLanguage attribute that ties it to a language preference. Hence, the viewer hears an incomprehensible blend of French and English.

Only a <switch> tag causes RealONE Player to evaluate all options as a group and choose only one option. The following example illustrates the correct way to add the default, English-language choice to the parallel group shown above:

<par>
<!-- This is a good example of switching. -->
<ref src="cartoon.swf" region="playback"/>
<switch>
<audio src="french.rm" systemLanguage="fr"/>
<audio src="german.rm" systemLanguage="de"/>
<audio src="english.rm"/>
</switch>
</par>

Available Test Attributes

The following table lists the test attributes available for switching. These attributes are described in detail in the remainder of this chapter.

Switch Attributes
Attribute Value Tests For Reference
systemAudioDesc on|off audio descriptions preference click here
systemBitrate bits_per_second total available bandwidth click here
systemCaptions on|off captions preference click here
systemCPU CPU_type computer CPU type click here
systemLanguage language_code language preference click here
systemOperatingSystem OS_name computer operating system click here
systemOverdubOrSubtitle overdub|subtitle overdubbing or subtitle preference click here
systemScreenDepth 1|4|8|24|32 monitor color bit depth click here
systemScreenSize heightXwidth monitor size click here

Tips for Writing Switch Groups

Switching Between Language Choices

When source clips are in different languages, use a test attribute of systemLanguage in the clip source tag or group tag. The following example shows a video slideshow with separate audio narrations in French, German, Spanish, Japanese, Korean, and English. Each RealONE Player requests the same slideshow, but chooses an audio clip based on its language preference and its evaluation of the systemLanguage values:

<par>
<ref src="seattle_slides.rp"/>
<!-- select audio based on RealONE Player language preference setting -->
<switch>
<audio src="seattle_french.rm" systemLanguage="fr"/>
<audio src="seattle_german.rm" systemLanguage="de"/>
<audio src="seattle_spanish.rm" systemLanguage="es"/>
<audio src="seattle_japanese.rm" systemLanguage="ja"/>
<audio src="seattle_korean.rm" systemLanguage="ko"/>
<audio src="seattle_english.rm"/>
</switch>
</par>

The last audio option in the preceding example is the default. Because the last option does not have a test attribute, a RealONE Player that does not have French, German, Spanish, Portuguese, Japanese, or Korean set as its preferred language chooses the English clip.

View it now! (requirements for viewing this sample)
This sample demonstrates language switching . A different number (1 through 5) appears if you set your RealONE Player language preference to French, German, Spanish, Japanese, or Korean. Number 6 is the default, which appears for any other language preference.

Setting Language Codes

Appendix G lists the codes used as systemLanguage values. In some cases, a primary language code has variation codes. For instance, es is the primary code for Spanish, corresponding to Spanish as spoken in Spain. This code has several variations, such as es-mx for Mexican Spanish and es-pr for Puerto Rican Spanish. When variation codes are used, RealONE Player uses the following rules to select a clip:

If you have different clips for different language variations, list the clip that corresponds to the primary code as the last option, as shown here:

<switch>
<audio src="mexico.rm" systemLanguage="es-mx"/>
<audio src="puertorico.rm" systemLanguage="es-pr"/>
<audio src="defaultspanish.rm" systemLanguage="es"/>
</switch>

In the preceding example, RealONE Players with a preference for Mexican Spanish (es-mx) choose the first clip. RealONE Players with a preference for Puerto Rican Spanish (es-pr) choose the second clip. All other RealONE Players with a preference for any variation of Spanish choose the last clip. For instance, a RealONE Player with a preference for Chilean Spanish chooses the es option because its preferred variation (es-cl) is not listed.

Providing Subtitles or Overdubbing

For clips in foreign languages, RealONE Player viewers can set a preference for subtitles or overdubbing. The systemOverdubOrSubtitle attribute tests for this preference, displaying clips based on the viewer's choice. It can have one of two values, either overdub or subtitle. Suppose that you have three versions of a RealVideo clip:

  1. an original French version (original.rm)
  2. a version dubbed in English (dubbed.rm)
  3. the original French version with English subtitles (titled.rm)

You can use systemOverdubOrSubtitle along with systemLanguage in a <switch> group as shown in the following example:

<switch>
<!-- Version for RealONE Players with a preference for English and overdubbing. -->
<video src="dubbed.rm" systemLanguage="en" systemOverdubOrSubtitle="overdub"/>
<!-- Version for RealONE Players with a preference for English and subtitling. -->
<video src="titled.rm" systemLanguage="en" systemOverdubOrSubtitle="subtitle"/>
<!-- Version for RealONE Players with a language preference other than English. -->
<video src="original.rm"/>
</switch>

In the preceding example, RealONE Players with a preference for English and overdubbing play the first clip. Any other RealONE Player preferring English plays the second clip. The original French clip is listed last with no systemLanguage attribute. This makes it the default played by RealONE Players that prefer French or another language besides English.

Note: In the preceding example, the second clip does not need to specify subtitle explicitly. The systemOverdubOrSubtitle attribute uses only overdub or subtitle as its value. Because the first clip takes the overdub value, only the subtitle value is left for the second clip.

Switching Between Bandwidth Choices

To stream different clips to viewers at different connection speeds, use the systemBitrate test attribute to define options each RealONE Player can choose based on the total amount of bandwidth it has available. The systemBitrate attribute takes as a value the approximate bits per second required to stream the whole presentation. The following sample <switch> tag lists two different RealPix presentations. The first is for connections that have at least 80 Kbps of bandwidth. The second is for slower connections, down to 28.8 Kbps modems:

<switch>
<ref src="slides1.rp" systemBitrate="80000"/>
<ref src="slides2.rp" systemBitrate="20000"/>
</switch>

As shown above, list the bandwidth choices from fastest to slowest. RealONE Player evaluates options in order, selecting the first option it can play. If the 20,000 bps option were first, a RealONE Player with a high-speed connection would choose it because it is the first viable option. Also ensure that the last option satisfies the slowest connection speed you want to support. If the last choice is systemBitrate="60000", for example, RealONE Players on modems will not play the presentation because its bandwidth requirement is too high.

The more complex example below shows three sets of clips. Each <par> tag has a systemBitrate attribute that lists the approximate bandwidth the clips as a whole consume. Note that each group uses the same RealText clip, but has different RealAudio and RealPix clips created for its bandwidth:

<switch>
<par systemBitrate="225000">
<!--RealONE Players with 225 Kbps or faster connections choose this group-->
<audio src="music1.rm"/>
<ref src="slides1.rp" region="images"/>
<textstream src="narration.rt" region="text"/>
</par>
<par systemBitrate="80000">
<!--RealONE Players with connections between 80 and 225 Kbps get this group-->
<audio src="music2.rm"/>
<ref src="slides2.rp" region="images"/>
<textstream src="narration.rt" region="text"/>
</par>
<par systemBitrate="20000">
<!--RealONE Players with connections between 20 and 80 Kbps get this group-->
<audio src="music3.rm"/>
<ref src="slides3.rp" region="images"/>
<textstream src="narration.rt" region="text"/>
</par>
</switch>

For More Information: The table "Maximum Streaming Rates" gives bandwidth guidelines for various network connections.

Switching with SureStream Clips

With RealAudio or RealVideo clips encoded for multiple bit rates with SureStream technology, you may or may not need to use the <switch> tag with a systemBitrate attribute. The following guidelines will help you to make this decision:

Enhancing Presentation Accessibility

RealONE Player users who are sight- or hearing-impaired can set an accessibility preference that gives them audio descriptions or captions, respectively, when those options are available. You can match RealONE Player viewers to these options with the systemAudioDesc and systemCaptions attributes. Both attributes, which you can use together or singly, take a value of either on or off. Suppose you have three versions of a video clip:

  1. An original version for viewers with no accessibility preference (video.rm).
  2. A version for sight-impaired viewers with a preference for audio descriptions (video_descriptions.rm).
  3. A video with audio descriptions might consist of a standard video that pauses intermittently while a separate audio track encoded in the clip describes upcoming scenes.

  4. A version for hearing-impaired viewers with a preference for captions (video_captions.rm).
  5. A video with captions might consist of a standard video that includes encoded captions similar to subtitles, but in the same language as the video's audio track.

You can use inline switching with the systemAudioDesc and systemCaptions attributes as shown in the following example to choose between clips based on the viewer's accessibility preference:

<seq>
<video src="video_descriptions.rm" systemAudioDesc="on"/>
<video src="video_captions.rm" systemCaptions="on"/>
<video src="video.rm"/>
</seq>

For More Information: See "Displaying System Captions Using RealText" for an example of using RealText to provide system captions.

Switching Based on the Viewer's Computer

Several <switch> tag attributes—systemCPU, systemOperatingSystem, systemScreenSize, and systemScreenDepth—let you switch between clips or groups based on the viewer's computer hardware or software. This lets you tailor a presentation's size or clip types, for example, based on the features of the machine running RealONE Player.

Switching for CPU Type

The systemCPU attribute lets you switch clips based on the processor for the RealONE Player computer. This attribute identifies the computer processor but no other machine attributes, such as the computer's clock speed, available memory, or operating system. The following table lists the possible values for the systemCPU attribute.

systemCPU Attribute Values
Attribute Value Computer Processor Selected
alpha Compaq Alpha processor
arm Unix-based server processor
arm32 Unix-based server processor
hppa1.1 Hewlett-Packard Unix-based server processor
m68k pre-PowerPC Macintosh
mips Unix-based server processor
ppc PowerPC Macintosh and Linux
rs6000 IBM Unix-based server processor
unknown unknown processor type
vax DEC VAX running VMS or Unix
x86 Intel chip set for Windows and Linux PCs and servers

Note: The preceding table lists all systemCPU attribute values defined for SMIL. This does not mean, however, that RealONE Player is available for each hardware platform.

Switching for Operating System

The systemOperatingSystem attribute lets you switch clips based on the operating system running on the RealONE Player computer. This attribute does not discriminate between various versions of an operating system, however. The following table lists the values for systemOperatingSystem. The last column indicates if a version of RealONE Player is available for that operating system. Note, however, that RealONE Player availability is subject to change.

systemOperatingSystem Attribute Values
Attribute Value Operating System Selected RealONE Player?
aix IBM AIX version of Unix yes
beos Be operating system no
bsdi Berkeley Software Design's version of Unix no
dgux Data General UX version of Unix no
freebsd FreeBSD version of Unix no
hpux HP-UX version of Unix yes
irix Silicon Graphics Irix version of Unix yes
linux Any Linux distribution yes
macos Any Macintosh operating system, including MacOSX yes
ncr NCR network operating system no
nec NEC version of Unix no
netbsd Network BSD version of Unix no
nextstep NeXT operating system no
nto NTO version of Unix no
openbsd Open BSD version of Unix no
openvms Open VMS no
os2 IBM OS/2 no
osf Open Software Foundation's version of Unix no
palmos Palm operating system no
qnx QNX Software System's realtime platform no
rhapsody Macintosh OSX Server no
sco Caldera version of Unix (fomerly Santa Cruz Operations) no
sinix Siemens Nixdorf version of Unix no
solaris Sun Solaris version of Unix yes
sunos Sun version of Unix pre-dating Solaris no
unixware Caldera version of Unix (formerly Novell) yes
unknown unknown operating system n/a
win16 Microsoft Windows 16-bit OSes yes
win32 Microsoft Windows 32-bit OSes yes
win9x Microsoft Windows 95/98/ME yes
wince Microsoft Windows CE and PocketPC yes
winnt Microsoft Windows NT/2000/XP yes

Switching for Monitor Size or Color Depth

Two test attributes, systemScreenSize and systemScreenDepth, let you switch clips based on the size and color capability of the monitor displaying RealONE Player. They are useful if you have different versions of the same video in different sizes or different color depths, for example.

Specifying a Monitor Size

The systemScreenSize attribute uses a pixel measurement value in the form heightXwidth. The value specifies that the monitor displaying RealONE Player must be of the given size or larger. The following are common systemScreenSize values:

1024X1280 common size for 21-inch monitors or larger
768X1024 common size for 17-inch monitors or larger
600X800 common size for 15-inch monitors or larger
480X640 smallest desktop monitor size in general use

Note: You must use a capital "X". Note, too, that monitor sizes are commonly referred to in a width-by-height format, such as 640-by-480. With SMIL, though, you must specify height first.

Because a monitor must be at least the specified size for RealONE Player to choose an option, always list options from the largest to the smallest screen size as shown above. If you listed systemScreenSize="480X640" first, for example, all RealONE Players on standard desktop computers would choose that option because all standard desktop monitors are at least that size.

Tip: Keep in mind that computer users can generally set their monitor resolutions differently. Some 17-inch monitors may have a resolution of 768X1024 for example, while others are set to 600X800.

Specifying a Color Depth

The systemScreenDepth attribute uses an integer value that specifies the color bit depth of the monitor. The monitor must have the given bit depth or higher to play the clip. The following are common systemScreenDepth values:

32 millions of colors
24 millions of colors
16 thousands of colors
8 256 colors
4 16 colors
1 black-and-white

Because a monitor must have at least the specified color depth for RealONE Player to choose an option, always list options from the highest bit depth to the lowest as shown above. If you listed systemScreenDepth="8" first, for example, all RealONE Players on standard color monitors would choose that option because all standard color monitors can display at least 256 colors.

Switch Group Examples

The following examples illustrate different ways to use switching. Note that there are many applications for switching, and many ways to write SMIL presentations that include switching. Choose Sample Files from the pull-down menu to view all the playable sample files included in this chapter.

Switching with Multiple Attributes

Using multiple test attributes in a <switch> group, you can have RealONE Player choose clips based on combined criteria, such as both available bandwidth and language preference. There are two ways to do this:

Example 1: Multiple Test Attributes

In the following example, the first two RealAudio clips have two test attributes each—one for language and one for bandwidth. Both attributes must be viable for RealONE Player to choose the clip. Because RealONE Player evaluates the <switch> choices from top to bottom, selecting the first viable option, the last two choices do not have language attributes. This lets all RealONE Players other than those with French selected as their language preference choose between the two English-language clips, based on their available bandwidth:

<switch>
<!-- French language choices -->
<audio src="french2.rm" systemLanguage="fr" systemBitrate="47000"/>
<audio src="french1.rm" systemLanguage="fr" systemBitrate="20000"/>
<!-- English language choices (default) -->
<audio src="english2.rm" systemBitrate="47000"/>
<audio src="english1.rm" systemBitrate="20000"/>
</switch>

Example 2: Nested <switch> Groups

The next example adds RealText clips in both French and English to the presentation possibilities. Here, <switch> groups are nested so that RealONE Players with French set as their language preference play the French RealText clip and choose from the set of French-language RealAudio clips, based on available bandwidth. All other RealONE Players play the English RealText clip and choose from the set of English-language RealAudio clips:

<switch>
<!-- Choose French as the language. -->
<par systemLanguage="fr">
<textstream src="frenchcredit.rt" region="credits_region" fill="remove"/>
<switch>
<!-- Choose fast or slow bit rate for French audio -->
<audio src="french2.rm" systemBitrate="47000"/>
<audio src="french1.rm" systemBitrate="20000"/>
</switch>
</par>
<!-- Choose English as the language. This is the default. -->
<par>
<textstream src="enlgishcredits.rt" region="credits_region" fill="remove"/>
<switch>
<!-- Choose fast or slow bit rate for English audio -->
<audio src="english2.rm" systemBitrate="47000"/>
<audio src="english1.rm" systemBitrate="20000"/>
</switch>
</par>
</switch>

Switching for Different Video Sizes

As described in "Different Clip Dimensions for Different Bandwidths", you can encode different sizes of the same video, streaming a small clip over slow modems and a larger clip (or clips) over faster connections. Reducing the video size for slower connections ensures that the video's frame rate and visual quality remain high. For example, you could create the three clips listed in the following table.

RealVideo Clips at Different Sizes
Clip Name Dimensions SureStream Audiences systemBitrate value
videosmall.rm 176 x 132 28.8 and 56 Kbps Modems 20000
videomedium.rm 240 x 180 ISDN and corporate LANs 45000
videobig.rm 320 x 240 256, 384, and 512 Kbps DSL and cable modems 225000

In the following example, each <switch> tag test attribute uses the target bit rate of its clip's slowest SureStream stream. The <switch> tag then presents the three RealVideo choices to RealONE Player from fastest to slowest:

<switch>
<video src="videobig.rm" systemBitrate="225000" region="video_region" .../>
<video src="videomedium.rm" systemBitrate="45000" region="video_region" .../>
<video src="videosmall.rm" systemBitrate="20000" region="video_region" .../>
</switch>

For More Information: Target bit rates are listed in the table "Maximum Streaming Rates".

Displaying System Captions Using RealText

As the section "Enhancing Presentation Accessibility" explains, you can use the systemCaptions attribute to display captions for hearing-impaired viewers. The following examples demonstrate various ways to display RealText captions coordinated with an audio track.

Note: You can use any means to provide captions. The systemCaptions="on" attribute simply tells RealONE Player to play a certain clip if the viewer has set the captions preference. There are no requirements for what type of clip to use for captions, though.

For More Information: Chapter 6 explains how to write and time a RealText clip. See Chapter 11 for information about layouts.

Example 1: Using a Transparent RealText Overlay

Although it may not be suitable in all cases, the simplest way to provide captioning is to overlay a clip with a RealText clip that has a transparent background. To do this, you define two regions, one for the video, and one for the captions, using the z-index attribute to ensure that the captions appear in front, as shown in the following example:

<layout>
<root-layout width="320" height="240" backgroundColor="black"/>
<region id="video_region1" z-index="1"/>
<region id="text_region" height="40" bottom="0" left="10" z-index="2"/>
</layout>

You then play the RealText clip in parallel with the main clip, using systemCaptions="on" to display the RealText clip only in RealONE Players that have a preference for system captions. Because system captions are either on or off, you can easily use inline switching (no <switch> tag), as shown here:

<par>
<video src="video.rm" region="video_region1" fill="remove"/>
<textstream src="transparentcaptions.rt" region="text_region"
systemCaptions="on" fill="remove"/>
</par>

View it now! (requirements for viewing this sample)
This sample overlays a video with captions when the systems captions preference is turned on. If the preference is turned off, just the video displays.

Example 2: Creating a Captions Region

If you do not want to overlay the video as described in the preceding example, you can create a separate region for the captions through your SMIL file layout. The following layout is similar to that used in the preceding example, except that the captions region appears below the video region rather than on top of it:

<layout>
<root-layout width="320" height="300" backgroundColor="black"/>
<region id="video_region" height="240"/>
<region id="text_region" height="40" top="260" left="10"/>
</layout>

If you play a video in parallel with a captions clip as shown in the preceding example, the captions region would appear blank for viewers who have the captions preference turned off. Alternatively, you can create a "filler clip" that displays in the captions region when captions are off. This clip might simply thank the viewer for watching the presentation. The following example demonstrates how to do this:

<par>
<video src="../clips/video3.rm" region="video_region" fill="remove"/>
<switch>
<textstream src="videocaptions.rt" region="text_region" systemCaptions="on"/>
<textstream src="fillercaptions.rt" region="text_region" systemCaptions="off"/>
</switch>
</par>

View it now! (requirements for viewing this sample)
This sample creates a separate captions area that displays filler text if the captions preference is turned off.

Example 3: Resizing the Media Window for Captions

This example demonstrates how to use systemCaptions in <layout> tags to change layouts depending on whether or not captions are displayed. The following layout creates a captions region only when captions are turned on. Note that in each layout, the video region has a unique ID, which is required by SMIL. But both video regions have the same name:

<switch>
<layout systemCaptions="on">
<root-layout width="320" height="300" backgroundColor="black"/>
<region id="video_region1" regionName="video" height="240"/>
<region id="text_region" height="40" top="260" left="10"/>
</layout>
<layout systemCaptions="off">
<root-layout width="320" height="240" backgroundColor="black"/>
<region id="video_region2" regionName="video"/>
</layout>
</switch>

Tip: Although the preceding example uses systemCaptions in the <layout> tag, you could use the attribute in <root-layout/> and <region/> tags instead to display or hide individual regions based on RealONE Player's captions setting.

In the SMIL body, you then assign clips to the regions. Note that the following markup assigns the single video clip to a region through the region name instead of the region ID. If you didn't use the region name, you'd need to create two <video/> tags, one assigned to video_region1, the other assigned to video_region2. Each tag would require a systemCaptions attribute to turn the tag on or off depending on the captions preference. With the following method, only the RealText clip uses the systemCaptions attribute:

<par>
<video src="video.rm" region="video" .../>
<textstream src="captions.rt" region="text_region" systemCaptions="on" .../>
</par>

For More Information: See "Setting Region IDs and Names" for more on region names.

View it now! (requirements for viewing this sample)
This sample resizes the main media window and displays captions if the captions preference is turned on.


RealNetworks, Inc. ©2001 RealNetworks, Inc. All rights reserved.
For more information, visit RealNetworks
Click here if the Table of Contents frame is not visible at the left side of your screen.
previous next