Export (0) Print
Expand All
6 out of 8 rated this helpful - Rate this topic

About Content Selection: System Test Attributes and t:SWITCH

This topic documents a feature of HTML+TIME 2.0, which is obsolete as of Windows Internet Explorer 9.

HTML+TIME 2.0 provides authors with the option to display different elements based on system settings. The t:SWITCH element specifies a set of alternative elements from which only the first acceptable element is chosen. Although the t:SWITCH element is most useful for setting conditions that determine what content to display based on the value of various system test attributes, it can also allow you to handle circumstances in which those system attributes affect timing, animation, or media presentation on your Web page.

Suppose that your page displays a video presentation that you want to accompany with an English, Spanish, or Portuguese audio file, depending on the language settings of the user's system. The t:SWITCH element can enable your page to detect the system language setting in the Regional Options section of the user's Control Panel and to play the appropriate audio file. Alternatively, your page can play a default file if, in this case, the user's system language is Japanese (or any other language for which you don't have an audio file). In much the same way, you can use t:SWITCH to display different elements based on system bitrate or the user's captioning, overdub, or subtitle preferences. Supported system test attributes include systemCaptions, systemBitrate, systemOverdubOrSubtitle, and systemLanguage.

You can also use system test attributes inline with other elements, rather than with the t:SWITCH element. This overview provides some examples of both methods and their relative advantages.

Adding the Time2 Behavior

Because Microsoft Internet Explorer 5.5 provides support for HTML+TIME (Timed Interactive Multimedia Extensions) through the time2 behavior, you must add a declaration for the behavior to your page. The time2 behavior is available as of Internet Explorer 5.5 in the Microsoft Win32 platform. For more information about element behaviors, see the About Element Behaviors overview.

The prefix t: associates the t:SWITCH element with an XML namespace. You must declare the XML namespace in the html tag of your document when using this element.

<HTML XMLNS:t ="urn:schemas-microsoft-com:time">

You must then import the tag definitions from the time2 behavior by using the IMPORT processing instruction.

<?IMPORT namespace="t" implementation="#default#time2">

If you want to use system test attributes with the media elements introduced with HTML+TIME (t:ANIMATION, t:AUDIO, t:MEDIA, t:IMG, and t:VIDEO), you don't need to associate the time2 behavior with them because the media elements are defined by the behavior itself. However, if you want to use system test attributes and the t:SWITCH element with other content elements, you must associate the behavior with those elements. You can do this inline on a given element:

<DIV STYLE="behavior:url(#default#time2)";}... 

If you plan to use HTML+TIME functionality on more than a couple of elements on the page, however, you might find it less cumbersome to associate elements with the time2 behavior by creating a Cascading Style Sheets (CSS) class attribute.

    .time {behavior: url(#default#time2);}
    <DIV CLASS="time"...

For more information about referencing the time2 behavior, see Authoring HTML+TIME.

System Test Attributes

The systemCaptions, systemBitrate, systemOverdubOrSubtitle, and systemLanguage attributes provide a means of testing system settings. For example, users can set the system language in the Regional Options control panel, available from the Start menu by choosing Control Panel from the Settings menu. Your Web page can test for this setting with the systemLanguage attribute. Similarly, the systemCaptions attribute tests whether the user has set sound captioning in the Accessibility Options control panel. The systemBitrate attribute retrieves the bandwidth available to the system; it is sampled once when the page loads or is refreshed. Note that if the user changes the system settings during a browser session, the new attribute values will not be reflected on your page until the page is refreshed.

Using System Test Attributes with the t:SWITCH Element

You can use the system test attributes provided in HTML+TIME 2.0 within a t:SWITCH element or inline with other elements. You might use the t:SWITCH element to:

  • Set an order of preference for your page markup to select among different elements or media. For example, if your page includes a media presentation, you might prefer that users with high-speed Internet connections see larger, higher-resolution video files. If users connect to the Internet with slower modems, however, you can ensure that they see smaller files and experience a faster, less frustrating download.

  • Set a "failsafe" element to appear when no other system attributes return true. For instance, you might use this option to show a simple image if users' connections are too slow to accommodate any available video presentation, or to play a default music file when users' systems are set to languages you can't support with an audio presentation.

Note  Within a t:SWITCH element, any element without a valid test attribute resolves true. It's important to remember this as you order elements within a t:SWITCH block.

The following example tests the systemBitrate attribute, within a t:SWITCH element, in order to select an appropriate audio object to accompany the video object.

<t:VIDEO SRC="omelette.mpg">
    <t:AUDIO SRC="chef_fast.aiff" SYSTEMBITRATE="56000"/>
    <t:AUDIO SRC="chef_med.aiff" SYSTEMBITRATE="28800"/>
    <t:AUDIO SRC="chef_slow.aiff" SYSTEMBITRATE="14400"/>
    <t:AUDIO SRC="sizzle.aiff" />

Because the t:AUDIO elements are arranged in descending order in the t:SWITCH element, the most desirable (fastest) bitrate is selected first. In this case, true means that the speed of the connection at page load was greater than or equal to one of the listed values for systemBitrate. If no element's systemBitrate returns a value of true, Sizzle.aiff is selected because it has no test attribute and is therefore always acceptable. Using t:SWITCH in this situation allows you to set a "fallback" option that always returns true, which might not be feasible using inline test attributes. Authors are encouraged to use a fallback option.

In the following example, a French-language video is accompanied by one or more media objects. The first t:SWITCH element provides an appropriate audio file for overdubbing if the system language has been set to English or Dutch; if neither, the default French audio object plays. The second t:SWITCH element selects a subtitle sequence in English or Dutch if systemOverdubOrSubtitle has been set to subtitle. The last sequence provides captions in French if captioning is set on the user's system.

<t:VIDEO src="rhinoceros.mpg"/>
    <t:AUDIO SRC="rhino-english.aiff" SYSTEMLANGUAGE="en" 
    <t:AUDIO SRC="rhino-dutch.aiff" SYSTEMLANGUAGE="nl" 
    <t:AUDIO SRC="rhino-french-lecture.aiff" />
        <SPAN class="time" BEGIN="1" DUR="4" >English subtitle 1</SPAN>
        <SPAN class="time" BEGIN="5" DUR="4" >English subtitle 2</SPAN>
        <SPAN class="time" BEGIN="9" DUR="4" >English subtitle 3</SPAN>
        <SPAN class="time" BEGIN="1" DUR="4" >Dutch subtitle 1</SPAN>
        <SPAN class="time" BEGIN="5" DUR="4" >Dutch subtitle 2</SPAN>
        <SPAN class="time" BEGIN="9" DUR="4" >Dutch subtitle 3</SPAN>
    <t:SEQ SYSTEMCAPTIONS="on" DUR="15">
        <SPAN class="time" BEGIN="1" DUR="4" >French subtitle 1</SPAN>
        <SPAN class="time" BEGIN="5" DUR="4" >French subtitle 2</SPAN>
        <SPAN class="time" BEGIN="9" DUR="4" >French subtitle 3</SPAN>    

Notice that in this example, unlike the previous example, no fallback media file accompanies the video. For the t:AUDIO elements contained by the two t:SWITCH elements to return true, the attribute values must match both the user overdub or subtitle preference and the system language setting. Also notice that if the user prefers captioning, the example provides French captions regardless of the user's system language setting.

Using Inline System Test Attributes

In some circumstances—when you want to support multiple attribute criteria, for instance—using many nested t:SWITCH containers might become unwieldy. Instead, you might choose to set inline system test attributes on the elements themselves.

In the following example, a video can play by itself or accompanied by one or more media objects with inline system test attributes. If the system language has been set to Dutch or English, the appropriate audio object plays. If the system language is Dutch or English and systemCaptions has been set to on, appropriate text blocks are displayed as well. Notice that if the system language is neither Dutch nor English, only the video object is displayed.

    <t:VIDEO SRC="somemovie.mpg" />
    <t:AUDIO SRC="dutch.aiff" SYSTEMLANGUAGE="nl" />
    <t:AUDIO SRC="english.aiff" SYSTEMLANGUAGE="en" />
    <DIV class="time" SYSTEMLANGUAGE="nl" SYSTEMCAPTION="on">
    Text block to accompany Dutch audio</DIV>
    <DIV class="time" SYSTEMLANGUAGE="en" SYSTEMCAPTION="on">
    Text block to accompany English audio</DIV>

Comments in the t:SWITCH Element

When used inside a t:SWITCH element, any element without a valid test attribute returns true. In Internet Explorer 6, comment tags are an exception to this rule, so it's possible to add comments to your markup in a t:SWITCH element without causing errors.

However, in Internet Explorer 5.5 and earlier versions, comment elements in a t:SWITCH element always return true, so they resolve the t:SWITCH element before any element that follows them. If you want to include comments within a t:SWITCH element, wrap the comments in another container, such as a div or t:PAR element. Assign an invalid test attribute to the container, so that it can't return true, as in the following example.

<t:VIDEO SRC="omelette.mpg">
    <t:AUDIO SRC="chef_fast.aiff" SYSTEMBITRATE="56000"/>
    <t:AUDIO SRC="chef_med.aiff" SYSTEMBITRATE="28800"/>
    <t:AUDIO SRC="chef_slow.aiff" SYSTEMBITRATE="14400"/>
    <DIV SYSTEMBITRATE="99999999999"> <!-- The following audio object plays if none of 
        the preceding bitrates are true. --> </DIV>
    <t:AUDIO SRC="sizzle.aiff" />

Related Topics

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.