soundSingle
|
Constructor Summary | |
SoundSingle()
|
Method Summary | |
void |
load(String fileName)
Loads fileName , overwriting the previously held sound.
|
void |
on()
Enables sound playing. |
void |
off()
Disables sound playing until on is called. |
boolean |
isOn()
Reports if sounds can be played. |
void |
play()
Called to play the sound. |
void |
loop()
Called to begin looping the sound. |
void |
stop(int index)
Called to stop the sound. |
void |
init()
Called by the browser or applet viewer to load the sounds. The sound is specified by the <PARAM> . |
Constructor Detail |
public SoundSingle()
Method Detail |
public void load(String fileName)
fileName
, overwriting the previously held sound.
With this class you may also
load() a new sound. However only one sound is availiable
at a time. (Why not more? To preserve the end users memory, that's why! And because
it normally gets cached, no performance hurt anyway. I thought about this for a while.)fileName
- the relative URL of the sound file.public void on()
public void off()
public bolean isOn()
public void play()
public void loop()
If for some reason there is some problem and the sound cannot be played, nothing happens. The sound is not played if the sounds for this object is currently off().
public void stop()
public void init()
It looks for the parameter "sound0". The value of the parameter is treated as the URL of the sound file. This URL must be relative to the location of the document, otherwise known as the base URL. Realize that all sound files must be 8000Hz 8bit Mono µLaw encoded .au files. There are many software packages to convert other sound files like .wav and even raw sound to .au. The best is Cool Edit.
Init() also looks for a parameter with the name "sound". If the value of this parameter is "on" (case insensitive), sounds may be played as soon as they download. If the value is anything else (i.e. "off") or the parameter "sound" ommited, sounds will be off by default and will not play until on() is called.
Note that you never call this method directly but is automatically called by the browser when you set up your sounds.
Example |
View the source code for the websounds page.
Comments:
You must also have soundsingle.class (1111 bytes), as well as the sounds, in the current directory (or somewhere you can get at them).