About Content Selection: System Test Attributes and t:SWITCH | DHTML文档教程 |
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.
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 extensible markup language (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.
<HTML> <HEAD> <STYLE> .time {behavior: url(#default#time2);} </STYLE> </HEAD> <BODY> <DIV CLASS="time"... </BODY> </HTML>
For more information about referencing the time2 behavior, see authoring html+time.
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.
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.
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:PAR> <t:VIDEO SRC="omelette.mpg"> <t:SWITCH> <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" /> </t:SWITCH> </t:PAR>
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:PAR> <t:VIDEO src="rhinoceros.mpg"/> <t:SWITCH> <t:AUDIO SRC="rhino-english.aiff" SYSTEMLANGUAGE="en" SYSTEMOVERDUBORSUBTITLE="overdub"/> <t:AUDIO SRC="rhino-dutch.aiff" SYSTEMLANGUAGE="nl" SYSTEMOVERDUBORSUBTITLE="overdub"/> <t:AUDIO SRC="rhino-french-lecture.aiff" /> </t:SWITCH> <t:SWITCH> <t:SEQ SYSTEMLANGUAGE="en" SYSTEMOVERDUBORSUBTITLE="subtitle" DUR="15"> <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> </t:SEQ> <t:SEQ SYSTEMLANGUAGE="nl" SYSTEMOVERDUBORSUBTITLE="subtitle" DUR="15"> <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> <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> </t:SEQ> </t:SWITCH> </t:PAR>
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.
In some circumstances梬hen you want to support multiple attribute criteria, for instance梪sing 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:PAR> <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> </t:PAR>
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:PAR> <t:VIDEO SRC="omelette.mpg"> <t:SWITCH> <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" /> </t:SWITCH> </t:PAR>