I'm trying to play midi within a browser, and have been using a Java Applet that works just fine on PCs. Its extremely unreliable on OSX, so I wrote a simple test case that exhibits the same problem:
import javax.sound.midi.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class MidiPlayer {
public static void main(String[] args) {
try {
Sequencer sequencer = MidiSystem.getSequencer();
if (sequencer == null)
throw new MidiUnavailableException();
sequencer.open();
FileInputStream is = new FileInputStream("sample.mid");
Sequence mySeq = MidiSystem.getSequence(is);
sequencer.setSequence(mySeq);
sequencer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
It sounds like the occasional message is getting dropped.. Like a noteoff won't fire, and a random note will hang on forever. Is this a known problem in OSX? Seems like Java just isn't getting enough love from Apple these days.
If anyone has a better solution to playing Midi in a browser, I'm all ears!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…