| Author |
JavaSound Sequencer
|
Rajat Sarkar
Greenhorn
Joined: Sep 07, 2008
Posts: 18
|
|
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
Joined: Feb 10, 2009
Posts: 710
|
|
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.
|
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
|
 |
Brian Legg
Ranch Hand
Joined: Nov 07, 2008
Posts: 488
|
|
You called "player.open();" but you never called "player.close();". Add it and it should work.
|
SCJA
~Currently preparing for SCJP6
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
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.
|
 |
 |
|
|
subject: JavaSound Sequencer
|
|
|