I was trying to implement a MIDI player for a java program. So I started using the javax.sound.midi
library. I load my Sequencer
and my Synthesizer
there:
private void playMidiFile() {
Soundbank soundfont = MidiSystem.getSoundbank(Util.internalFile("FluidR3_GM.sf2").getInputStream());
Sequencer sequencer = MidiSystem.getSequencer();
Synthesizer synthesizer = MidiSystem.getSynthesizer();
sequencer.open();
synthesizer.open();
synthesizer.loadAllInstruments(soundfont);
sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());
sequencer.setSequence(Util.internalFile("MyMusic.mid").getInputStream());
sequencer.start();
}
The first second I can clearly hear my loaded soundfont, but after that somehow the midi is played back with a standard soundfont. I checked and the SF2 file is supported by the javax.sound.midi
library (synthesizer.isSoundBankSupported(soundfont)
returns true).
Does anybody know why my program behaves like this?