• Post Reply Bookmark Topic Watch Topic
  • New Topic

Midi Events  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a sound player app with the following code below, but when i run it, I get the following error message:

java.lang.IllegalStateException: sequencer not open
at com.sun.media.sound.RealTimeSequencer.start(Unknown Source)
at MiniMiniMusicApp.play(MiniMiniMusicApp.java:27)
at MiniMiniMusicApp.main(MiniMiniMusicApp.java:7)


how would I open the sequencer? here is my code:

import javax.sound.midi.*;

public class MiniMiniMusicApp {

public static void main (String [] args){
MiniMiniMusicApp mini = new MiniMiniMusicApp();
mini.play();
// close main
}
private void play() {

try {

Sequencer player = MidiSystem.getSequencer();

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);

player.setSequence(seq);

player.start();

} catch (Exception ex){
ex.printStackTrace();
}
} // close play
} // close class
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the error message suggests, try calling open() on the sequencer object before calling start():

player.open();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!