|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmhframework.media.MHSoundManager
public class MHSoundManager
Manages all sound data for a game application made with the MHFramework package. I recommend that maintaining the sound manager for a game application should be the responsibility of the application's data model.
This class borrows heavily from the SoundManager class presented in the the book Java 1.4 Game Programming by Andrew Mulholland and Glenn Murphy (Wordware Publishing).
Field Summary | |
---|---|
static int |
AUTO_ASSIGN_CHANNEL
Constant for telling the MHSoundManager object to automatically assign an available channel number for playing a sound. |
Constructor Summary | |
---|---|
MHSoundManager()
Constructor. |
Method Summary | |
---|---|
int |
addSound(java.lang.String filepath)
Adds a sound file to the sound manager. |
boolean |
isChannelPlaying(int channelId)
States whether the requested channel is currently playing a sound. |
boolean |
isSoundPlaying(int soundId)
States whether the sound specified by soundId is currently playing. |
void |
play(int soundId,
boolean loop,
int channelId)
Plays a sound. |
void |
stop(int soundId)
Stops the sound specified by soundId if it is currently playing. |
void |
stopAllChannels()
Stops all active channels. |
void |
stopChannel(int channelId)
Stops the sound playing in the channel specified by channelId. |
void |
update(javax.sound.sampled.LineEvent e)
Event handler for line events. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int AUTO_ASSIGN_CHANNEL
Constructor Detail |
---|
public MHSoundManager()
Method Detail |
---|
public int addSound(java.lang.String filepath)
filepath
- The path and file name of the sound file to
be added.
public void play(int soundId, boolean loop, int channelId)
Note: This method was made "synchronized" due to problems with calling it from event handlers. The same channel was being allocated to multiple sound instances, which caused the program to hang.
soundId
- ID of which sound to play.loop
- True if sound should be looped.channelId
- ID of the channel on which to play the
sound.public void stop(int soundId)
soundId
- The ID of the sound to be stopped.public void stopChannel(int channelId)
channelId
- The channel containing the sound to be
stopped.public boolean isChannelPlaying(int channelId)
Checks two conditions to determine this:
If both of the above conditions are true, the channel is playing a sound.
channelId
- The ID of the channel to be checked for
sound data.
public boolean isSoundPlaying(int soundId)
soundId
- The ID of the sound in question.
public void update(javax.sound.sampled.LineEvent e)
update
in interface javax.sound.sampled.LineListener
e
- The line event being handled.public void stopAllChannels()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |