• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

JavaSound Sequencer

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You called "player.open();" but you never called "player.close();". Add it and it should work.
 
Marshal
Posts: 74341
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic