<HTML><HEAD></HEAD> <BODY> <EMBED SRC="sound1.wav" HIDDEN=TRUE> <A HREF="javascript:document.embeds[0].play(false)">Play the sound now!</A> </BODY> </HTML>The above method of playing a sound file is probably the simplest, but can pose many problems. If you are using the
embeds[]
parameter of the document
tag, Netscape Navigator 2.0 will generate an error because the embeds[]
parameter is a Navigator 3.0
feature. Rather than use the document.embeds[]
parameter, there
is a better way to identify the particular EMBED
you would like to use in JavaScript.
This involves using the NAME
and MASTERSOUND
attributes in your original EMBED
tag. For example:
<HTML><HEAD></HEAD> <BODY> <EMBED SRC="sound1.wav" HIDDEN=TRUE NAME="firstsound" MASTERSOUND> <A HREF="javascript:document.firstsound.play(false)">Play the sound now!</A> </BODY> </HTML>The above example is a much more descriptive way to describe your plug-in in JavaScript, and can go a long way toward eliminating confusion. If, for example, you had several sounds embedded in an HTML document, it may be easier for developers to use the
NAME
attribute rather than the
embeds[]
parameter. In the above example, notice that the MASTERSOUND
attribute in the EMBED
tag is used. This is because anytime a NAME
attribute is used referencing LiveAudio, an
accommodating MASTERSOUND
tag must be present as well. This is due to the EMBED
linking abilities
described in the first section of this documentation.Another common thing you might do with LiveConnect and LiveAudio is to defer loading a sound until a user clicks on the Play button. To do this, try the following:
<HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> <!-- Hide JavaScript from older browsers function playDefferedSound() { document.firstsound.play(false, 'http://url_to_new_sound_file/sound1.wav'); } // --> </SCRIPT> </HEAD> <BODY> <EMBED SRC="stub1.wav" HIDDEN=TRUE NAME="firstsound" MASTERSOUND> <A HREF="javascript:playDefferedSound()">Load and play the sound</A> </BODY> </HTML>The stub file loads relatively quickly. The Play function then loads the sound file, but only when it is called. That way users have to load the sound file only if they want to hear it.
Web designers might want to create whole new interfaces with LiveConnected LiveAudio. To create an alternate console for sound playing or interaction, a designer might do the following:
<HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> <!-- Hide JavaScript from older browsers function playsound() { document.firstsound.play(false); } function pausesound() { document.firstsound.pause(); } function stopsound() { document.firstsound.stop(); } function volup() { currentVolume = document.firstsound.GetVolume(); newVolume = ( currentVolume + 10 ) ; if ( document.firstsound.GetVolume() == 100 ) { alert("Volume is already at maximum"); } if ( newVolume < 90 ) { document.firstsound.setvol(newVolume) ; } else { if ( ( newVolume <= 100 ) && ( newVolume > 90 ) ) { document.firstsound.setvol(100) ; } } } function voldown() { currentVolume = document.firstsound.GetVolume(); newVolume = ( currentVolume - 10 ) ; if ( document.firstsound.GetVolume() == 0 ) { alert("Volume is already at minimum"); } if ( newVolume > 10 ) { document.firstsound.setvol(newVolume) ; } else { if ( ( newVolume >= 0 ) && ( newVolume < 10 ) ) { document.firstsound.setvol(0) ; } } } // --> </SCRIPT> </HEAD> <BODY> <EMBED SRC="sound1.wav" HIDDEN=TRUE AUTOSTART=FALSE NAME="firstsound" MASTERSOUND> <P><A HREF="javascript:playsound()">Play the sound now!</A></P> <P><A HREF="javascript:pausesound()">Pause the sound now!</A></P> <P><A HREF="javascript:stopsound()">Stop the sound now!</A></P> <P><A HREF="javascript:volup()">Increment the Volume!</A></P> <P><A HREF="javascript:voldown()">Decrement the Volume!</A></P> </BODY> </HTML>The above example illustrates how you might create your own method of controlling a sound file. The possibilities are really endless in this arena - you can use images, and onClick() events to truly simulate your own sound player!
Corporate Sales: 415/937-2555; Personal Sales: 415/937-3777; Federal Sales: 415/937-3678
Copyright © 1996 Netscape Communications
Corporation
If you have any questions, please visit Customer Service.