com.brackeen.javagamebook.sound
Class SoundManager

java.lang.Object
  extended byjava.lang.ThreadGroup
      extended bycom.brackeen.javagamebook.util.ThreadPool
          extended bycom.brackeen.javagamebook.sound.SoundManager

public class SoundManager
extends ThreadPool

The SoundManager class manages sound playback. The SoundManager is a ThreadPool, with each thread playing back one sound at a time. This allows the SoundManager to easily limit the number of simultaneous sounds being played.

Possible ideas to extend this class:


Constructor Summary
SoundManager(javax.sound.sampled.AudioFormat playbackFormat)
          Creates a new SoundManager using the maximum number of simultaneous sounds.
SoundManager(javax.sound.sampled.AudioFormat playbackFormat, int maxSimultaneousSounds)
          Creates a new SoundManager with the specified maximum number of simultaneous sounds.
 
Method Summary
 void close()
          Closes this ThreadPool and returns immediately.
 javax.sound.sampled.AudioInputStream getAudioInputStream(java.io.InputStream is)
          Creates an AudioInputStream from a sound from an input stream
 javax.sound.sampled.AudioInputStream getAudioInputStream(java.lang.String filename)
          Creates an AudioInputStream from a sound from the file system.
static int getMaxSimultaneousSounds(javax.sound.sampled.AudioFormat playbackFormat)
          Gets the maximum number of simultaneous sounds with the specified AudioFormat that the default mixer can play.
 Sound getSound(javax.sound.sampled.AudioInputStream audioStream)
          Loads a Sound from an AudioInputStream.
 Sound getSound(java.io.InputStream is)
          Loads a Sound from an input stream.
 Sound getSound(java.lang.String filename)
          Loads a Sound from the file system.
 boolean isPaused()
          Returns the paused state.
 void join()
          Closes this ThreadPool and waits for all running threads to finish.
 java.io.InputStream play(java.io.InputStream is)
          Plays a sound from an InputStream.
 java.io.InputStream play(java.io.InputStream is, SoundFilter filter)
          Plays a sound from an InputStream with an optional sound filter.
 java.io.InputStream play(Sound sound)
          Plays a sound.
 java.io.InputStream play(Sound sound, SoundFilter filter, boolean loop)
          Plays a sound with an optional SoundFilter, and optionally looping.
 void setPaused(boolean paused)
          Sets the paused state.
 
Methods inherited from class com.brackeen.javagamebook.util.ThreadPool
runTask
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SoundManager

public SoundManager(javax.sound.sampled.AudioFormat playbackFormat)
Creates a new SoundManager using the maximum number of simultaneous sounds.


SoundManager

public SoundManager(javax.sound.sampled.AudioFormat playbackFormat,
                    int maxSimultaneousSounds)
Creates a new SoundManager with the specified maximum number of simultaneous sounds.

Method Detail

getMaxSimultaneousSounds

public static int getMaxSimultaneousSounds(javax.sound.sampled.AudioFormat playbackFormat)
Gets the maximum number of simultaneous sounds with the specified AudioFormat that the default mixer can play.


close

public void close()
Description copied from class: ThreadPool
Closes this ThreadPool and returns immediately. All threads are stopped, and any waiting tasks are not executed. Once a ThreadPool is closed, no more tasks can be run on this ThreadPool.

Overrides:
close in class ThreadPool

join

public void join()
Description copied from class: ThreadPool
Closes this ThreadPool and waits for all running threads to finish. Any waiting tasks are executed.

Overrides:
join in class ThreadPool

setPaused

public void setPaused(boolean paused)
Sets the paused state. Sounds may not pause immediately.


isPaused

public boolean isPaused()
Returns the paused state.


getSound

public Sound getSound(java.lang.String filename)
Loads a Sound from the file system. Returns null if an error occurs.


getSound

public Sound getSound(java.io.InputStream is)
Loads a Sound from an input stream. Returns null if an error occurs.


getSound

public Sound getSound(javax.sound.sampled.AudioInputStream audioStream)
Loads a Sound from an AudioInputStream.


getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream(java.lang.String filename)
Creates an AudioInputStream from a sound from the file system.


getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream(java.io.InputStream is)
Creates an AudioInputStream from a sound from an input stream


play

public java.io.InputStream play(Sound sound)
Plays a sound. This method returns immediately.


play

public java.io.InputStream play(Sound sound,
                                SoundFilter filter,
                                boolean loop)
Plays a sound with an optional SoundFilter, and optionally looping. This method returns immediately.


play

public java.io.InputStream play(java.io.InputStream is)
Plays a sound from an InputStream. This method returns immediately.


play

public java.io.InputStream play(java.io.InputStream is,
                                SoundFilter filter)
Plays a sound from an InputStream with an optional sound filter. This method returns immediately.