aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes MidiSystem.getSequencer (locks up) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "MidiSystem.getSequencer (locks up)" Watch "MidiSystem.getSequencer (locks up)" New topic
Author

MidiSystem.getSequencer (locks up)

Mace Challinor
Greenhorn

Joined: Dec 04, 2003
Posts: 2
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
I'm going to move this to Other Java APIs. Please post any follow-ups there.
Mace Challinor
Greenhorn

Joined: Dec 04, 2003
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MidiSystem.getSequencer (locks up)
 
Similar Threads
midi player when used from commandline does not work
Head First Java Chapter 11 MiniMiniMusicApp
MiniMiniMusicApp? anyone else having issues with it?
Java sounds not working!
Application doesn't quit -- MiniMiniMusicApp sample from Head First Java