您好我在Android上使用javax midi lib,它可以很好地处理midi消息,但是当我打开并尝试播放midi文件时,它不会执行任何声音。我已经验证了所有这些步骤:
我的代码:
private Sequencer playMidiFile()
{
try {
Sequencer mSeqr = MidiSystem.getSequencer();
InputStream in = getAssets().open(MIDI_FILE);
Sequence mSeq = MidiSystem.getSequence(in);
mSeqr.open();
mSeqr.setSequence(mSeq);
mSeqr.start(); //it is supposed this execution will perform the play of the file
return mSeqr;
} catch (MidiUnavailableException e) {
e.printStackTrace();
} catch (InvalidMidiDataException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
我该怎么做才能听到什么? THX !!
答案 0 :(得分:0)
从java端,您必须连接到合成器,以便执行以下操作 - 如果您的音序器被绑定或者您无法获得默认值,则应检查系统中的所有其他可用组件。查看oracle的教程以获取更多信息
static void play(Sequence sequence)
throws MidiUnavailableException, InvalidMidiDataException, IOException
{
Sequencer sequencer=MidiSystem.getSequencer( );
sequencer.open();
Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
sequencer.getTransmitter().setReceiver(synthesizer.getReceiver( ));
sequencer.setSequence(sequence);
sequencer.addMetaEventListener(new MetaEventListener( ) {
public void meta(MetaMessage m) {
if (m.getType( ) == END_OF_TRACK) {
System.out.println("end of track");
return;
}
}
});
sequencer.start( );
}