mhframework.media
Class MHMidiPlayer

java.lang.Object
  extended by mhframework.media.MHMidiPlayer
All Implemented Interfaces:
java.util.EventListener, javax.sound.midi.MetaEventListener

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

Plays MIDI files.

This class originated as the MidiPlayer class provided in the book Developing Games in Java by David Brackeen.

That code did contain one defect, however, which has been repaired for this version.


Field Summary
static int END_OF_TRACK_MESSAGE
           
 
Constructor Summary
MHMidiPlayer()
          Constructor.
 
Method Summary
 void close()
          Closes the sequencer.
 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.
static void main(java.lang.String[] args)
           
 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
clone, equals, finalize, 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

MHMidiPlayer

public MHMidiPlayer()
Constructor.

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.


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.


main

public static void main(java.lang.String[] args)