By Sarahjane White
In the history of Stupid Web Tricks, the staffers here at Builder.com can't believe we've never offered you a sound-related tip to annoy your friends, coworkers, and other site visitors.
What is more aggravating than having your ears blasted by the Muzak version of "Ice, Ice Baby" that plays automatically every time your site is accessed? Nothing that we can think of, except maybe the song being, "I'm Too Sexy." This is senior producer Paul Anderson's tribute to a previously overlooked stupid Web trick.
There are many ways to add sound to your site, but the most unnecessary way is to have it start playing when a page starts to load. This is one trick that hasn't changed much over the past couple years. Despite carefully thought-out advances such as Beatnik, SMIL, and the aural style sheets, the best way to make a Web page announce itself with sound is still to add an EMBED element, which works on nearly all browsers.
Put this code in the beginning, middle, or end of your page's BODY region, depending on how much you want the reader to see before the browser starts loading the audio file:
<EMBED src="applause.wav" type="audio/wav" hidden=true autostart=true loop=false width=1 height=1>
The autostart, width, and height attributes are there for Internet Explorer 3.0, to keep it from displaying the Windows Media Player and waiting for someone to press the Play button. The loop=false is your insurance against the sound repeating, although usually it won't even if you indicate loop=true. The type attribute gives the MIME-type of the audio file, which helps the browser figure out how to play it. Most browsers can play embedded WAV, MIDI, AU, and AIFF files with the MIME types audio/wav, audio/midi, audio/basic, and audio/aiff.
Hey, What About MP3?
You see plenty of links to MP3 files these days. But for all the format's advantages, you seldom find MP3s playing within Web pages. One reason is that there is still no accepted standard MIME type for audio MP3 files, making it difficult for Web servers and browsers to identify them. The other is the lack of a common MP3 plug-in: QuickTime supports MP3, but its Windows plug-in doesn't register for it. If you don't mind incomplete reception, use an MP3 EMBED with type="audio/mpeg" and make sure your Web server supports that MIME type. It will work for Macintosh users with the QuickTime plug-in and for Windows users with Internet Explorer and an up-to-date Windows Media Player.
Sarahjane White is an editorial research assistant for CNET Web Building. She is also the creator of della, a tricky Web site that is just a little stupid.