Creating a Web Page VIII: Sound
Created | Updated Sep 15, 2002
Please refer to previous entries in the "Creating a Web Page" series:
- I: Getting Started
- II: Learning HTML
- III: Text
- IV: Links
- V: Formatting Text and Lists
- VI: Tables
- VII: Colour
- VII.5: Images
Be advised...
It is possible to add sound to a web page. Many web development sources discourage it because when it works it’s often irritating to your visitors, and when it doesn’t work it’s even more irritating because it can cause error messages or problems when loading the page. There are ways to cut down on the irritation, as you’ll see below.
The three ways of adding sound to a page are the BGSOUND tag, the EMBED tag, and as a link.
BGSOUND
This one only works in Microsoft Internet Explorer 2.0 and above. The tag is located within the HEAD tag, along with TITLE and any META tags you choose to put in.
<HEAD>...other tags...
<BGSOUND SRC=” “ LOOP= “ “ VOLUME=” “ BALANCE= “ “>
</HEAD>
- SRC :
- LOOP :
- VOLUME :
- BALANCE :
"Source", the filename of the sound file and the path to it if it’s not in the same directory or folder as your HTML file. This tag supports .wav, .au, and .mid files.
...is the number of times you want the piece to be played. Setting it to -1 or INFINITE will make it play without stopping.
-10000 is mute and 0 is full volume.
This determines which speaker the sound comes out of more. It can be set to -10000 (all left), 0 (equal amounts out of each side), or 10000 (all right).
EMBED
This tag works with Netscape Navigator 2.0 and above, and IE 3.0 and above.
<EMBED SRC=" " HIDDEN=" " WIDTH=" " HEIGHT=" " AUTOSTART=" " LOOP=" " CONTROLS=CONSOLE>- SRC :
- HIDDEN :
- AUTOSTART :
- LOOP :
- CONTROLS=CONSOLE
This is where you tell it the filename and path to the file if the sound file is not in the same place as the HTML file.
... can be either "true" or "false". It determines whether or not you want to display a control panel that allows the visitor to play, stop, and control the volume of the music. If you’re going to use sound on your page, this attribute is highly recommended. If hidden=”false”, you’ll need to also specify the width and height of the control panel. Width of 144 and height of 74 is standard but you can set it however you wish.
... means whether or not the sound starts automatically when the page loads.
"True" mean it will play continously, "false" will make it play once then stop, or you can enter the number of times you want the sound to play before stopping (3, 4, 5, etc).
To be honest, I'm not fully sure why that has to be in there. Perhaps there are other kinds of controls besides the console setup with the little "play", "pause", and "stop" buttons.
This supports tag supports .wav, .aiff, .au, and .mid files.
Links
The less known way of including sound is to turn it into a link. A small download window will appear and your visitor can choose to listen to it from the site or download it to their computer and save it. This way is arguably the least intrusive method of the three for incorporating sound into your site, since visitors can decide for themselves whether or not to listen to it even once.
<A HREF=”soundfile”>Click here to listen</A>