One other form of inline multimedia is generally available to web
surfers—audio. Most browsers treat audio multimedia as separate
documents, downloaded and displayed by special helper applications,
applets, or plug-ins. Internet Explorer and Opera, on the other hand,
contain built-in sound decoders and support a special tag (<bgsound>
) that lets you integrate with your document an audio file
that plays in the background as a soundtrack for your page. [Applets and Objects, 12.1] [Embedded Content, 12.2]
We applaud the developers of Internet Explorer and Opera for providing a mechanism that more cleanly integrates audio into HTML and XHTML documents. The possibilities with audio are very enticing, but at the same time, we caution authors that special tags and attributes for audio don't work with other browsers, and whether this is the method that the majority of browsers will eventually support is not at all assured.
Use the <bgsound>
tag to play a soundtrack in
the background. This tag is for Internet Explorer and Opera documents
only. Other browsers ignore the tag. It downloads and plays an audio
file when the user first downloads and displays the host document. The
background sound file also will replay whenever the user refreshes the
browser display.
The src
attribute is
required for the <bgsound>
tag. Its value references the URL for the related sound file. For
example, when Internet Explorer or Opera users first download a
document containing the tag:
<bgsound src="audio/welcome.wav">
they will hear the welcome.wav audio file—perhaps an inviting message—play once through their computers' sound systems.
Currently, <bgsound>
can handle several different sound format files, including .wav, the native format for PCs;
.au, the native format for most
Unix workstations; and MIDI, a universal music-encoding scheme (see
also Table 5-1).
Table 5-1. Common multimedia formats and respective filename extensions
Format | Type | Extension | Platform of origin |
---|---|---|---|
Graphics Interchange Format | Image | gif | Any |
Joint Photographic Experts Group | Image | jpg, jpeg, jpe | Any |
X Bit Map | Image | xbm | Unix |
Tagged Image File Format | Image | tif, tiff | Any |
PICT | Image | pic, pict | Apple |
Rasterfile | Image | ras | Sun |
Portable Network Graphics | Image | png | Any |
Moving Pictures Expert Group | Movie | mpg, mpeg | Any |
Audio Video Interleave | Movie | avi | Microsoft |
QuickTime | Movie | qt, mov | Apple |
Windows Media Video | Movie | wmv | Microsoft |
Shockwave | Movie | dvr | Macromedia |
Real Video | Movie | ra, rm, ram | Real Networks |
DivX | Movie | div, divx, tix, mp4 | DivX |
AU | Audio | au, snd | Sun |
Waveform Audio | Audio | wav | Microsoft |
Audio Interchange File Format | Audio | aif, aiff | Apple |
Musical Instrument Digital Interface | Audio | midi, mid | Any |
PostScript | Document | ps, eps, ai | Any |
Acrobat | Document | Any |
As with inline movies, the loop
attribute for the browser's <bgsound>
tag lets you replay a
background soundtrack a certain number of times (or indefinitely),
at least until the user moves on to another page or quits the
browser.
The value of the loop
attribute is the integer number of times to replay the audio file,
or infinite
, which makes the
soundtrack repeat endlessly.
For example:
<bgsound src="audio/tadum.wav" loop=10>
repeats the ta-dum soundtrack 10 times, whereas:
<bgsound src="audio/noise.wav" loop=infinite>
continuously plays the noise soundtrack.
There are other ways to include audio in your documents,
using more general mechanisms that support other embedded media as
well. The most common alternative to the <bgsound>
tag is the <embed>
tag, originally implemented by
Netscape and supplanted by the <object>
tag in the HTML 4 and XHTML
standards. Take a look in Chapter
12 for details.
Ultimately, you should handle all background audio, including
spoken (aural) document content, using the various audio extensions
defined in a CSS standard. While we cover the speech synthesis-related
extensions in Chapter 8, they are
not yet supported by any browser. When such support becomes widely
available, all of these early audio extensions will go the way of the
<blink>
and <isindex>
tags, early specialized tags
deprecated in favor of more generalized and powerful features.