com.brackeen.javagamebook.sound
Class MidiPlayer

java.lang.Object
  extended bycom.brackeen.javagamebook.sound.MidiPlayer
All Implemented Interfaces:
java.util.EventListener, javax.sound.midi.MetaEventListener

public class MidiPlayer
extends java.lang.Object
implements javax.sound.midi.MetaEventListener


Field Summary
static int END_OF_TRACK_MESSAGE
           
 
Constructor Summary
MidiPlayer()
          Creates a new MidiPlayer object.
 
Method Summary
 void close()
          Closes the sequencer.
 javax.sound.midi.Sequence getSequence(java.io.InputStream is)
          Loads a sequence from an input stream.
 javax.sound.midi.Sequence getSequence(java.lang.String filename)
          Loads a sequence from the file system.
 javax.sound.midi.Sequencer getSequencer()
          Gets the sequencer.
 boolean isPaused()
          Returns the paused state.
 void meta(javax.sound.midi.MetaMessage event)
          This method is called by the sound system when a meta event occurs.
 void play(javax.sound.midi.Sequence sequence, boolean loop)
          Plays a sequence, optionally looping.
 void setPaused(boolean paused)
          Sets the paused state.
 void stop()
          Stops the sequencer and resets its position to 0.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

END_OF_TRACK_MESSAGE

public static final int END_OF_TRACK_MESSAGE
See Also:
Constant Field Values
Constructor Detail

MidiPlayer

public MidiPlayer()
Creates a new MidiPlayer object.

Method Detail

getSequence

public javax.sound.midi.Sequence getSequence(java.lang.String filename)
Loads a sequence from the file system. Returns null if an error occurs.


getSequence

public javax.sound.midi.Sequence getSequence(java.io.InputStream is)
Loads a sequence from an input stream. Returns null if an error occurs.


play

public void play(javax.sound.midi.Sequence sequence,
                 boolean loop)
Plays a sequence, optionally looping. This method returns immediately. The sequence is not played if it is invalid.


meta

public void meta(javax.sound.midi.MetaMessage event)
This method is called by the sound system when a meta event occurs. In this case, when the end-of-track meta event is received, the sequence is restarted if looping is on.

Specified by:
meta in interface javax.sound.midi.MetaEventListener

stop

public void stop()
Stops the sequencer and resets its position to 0.


close

public void close()
Closes the sequencer.


getSequencer

public javax.sound.midi.Sequencer getSequencer()
Gets the sequencer.


setPaused

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


isPaused

public boolean isPaused()
Returns the paused state.