I have Java programming Related problems

sahilgandhi87

sahilgandhi87

@sahilgandhi87-jf94Wy Oct 22, 2024
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;

}
}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • CEMember

    CEMember

    @cemember-PlqlWH 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

    @ms-cs-Ab8svl Mar 8, 2009

    Only a single syntax error shown for me...
    Very superb program...If you have similar programs post it here.....
  • komputergeek

    komputergeek

    @komputergeek-Yf5hJ4 Mar 8, 2009

    @sahilgandhi87: Nice program.Working fine.
  • CEMember

    CEMember

    @cemember-PlqlWH 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

    @komputergeek-Yf5hJ4 Mar 13, 2009

    Even I am not getting any syntax error.
  • ms_cs

    ms_cs

    @ms-cs-Ab8svl 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