HOW TO PLAY A SOUND FILE
AUTOMATICALLY ON YOUR WEB PAGE
by Joelle Steele
In most cases, the last thing you should be doing is playing a sound on your Web site, especially if it is a long sound such as music, an annoying voice, a loud sound, or one that plays in a loop. These things are just plain irritating to the average visitor. A little bit goes a very long way when it comes to sound effects on a Web site. In addition, sound files are rather large, and because they load first, they can delay your entire page from loading quickly. So, if you do decide to use a sound effect, make sure it is a sound of very short duration so that you will be loading the smallest file possible.
I used to use a very short little train whistle sound on two pages of my old computer website, the home page and the classes page. I shopped around for this sound effect and listened to countless train whistles before I selected this one. Others were too high-pitched and some were way too long. Once I found the one I wanted, I embedded it and I turned the volume down a little to make sure it wouldn't be overly loud in case someone was browsing my site in the workplace. I let it play just once and didn't set it to play in a loop (repeating itself).
The embed tag supports your common sound file formats such as .wav, .mid, .mp3, and .au. The code goes at the top within the <body> tags:
<embed src="http://www.yourwebsite.com/yoursound.wav" loop="false" autoplay="true" hidden="true" volume="50"></embed>
The above code stops the sound from playing in a loop (loop="false"), makes the sound play automatically when the page loads (autoplay="true"), omits the volume control box image from appearing on the page (hidden="true"), and sets the volume to normal (volume-"50").
Volume can be set anywhere from 1 to 100, but 50 is considered normal. When I set the volume on my train whistle, I tried various volume settings and decided it was good at 40. It sounded pretty subtle at that level on both of my computers. You will need to experiment with your volume control too, because no two sound files are alike. Mine was not that loud to begin with, but some can be quite loud and abrasive and need to be toned down to 20 or 25 or so to avoid driving your visitors away.
This article last updated: 07/29/2012.