Study Tips for 02/02/98

Adding Music and Sound to Your Web Pages



Introduction to Adding Music and Sound to Your Web Pages

Computers that can play sounds are nothing new; they've been around for years. The truly impressive thing is that sound files can now be played over the Internet. This fact is significant because the capability to play sound overcomes a few of the shortcomings that exist on the Net. The first big obstacle was the desire to support the lowest common denominator. This always meant supporting generic text terminals with no graphics or sound. The second obstacle was the lack of demand for such features. The Net was originally made up of mainly programmers and engineers working from workstations. Workstations have little or no sound support, and what exists is not consistent across different platforms.

Probably the most widely supported sound format is the WAV file format and gaining popularity (now almost passing) is the MIDI file. These robust formats allows you to encode stereo and mono sounds. You can also specify the degree with which to store the sounds. Most sound playing utilities support the WAV and MIDI formats without a problem.

Multimedia files require fairly computer-intensive programs to view properly. Most current Web browsers provide support for multimedia files by themselves, but not everyone. As a result, most of the time you must configure your web page to make the user comfortable in navigating your pages.

It's good idea is to not force multimedia files onto users or to warn them to expect it. Although you can have sound files play as soon as a user accesses a page, that may not a good idea. The file has to be downloaded from the Web server to the person's computer. After that, the user has to wait for the sound player to start up and play the sound file.

Although this process might be fast and unnoticeable for people with high-powered machines directly on the Net, most people don't have setups like that. Most people accessing the Net are doing it from modems, and they have to wait to get your files.

These problems do not even begin to address the issue of users who may be using a computer system that doesn't have a sound card or who use workstations (usually not equipped for sound).


The <BGSOUND> Tag

At this time the <BGSOUND> tag is Microsoft Internet Explorer specific.

If you'd like your page to play a sound as the page loads into your user's browser, you can add that capability with the <BGSOUND> tag. You'll generally want to put it near the top of the <BODY> section of your HTML document, but that's only for your benefit-it'll load as it's recognized by the browser.

The <BGSOUND> tag is an empty tag that accepts two attributes: SRC and LOOP. SRC is used to specify the sound file that you want played. LOOP determines how many times you want the sound played, and can have a number for a value or the word "infinite" for constant playing.

To play a .WAV, .AU, or MIDI (.MID) sound in the background automatically, place this HTML in your web page at the top:

<BGSOUND SRC="URL" LOOP="number -or- infinite">

An example of this might be:

<BGSOUND SRC="intro.au" LOOP="2">

In IE, the sound file can be a sound sample (.au or .wav files) or a MIDI (.mid or .midi) format sound file. Other browsers, if they support <BGSOUND>, may vary in their ability to play certain types of sounds.

Use LOOP="infinite" with care. A constantly repeated sound, especially a system sound, might confuse your user into thinking there's something wrong with his or her computer, or it may be just plain annoy your user.

Note: Currently only Internet Explorer supports this tag, to accomplish the same effect in both IE and Netscape 3.0 and above, use this HTML:

<EMBED SRC="ymca.mid" HIDDEN="True">


<EMBED>

You can use the <EMBED></EMBED> tag to place sound objects directly into an HTML page. This tag supports many common file formats... such as .wav, .mid, and .au.

For the file you embed to operate correctly, the user's browser must be equipped with either the appropriate plugin or ActiveX control for that file type. Most newer browsers come with basic plugins for MIDI, WAV, AU, AIFF, AVI, and Quicktime movies. In any case it's always good to provide an optional link to the embedded file so the visitor can download it and use it later if they don't have the right plugin.

Here's what a simple use of the <EMBED> tag looks like:

<EMBED SRC="ymca.mid" WIDTH=145 HEIGHT=61 BORDER=1>

The first example shows the window for the sound file. Also the WIDTH, HEIGHT, and BORDER thickness of the object is controlled.

Other attributes can be used as well with the <EMBED> tag:

<EMBED SRC="filename.ext" width=x height=x autostart=x hidden=x loop=x volume=x>

If you want the file to automatically play when the web page is loaded, set autostart=true, if you do not want the file to automatically start, simply leave out the autostart attribute or set autostart=false. If you want the control box to be hidden, use the hidden=true attribute. Normally the file will stop playing after it is completed the first time, so if you want it to start over once it is done use the attribute loop=true. You can set the volume setting with the volume attribute, a value from 1 to 100 (default is 50). The control box size is around 145 x 60 pixels.. so it is recommend to set width=145 height=60, but you may use the numbers of your choice (if it is less than these values, a portion of the control box will be cut off.)

Working example of the EMBED tag...

<embed src="ymca.mid" width=145 height=60 loop=true>



NOTE: Because this embed tag was not set to autostart, you will need to click the play button to play the sound file.

You may use multiple embed tags within one page, but it is recommended to never set more than one on autostart. It is also never recommended to use .wav or .au files in the embed tag, because they are very large and take a few minutes to download.


Tomorrow's Study Tips: FTP programs


This web page created by Kathleen M. Weber on February 4th, 1998.

Get a free 5MB homepage at XOOM