advertisement -- please support sponsors

sound, performance:
preloading sound files

Question:

How can I preload sound files?

Sounds can be attached to web pages using the <embed> tag. For example, the tag

<embed src="sound.wav">
tells the browser that it should load and play a sound file called "sound.wav." In addition to playing the sound, however, this tag will also display an audio player directly in the document. On both Netscape Navigator and Internet Explorer, embedded sounds are achieved through plug-ins that ship with the browsers as standard components.

Although Netscape's and Microsoft's audio plug-ins are quite different, they behave identically in a handful of circumstances. For example, both plug-ins begin loading the requested sound files as soon as the web page is loaded -- regardless of when the sounds are actually going to be played. Thus, including an <embed> tag to load a sound without playing it is a promising technique for preloading sounds.

An <embed> tag whose purpose is to preload a sound file, without actually playing it, is shown below:

<embed src="sound.wav" hidden=true autostart=false>

As you might expect, the "visible=false" property causes the plug-in to load but not appear. Similarly, the "autostart=false" property causes the sound to load but not play.

Obviously, an <embed> tag designed to preload sound files works most effectively when it is placed in the source for pages preceding the page where the sound should actually play. If the user spends enough time on the preceding page, then the sound file will be "waiting for him" when he advances to the next page.

Charlton Rose
July 28, 1997