• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaSound Sequencer

 
Rajat Sarkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.sound.midi.*;

public class MiniMiniMusicApp
{
public static void main(String[] arsg)
{
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,4);
track.add(noteOff);

player.setSequence(seq);

player.start();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}


when i run this by :
javac MiniMiniMusicApp.java
java MiniMiniMusicApp

Command prompt disappears,after playing a sound.why the command prompt disappears? Is there anything wrong?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple things that will probably be said sooner or later:

UseCodeTags
QuoteYourSources

Anyway, I think the program just doesn't terminate. This is from Head First Java by Sierra/Bates, Chapter 11 if I remember correctly. Mine would sit just like this also, and I believe there was a topic recently created about this program too.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You called "player.open();" but you never called "player.close();". Add it and it should work.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
W. Joe Smith wrote:A couple things that will probably be said sooner or later:

UseCodeTags
QuoteYourSources

. . . I believe there was a topic recently created about this program too.
Thank you for pointing out those FAQs. I recognised the program, which actually creates a question here about once a month.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic