View Feed
group-icon
Java Developers
Community of Java Developers: Get Java Programming Help from fellow Java Developers across the world.
597 Members
Join this group to post and comment.
sahilgandhi87
sahilgandhi87 • Mar 8, 2009

I have Java programming Related problems

when i run this program,it does nothing........it should produce sound but nothing.............What to do????



import javax.sound.midi.*;
class MiniMusicPlayer1
{
public static void main(String args[])
{
try
{
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();

Sequence seq = new Sequence(Sequence.PPQ,1);
Track track = seq.createTrack();

for(int i=5;i<61;i=i+4)
{
track.add(makeEvent(144,1,i,100,i));
track.add(makeEvent(128,1,i,100,i+2));
}

sequencer.setSequence(seq);
sequencer.setTempoInBPM(220);
sequencer.start();
}catch(Exception e)
{
e.printStackTrace();
}
}
public static MidiEvent makeEvent(int comd,int chan,int one,int two,int tick)
{
MidiEvent event = null;
try
{
ShortMessage a = new ShortMessage();
a.setMessage(comd,chan,one,two);
event= new MidiEvent(a,tick);
}catch(Exception e)
{}
return event;

}
}
CEMember
CEMember • Mar 8, 2009
Hey sahilgandhi !

What a superb work you have done 😀 Your program is perfectly working fine for me. It is making sound like someone is beating some musical instrument (I guess guitar or piano 😉) very hardly.

Check may be there is some problem in your computer system. You are not getting any compiler errors right? then just please wait for few seconds for listening the sound 😀
ms_cs
ms_cs • Mar 8, 2009
Only a single syntax error shown for me...
Very superb program...If you have similar programs post it here.....
komputergeek
komputergeek • Mar 8, 2009
@sahilgandhi87: Nice program.Working fine.
CEMember
CEMember • Mar 13, 2009
ms_cs
Only a single syntax error shown for me...
Very superb program...If you have similar programs post it here.....
Man, what syntax error it showed for you? 😕 It was perfectly fine for me .
komputergeek
komputergeek • Mar 14, 2009
Even I am not getting any syntax error.
ms_cs
ms_cs • Mar 15, 2009
CEMember
Man, what syntax error it showed for you? 😕 It was perfectly fine for me .
No ,,,While Copying the program I just missed some of the text

Share this content on your social channels -