Can anyone explain to me why my java freezes when I use the MidiSystem.getSequencer in the javax.sound.midi API? (until I press Ctl+C) The Midi sound works fine, the program works fine, but the Public class MiniMiniMusicApp will not complete. >Yes , I'm working through the Head First book. test code: __________________________________________________________
import javax.sound.midi.*; public class MiniMiniMusicApp {
public static void main(String[] args){ MiniMiniMusicApp mini = new MiniMiniMusicApp(); mini.play(); System.out.println("Competed Main"); } 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 ex) { ex.printStackTrace(); } System.out.println("Competed Play"); } }
Jason Menard
Sheriff
Joined: Nov 09, 2000
Posts: 6450
posted
0
I'm going to move this to Other Java APIs. Please post any follow-ups there.
No problems now,, I have been using the Midi API in conjunction with a JFrame and the command "setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)" will gracefully close the program without the Midi hanging.. This topic can now be closed. Thanks.