我无法改变JSR-135上的midi频道节目

时间:2013-05-28 01:27:29

标签: java-me midi midlet midi-instrument midi-interface

我告诉他们我正在使用MIDlet,我无法更改任何乐器midi频道。 我尝试使用.shortMidiEvent(0xC0 + channel, program, 0);setProgram(channel, -1, program)而没有结果。 在我的手机上是诺基亚X3-02仪器更换不起作用,只有midlet的模拟器。 这是代码片段

public final class Dmgcpu implements Runnable {
private Player player;
private static MIDIControl synth;

private void initSound() {
    try {

        player = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
        player.prefetch();
        synth = (MIDIControl) player.getControl("javax.microedition.media.control.MIDIControl");
    } catch (Exception ex) {
    }

    synth.setProgram(0, -1, instSound_a);
    //synth.shortMidiEvent(0xC0, instSound_a, 0);

   //sound test
   synth.shortMidiEvent(0x90 + channel, note[i], volume * MASTER_VOLUME);

   thread_sleep(300);

   synth.shortMidiEvent(0x80 + channel, note[i], 0);

}

是你可以改变乐器,因为据我所知你在这种情况下使用player数组。我试着没有工作。 saludos

1 个答案:

答案 0 :(得分:0)

使用JavaME,媒体播放器总是很棘手。某些设备要求您预取(),而其他设备则会崩溃。有些人喜欢(),而有些人不喜欢。所以最好使用prefetch()和realize()等多个try / catch块。 由于prefetch(),您的try块可能会失败。所以试试这个:

public final class Dmgcpu implements Runnable {
private Player player = null;
private static MIDIControl synth = null;

private void initSound() {
  try {
    player = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
  } catch (Exception e) {}
  try {
    player.realize();
  } catch (Exception e) {}
  try {
    player.prefetch();
  } catch (Exception e) {}
  try {
    synth = (MIDIControl) player.getControl("javax.microedition.media.control.MIDIControl");
  } catch (Exception ex) {}

    if (synth!=null) {
    synth.setProgram(0, -1, instSound_a);

    //synth.shortMidiEvent(0xC0, instSound_a, 0);

    //sound test
    synth.shortMidiEvent(0x90 + channel, note[i], volume * MASTER_VOLUME);

    thread_sleep(300);

    synth.shortMidiEvent(0x80 + channel, note[i], 0);
  }
}

有关媒体播放器的更多信息: http://indiegamemusic.com/help.php?id=1