我试图用我自己的声音替换MIDI文件的默认声音;然而,新的声音在旧的声音之上播放,而不是取代旧声音。我的代码:
Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
synthesizer.unloadAllInstruments(synthesizer.getDefaultSoundbank());
synthesizer.loadAllInstruments(MidiSystem.getSoundbank(new File("Airhorn.sf2")));
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File("Test.mid")));
sequencer.setSequence(inputStream);
sequencer.start();
答案 0 :(得分:0)
您可以使用
MidiSystem.getSequencer(false)
获取音序器并阻止将其连接到默认设备。由我工作,JDK 8,Windows 10.