The <BGSOUND> tag is a very simple way to add sound to a Web page. Unfortunately, it is supported only by Internet Explorer. Code listing 18-1 demonstrates the use of the <BGSOUND> tag.
Code Listing 18-1.
<HTML> <HEAD> <TITLE>Listing 18-1</TITLE> <BGSOUND SRC="music.wav" LOOP="infinite"> </HEAD> <BODY> This page demonstrates the use of the BGSOUND tag </BODY> </HTML> |
The <BGSOUND> tag must be located in the HEAD of the document. Like an IMG element, BGSOUND requires the SRC attribute to specify the location of the media file. BGSOUND supports a number of different media types. The exact types supported vary by operating system and individual machine. Commonly supported types include WAV, MIDI, and (somewhat less commonly) MP3.
The BGSOUND element supports a number of different attributes. The LOOP attribute specifies the number of times the sound file should be repeated. It accepts standard numerical values. A value of infinite or -1 will cause the sound to repeat forever. The BALANCE attribute accepts values between -10000 and 10000, where negative values direct sound to the left speaker, positive values send sound to the right, and a value of 0 will center the audio. The VOLUME attribute will accept values between -10000 and 0, where (nonintuitively) 0 is the loudest.
NOTE
<BGSOUND> will not work on systems that have the Play sounds option unchecked. This option is found in Internet Options/Advanced/Multimedia in the Tools menu in Internet Explorer 5 and in the View menu in Internet Explorer 4.