★ wanayoo — archive 1999 http://webdeveloper.com/drweb/97Jan06-drwebsite.htmlNouvelle recherche | Portail wanayoo
Get Ranked Higher on Search Engines

Adding Background Sound to Sites

Dear Dr. Website: I've visited some Web sites where music seems to play in the background for as long as I'm on that page. Is there an easy way I can add background music to my Web site like that?

A. There are a couple of different ways you could add background sound to a Web page. One of the simplest methods is to use the <BGSOUND> tag, which is supported by some leading browsers like the latest versions of Microsoft Internet Explorer, Netscape Navigator, and NCSA Mosaic. Here's an example of the tag's syntax:

<BGSOUND SRC="/old?u=http%3A%2F%2Fwebdeveloper.com%2Fdrweb%2Fsounds%2Fbarney.au&y=1999" LOOP=INFINITE>

Within the <BGSOUND> tag, the SRC attribute points to the path and filename of the desired audio file, just like the IMG tag uses SRC to specify a graphics file to be displayed. <BGSOUND> also utilizes a LOOP extension to specify how many times a sound should play. You can set LOOP to a specific number (for example, LOOP=3), or you could set LOOP to INFINITE to cause the sound to repeat endlessly.

Another straightforward method is to use the <EMBED> tag. With Netscape Navigator's built-in LiveAudio player for playing audio files in WAV, AIFF, AU, and MIDI formats, you can add a console with audio controls to a Web page. The controls include play, pause, and stop buttons and a volume control lever. The <EMBED> tag points to your sound file and displays audio controls according to dimensions you specify with WIDTH and HEIGHT parameters. Here's an example of the syntax for enabling this:

<EMBED SRC="/old?u=http%3A%2F%2Fwebdeveloper.com%2Fdrweb%2Fmoodmusic.wav&y=1999" width=140 autostart=true>

You can also hide the console so that the sound truly plays in the background; to do so, add the attribute HIDDEN=TRUE to the <EMBED> tag.

The AUTOSTART=TRUE setting causes the clip to play when the page is first loaded. You can use a LOOP=TRUE setting to allow the sound to play continuously until the stop button is clicked; if you want to give users the option to press the stop button, you should omit the HIDDEN attribute so the console will display. You could also set LOOP to a specific number; the sound will repeat that many times. Set LOOP to FALSE to cause the sound to play only once.

Another possibility for including background sound on a Web page is to use JavaScript in the <BODY> tag to cause sound to play as a Web document initially loads. You could also embed sound in a Web page via a Java applet, but you should note that only the AU and SND formats are currently supported; these audio files also need to be 8-bit mono sampled at no more than 8 kHz.

Specifying Font Faces

Dear Dr. Website: I had thought that if you wanted to use different fonts in a Web page--to set apart headlines or sidebars, for example--you had to resort to creating images for your display type. Now I'm seeing a number of sites with pages of ordinary text that display in a variety of typefaces. How does this work?

A. Navigator and Internet Explorer support an attribute in the <FONT> tag called FACE. You specify one or more fonts within the FACE attribute; the user's browser will go through the list of font names in FACE until it reaches one that is supported by the user's system, which it then uses to display the text enclosed by the <FONT> tag. If no font names match, the browser uses its default typeface; users won't even realize they're missing out on the typeface that the page's author intended. You can also specify font names when creating style sheets like those implemented by Internet Explorer.

You can specify up to 10 different fonts in the FACE attribute. To cover your bases, it's a good idea to include several font names in common use on several computer platforms, as in the following example:

<FONT FACE ="Arial, Helvetica, Geneva, Swiss, Sans Serif">

In addition, it's important to remember to check the spellings of the key font names you use--if you mean to specify "Arial" but key in "Ariel", for example, the client will fail to recognize the font you mean.


Reprinted from Web Week, Volume 3, Issue 1, January 6, 1997 © internet.com Corporation All rights reserved. Keywords: audio html Date: 19970106

http://www.internet.com