1

Im new to java and im creating a test application demonstrating creating sounds. i have this test code:

public class MiniMiniMusicApp {

    public MiniMiniMusicApp(){

    }

    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,20,100);
            MidiEvent noteOn = new MidiEvent(a, 1);
            track.add(noteOn);

            ShortMessage b = new ShortMessage();
            a.setMessage(128, 1, 44, 100);
            MidiEvent noteOff = new MidiEvent(b, 3);
            track.add(noteOn);

            Track[] t = seq.getTracks();
            player.setSequence(seq);

            player.start();

            System.out.println("Done");
        }
        catch (Exception ex){
            System.out.println("Ooops something went wrong");
            ex.printStackTrace();
        }
    }
}

and i can hear no sound. I've read somewhere that i need a soundbank, so i downloaded the deluxe version from here and i have copied it into C:\Program File\Java\jdk1.7.0_45\jre\lib created a folder called audio and copied soundbank.gm in there. What am i missing here?

4

1 回答 1

2

我没有足够的代表来评论这个问题 - 但你的意思是有这条线

track.add(noteOn);

在那里两次?

你也打电话

a.setMessage(...)

两次。

还有一些其他奇怪的事情正在发生,创建一个从未使用过的数组等。

我建议稍微清理一下你的代码。

于 2013-11-07T14:48:31.363 回答