我试图用javax.sound.midi
玩一下我遇到了一个问题 - 我听不到声音。我有音库安装btw。代码看起来像这样:
public class MainClass {
public static void main(String[] args) {
Synthesizer synth = null;
try {
synth = MidiSystem.getSynthesizer();
synth.open();
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
final MidiChannel[] mc = synth.getChannels();
System.out.println(mc.length);
Soundbank sB = synth.getDefaultSoundbank();
Instrument[] i = sB.getInstruments();
synth.loadInstrument(i[0]);
mc[5].noteOn(60, 600);
System.out.println("The SoundBank might be null - " + sB.equals(null));
System.out.println("The Synthesizer is open - " + synth.isOpen());
System.out.println(i[0]);
System.out.println(mc[0]);
}
}
System.out.println行的结果如下所示:
The SoundBank might be null - false
The Synthesizer is open - true
Instrument: Piano 1 bank #0 preset #0
com.sun.media.sound.SoftChannelProxy@7d132f26
为什么没有播放声音的任何想法(我试过不同的乐器,不同的音符,速度和midichannels - 没有效果)?