WORKING WITH SOUND

Adding sound or background music to your Web site is easier than you think. It's just the ongoing war between Netscape and Microsoft that makes things a bit tricky.

For example, Microsoft's Internet Explorer (version 2.0 and later) supports the <BGSOUND> (Background Sound) tag but Netscape does not. So, if you don't care who arrives at your site using the Netscape browser (or any other browser, for that matter), just use the <BGSOUND> tag. However, if you are more interested in accommodating everyone who views your page, then use the <EMBED> tag, supported by most browsers, including Netscape 2.0 (and later versions) and Internet Explorer 3.0 (and later versions).

<BGSOUND> TAG:

Two attributes make up the <BGSOUND> tag: SRC (source) and LOOP. The SRC attribute calls up the sound file and LOOP specifies how many times the audio clip will play. For instance, to play a sound file called hal.wav on a Web site viewed with Internet Explorer, just upload the sound file to your server as raw data and include the following code in your HTML document:

<BGSOUND SRC="hal.wav" LOOP=6>

In this instance, the sound file hal.wav will play 6 times in a row. You can make the sound file play as many times as you want by changing the value of the LOOP. If you want the sound file to repeat for as long as the viewer stays on your page (and keep in mind that this can be annoying), use LOOP=INFINITE. Your HTML will read as follows:

<BGSOUND SRC="hal.wav" LOOP=INFINITE>

Using the BGSOUND tag, sound files can be uploaded and played in WAV, AU, or MIDI format. As with images, remember to keep sound file size to a minimum. A 60k sound file will take about one minute to download via a 14.4 modem, and only after it has loaded, will it begin to play. Keep in mind, however, that Netscape users will not hear the sound at all and may receive an error message.

<EMBED> TAG:

The EMBED command works on both Netscape Navigator 2.0 (and later versions) and Microsoft Internet Explorer 3.0 and 4.0. Although the tag works a lot like Explorer's BGSOUND, it includes several different attributes.

To embed a sound file (let's use hal.wav again as an example) and have it play in the background, upload the sound file to your server as raw data and include the following tag in your HTML document:

<EMBED SRC="hal.wav" HIDDEN=TRUE
AUTOSTART=TRUE LOOP=TRUE>

  • EMBED SRC tells the browser where to find the sound file.
  • HIDDEN=TRUE tells the browser to load the sound file but not to display a sound control panel. If you use the attribute HIDDEN=FALSE, a sound player control panel with play, stop, pause, and volume control buttons will be displayed. Keep in mind, however, that if you choose to display this sound control panel, you must also specify a WIDTH and HEIGHT attribute for the CONSOLE (WIDTH=144 HEIGHT=74 is suggested). Your tag would then look like the following:

    <EMBED SRC="hal.wav" HIDDEN=FALSE
    AUTOSTART=FALSE LOOP=FALSE WIDTH=144
    HEIGHT=74 CONTROLS=CONSOLE>

    Just click on the arrow button in the middle of the console below to hear hal.wav:

  • AUTOSTART=TRUE specifies that the sound file will automatically start to play as soon as the file is loaded. If you change the attribute to AUTOSTART=FALSE, the audio will not start to play until the user instructs it to do so.
  • LOOP=TRUE specifies that the sound file will play an infinite number of times. With LOOP=FALSE, the sound file will play only once. LOOP=4 (or any number you choose) will cause the sound file to play 4 times.

Sound files can be uploaded and played in WAV, AIFF, AU, and MIDI format. In addition, you can use the EMBED tag to play QuickTime movies, AVI (under Windows 95 and NT) and VRML files.