|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.ThreadGroup
com.brackeen.javagamebook.util.ThreadPool
com.brackeen.javagamebook.sound.SoundManager
public class SoundManager
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:
| Nested Class Summary | |
|---|---|
protected class |
SoundManager.SoundPlayer
The SoundPlayer class is a task for the PooledThreads to run. |
| Field Summary | |
|---|---|
private java.lang.ThreadLocal |
localBuffer
|
private java.lang.ThreadLocal |
localLine
|
private boolean |
paused
|
private java.lang.Object |
pausedLock
|
private javax.sound.sampled.AudioFormat |
playbackFormat
|
| 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 | |
|---|---|
protected void |
cleanUp()
Does any clean up before closing. |
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. |
protected void |
threadStarted()
Signals that a PooledThread has started. |
protected void |
threadStopped()
Signals that a PooledThread has stopped. |
| Methods inherited from class com.brackeen.javagamebook.util.ThreadPool |
|---|
getTask, 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 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private javax.sound.sampled.AudioFormat playbackFormat
private java.lang.ThreadLocal localLine
private java.lang.ThreadLocal localBuffer
private java.lang.Object pausedLock
private boolean paused
| Constructor Detail |
|---|
public SoundManager(javax.sound.sampled.AudioFormat playbackFormat)
public SoundManager(javax.sound.sampled.AudioFormat playbackFormat,
int maxSimultaneousSounds)
| Method Detail |
|---|
public static int getMaxSimultaneousSounds(javax.sound.sampled.AudioFormat playbackFormat)
protected void cleanUp()
public void close()
ThreadPool
close in class ThreadPoolpublic void join()
ThreadPool
join in class ThreadPoolpublic void setPaused(boolean paused)
public boolean isPaused()
public Sound getSound(java.lang.String filename)
public Sound getSound(java.io.InputStream is)
public Sound getSound(javax.sound.sampled.AudioInputStream audioStream)
public javax.sound.sampled.AudioInputStream getAudioInputStream(java.lang.String filename)
public javax.sound.sampled.AudioInputStream getAudioInputStream(java.io.InputStream is)
public java.io.InputStream play(Sound sound)
public java.io.InputStream play(Sound sound,
SoundFilter filter,
boolean loop)
public java.io.InputStream play(java.io.InputStream is)
public java.io.InputStream play(java.io.InputStream is,
SoundFilter filter)
protected void threadStarted()
threadStarted in class ThreadPoolprotected void threadStopped()
threadStopped in class ThreadPool
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||