So I'm playing along with the Head First
Java book and I'm working on the midi examples in chapter 11.
For those of you not playing along at home there are a number of examples but they're all basically of the form :
/**
*
* Example class from Head First Java.
* Sierra, Kathy & Bates, Bert 2nd Ed (2005) O O'Riley Medi
*
*/
import javax.sound.midi.*;
public class MiniMiniMusicApp {
public static void main (
String[] args) {
MiniMiniMusicApp mini = new MiniMiniMusicApp();
mini.play();
}
public void play() {
try {
Sequencer player = MidiSystem.getSequencer();
player.open();
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
ShortMessage a = new ShortMessage();
a.setMessage(144, 1, 44, 100);
MidiEvent noteOn = new MidiEvent(a, 1);
track.add(noteOn);
ShortMessage b = new ShortMessage();
b.setMessage(128, 1, 44, 100);
MidiEvent noteOff = new MidiEvent(b, 16);
track.add(noteOff);
player.setSequence(seq);
player.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
Now the program works okay, makes noise and every thing, quite happily, but it hangs at the end.
Debugging it looks like it goes through all the midi code, but then waits at the last line of the program. I'm not sure I haven't spent that much time debugging.
Any ideas? I've tried setting the mini reference in main to null, but that doesn't seem to help, and calling play.stop() (which seems like it might make sense) only causes it to play nothing at all.
I realize this question has been asked before, but it doesn't seem to have been answered.
Thank you.