nu.dll.mm
Class Sound

java.lang.Object
  |
  +--nu.dll.mm.Sound

public class Sound
extends java.lang.Object

A very simple generic sound clip API. As of now only useful for smaller sound collections, as each loaded sounds allocates its own channel and keeps it until unloaded. This also means that each sound clip can only be played once concurrently. The playSound() methods are asyncronous (they will return as soon as the sound clip has started playing). The loadSound() methods are, however, synchronous and will not return until the audio clip has been loaded into memory.


Constructor Summary
Sound()
          Created a normal sound object.
Sound(boolean enabled)
          If the enabled parameter is false, the audio subsystem will never be used and all methods in this class will be dummies.
 
Method Summary
 boolean isEnabled()
          Returns true if this Sound object is capable of playing audio, false otherwise.
 boolean isMuted()
          Returns true if this Sound object has been muted by the mute() method, false otherwise.
 void loadSound(java.io.File f, java.lang.String key)
          Loads a sound clip from the file represented by given File object.
 void loadSound(java.io.InputStream is, java.lang.String key)
          Loads an uncompressed sound clip (in a supported format such as WAV or AU).
 void loadSound(java.io.InputStream is, java.lang.String key, boolean gzipped)
          Loads a sound clip of a supported format such as WAV or AU from the given InputStream.
 void loadSounds(java.io.InputStream is)
          Reads a property list from the input stream and loads the audio resources specified therein.
 void mute()
          Stops all sounds and prevents sounds from be played until unmute() is called.
 void playSound(java.lang.String key)
          Plays the sound with the given label.
 void playSound(java.lang.String key, int loop)
          Please the sound with the given label, perhaps repeatedly.
 void playSound(java.lang.String key, int loop, boolean restart)
          Please the sound with the given label, perhaps repeatedly.
 void stopAllSounds()
          Stops all currently playing sound clips.
 void stopSound(java.lang.String key)
          Stops a sound clip if it is playing.
 void unloadSound(java.lang.String key)
          Closes a sound clip's resources and dereferences it.
 void unmute()
          If mute() has been called, re-enabled sound playing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sound

public Sound()
Created a normal sound object.

Sound

public Sound(boolean enabled)
If the enabled parameter is false, the audio subsystem will never be used and all methods in this class will be dummies.
Method Detail

loadSounds

public void loadSounds(java.io.InputStream is)
                throws java.io.IOException
Reads a property list from the input stream and loads the audio resources specified therein. A sound clip may be gzipped, in which case its name must end with ".gz".
See Also:
Properties.load(InputStream)

loadSound

public void loadSound(java.io.File f,
                      java.lang.String key)
               throws java.io.IOException
Loads a sound clip from the file represented by given File object. If the file name ends with ".gz", it is assumed to be compressed with GZip.

loadSound

public void loadSound(java.io.InputStream is,
                      java.lang.String key)
               throws java.io.IOException
Loads an uncompressed sound clip (in a supported format such as WAV or AU).

loadSound

public void loadSound(java.io.InputStream is,
                      java.lang.String key,
                      boolean gzipped)
               throws java.io.IOException
Loads a sound clip of a supported format such as WAV or AU from the given InputStream.
Parameters:
is - The InputStream object to load the sound data from
key - The label to store the sound clip with
gzipped - if true, the stream will be uncompressed before passed to the audio subsystem.

playSound

public void playSound(java.lang.String key)
Plays the sound with the given label. No loop and if the clip is already playing, it will be restarded.
Parameters:
key - The label of the sound to play.

playSound

public void playSound(java.lang.String key,
                      int loop)
Please the sound with the given label, perhaps repeatedly.
Parameters:
key - The label of the sound to play.
loop - an integer specifying how many times to loop the clip (i.e. 1 plays the clip twice).

playSound

public void playSound(java.lang.String key,
                      int loop,
                      boolean restart)
Please the sound with the given label, perhaps repeatedly.
Parameters:
key - The label of the sound to play.
loop - an integer specifying how many times to loop the clip (i.e. 1 plays the clip twice).
restart - if false, the given clip does not restart if it is already playing.

stopSound

public void stopSound(java.lang.String key)
Stops a sound clip if it is playing.

stopAllSounds

public void stopAllSounds()
Stops all currently playing sound clips.

unloadSound

public void unloadSound(java.lang.String key)
Closes a sound clip's resources and dereferences it.

mute

public void mute()
Stops all sounds and prevents sounds from be played until unmute() is called.

unmute

public void unmute()
If mute() has been called, re-enabled sound playing.

isEnabled

public boolean isEnabled()
Returns true if this Sound object is capable of playing audio, false otherwise.

isMuted

public boolean isMuted()
Returns true if this Sound object has been muted by the mute() method, false otherwise.