Playing a Sound File Automatically on Your Web Page

Playing a Sound File Automatically on Your Web Page

Playing 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 website, 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 website. 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 one of my old websites. 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 tags:

< embed src=”http://www.yourwebsite.com/yoursound.wav” loop=”false” autoplay=”true” hidden=”true” volume=”50″>

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.

Leave a Reply

You must be logged in to post a comment.