Practical and Useful Information For Enhancing Your Site

Playing Music On A Site

There may be times when you want visitors to be able to be able to play music on a site. Perhaps you have developed a site for a musical performer or group, and you want visitors to be able to hear selections from the latest album.

The typical method of playing a sound file is to use an <embed> tag wrapped in an <object> tag, using code similar to the following:

<object width="300" height="42">
<param name="src" value="filename.mp3">
<param name="autoplay" value="true">
<param name="controller" value="true">
<param name="bgcolor" value="#FF9900">
<embed src="filename.mp3" autostart="true" loop="false" width="300" height="42" controller="true" bgcolor="#FF9900"></embed>
</object>

Unfortunately, the code is not valid HTML/XHTML. Apparently, the <embed> tag is a Netscape proprietary tag that was never included in the HTML/XHTML specification. A gentleman by the name of David Battino has developed a JavaScript file that can be linked to a page and the page should validate. David is the Audio and Digital Music Editor for O’Reilly’s Digital Media site, the co-author of The Art of Digital Music, and on the Steering Committee for the Interactive Audio Special Interest Group (IASIG). To see David's link system in action, click on the following link:

Play Bach Toccata Sample

You can read about David's link system and download the JavaScript file here. If you're a Dreamweaver user, please note that David offers a free extension.

While we think that David's link system is an improvement over having the code in the page, we prefer using a Flash player on a Web page, and a commercial Flash player that works well and is relatively inexpensive is SWiSH Jukebox. Below is a sample player created with SWiSH Jukebox. Click on the play button to hear it action: