How to fix "Synthesizer not found" and "invalid meta event" ?
ghopretz opened this issue · 2 comments
My Code in Android Studio is:
try {
Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
synthesizer.unloadAllInstruments(synthesizer.getDefaultSoundbank());
synthesizer.loadAllInstruments(MidiSystem.getSoundbank(getAssets().open("SmallTimGM6mb.sf2")));
Sequencer sequencer = MidiSystem.getSequencer(false);
sequencer.open();
sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());
InputStream inputStream = new BufferedInputStream(getAssets().open("lagu.mid"));
sequencer.setSequence(inputStream);
sequencer.start();
Toast.makeText(this, "play", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "error "+e.toString(), Toast.LENGTH_SHORT).show();
}
Have you solved your problem, I have a problem similar to yours.
the same code ' Synthesizer synthesizer = MidiSystem.getSynthesizer(); ', but the synthesizer is null.
and when i use 'sequencer.start()', there is no sound.
MidiSystem.getSynthesizer()
This library appears to be a port of javax.sound.midi
, which I don't believe includes a synthesizer.
Someone else has ported the synthesizer from com.sun.media.sound
, which also conveniently bundles this library: https://github.com/KyoSherlock/MidiDriver
It also bundles a sample app which shows you how to use it: https://github.com/KyoSherlock/MidiDriver/blob/master/sample/src/main/java/cn/sherlock/midi/sample/MainActivity.java
I have an updated fork of that project here in case it helps: https://github.com/bmaupin/MidiDriver