Android的使用javax MIDI音序器不玩中期文件 [英] Android javax midi Sequencer not playing mid file

查看:217
本文介绍了Android的使用javax MIDI音序器不玩中期文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用了Android的javax MIDI lib和它工作得很好处理MIDI信息,但是当我打开并尝试播放MIDI文件不执行任何声音。我已经验证了这一切的步骤:

Hi i'm using javax midi lib with Android and it works very well handling midi messages, but when i open and try to play a midi file it does not perform any sound. I've verified all this steps:


  • 无异常处理MIDI文件。

  • previously我已经得到了与AOL的Winamp,并用DAW播放MIDI文件。

  • 我已经放在soundbank.gm到目录C:\\ Program Files文件\\的Java \\ jdk1.7.0_45 \\ lib目录\\音频和C:\\ Program Files文件(x86)的\\的Java \\ jre1.8.0_66 \\ lib目录\\音频

  • 我得到了与一流的MediaPlayer成功扮演它

  • 我的code:

  • No exception handling the midi file.
  • Previously i've got play the midi file with winamp and with a DAW.
  • I've placed soundbank.gm to directory C:\Program Files\Java\jdk1.7.0_45\lib\audio and C:\Program Files (x86)\Java\jre1.8.0_66\lib\audio
  • I've got play it successfully with MediaPlayer class
  • My code:

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!

What should i do to ear something? Thx!!

推荐答案

从Java端,你必须连接到一个合成器,这样你就以下 - 如果您的音序器绑起来,或者你不能得到你应该检查默认在您的系统中可用的所有其他人。检查在甲骨文的教程进一步信息

From the java side, you have to connect to a synthesizer so you do the following -if your sequencer is tied up or you cant get the default you should check all others available in your system. Check the tutorials at oracle for further info

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( );

}

这篇关于Android的使用javax MIDI音序器不玩中期文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆