You are in: School Web Sites » Enhancing Your Web Site » Using Sound on School Web Pages

Using Sound on School Web Pages

When it comes to inserting images on a web page, things are fairly simple. Use one of two file types (GIF or JPEG) and insert it in to your page. You may have problems with the image taking ages to download, but once you have inserted it into your page, any graphical browser (that's one which isn't purely text-based) will be able to see it.

Unfortunately, sound isn't quite that simple... the problem lies in the fact that sound is more complex and different browsers will attempt to play it using different ways. Let's look at a simple way and then see some of the problems that creates...

A 'simple' way - the <BGSOUND> tag

This way is probably suitable for some applications, such as a short sound to be played in the background of (for example) a Christmas page. First of all you will need the sound you would like to play in the background of your web site, in MIDI format (ending in .mid) or Microsoft WAV format (ending in .wav). If you would like to practice, here are two files which you can save to your own computer if you would like to:

Once you have either of these files saved in the same folder as the files which make up your school web site, then place one of the following lines of HTML in the <HEAD> section of your web page:

<BGSOUND SRC="12days.mid" LOOP=10>
<BGSOUND SRC="ahhhello.wav" LOOP=10>

These lines assume that the sound file is in the same folder as your HTML file. If the sound file was in a subfolder called sounds, the HTML might read:

<BGSOUND SRC="sounds/12days.mid" LOOP=10>

It is possible to set various parameters to control how the sound plays. Here are some of them:

LOOP="n"

Specifies how many times the sound will loop. a value of -1 means the sound will loop indefinitely

 
SRC="url"

Specifies the URL of the sound file. As shown above, sound files can be in any recognizable format (for example: "midi, wav, au")

 
VOLUME="n"

Determines the loudness of the background sound. Values may range from -10,000 (weakest) to 0 (loudest). This will have no effect on a Macintosh computer

 
BALANCE="n"

Determines the division of sound power between the left and right speakers. Valid values are between -10,000 and +10,000, with 0 being perfect balance between the two.

 

The drawback of <BGSOUND>

Unfortunately, this method only works in Internet Explorer and hence will not work in Netscape. So, if you want everyone to be able to hear your sound, the BGSOUND tag will not accomplish this. In reality, it is just as difficult to make a sound which is audible in Netscape audible in Internet Explorer too. Watch out for another page soon which explains how you might achieve this.