2013-05-28 47 views
0

我告訴他們我正在使用MIDlet,並且無法更改任何樂器MIDI通道。 我用.shortMidiEvent(0xC0 + channel, program, 0);setProgram(channel, -1, program)嘗試沒有結果。我手機上的 是諾基亞X3-02樂器變化不起作用,只有midlet的仿真器。 這裏是代碼片段我無法更改JSR-135上的MIDI通道程序

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

回答

0

媒體播放器對JavaME來說總是很棘手。有些設備要求您預取(),而其他設備則會因此而崩潰。有些喜歡意識到(),而有些則不喜歡。所以最好使用prefetch()和realize()等多個try/catch塊。 由於預取(),您的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

+0

手機崩潰與'預取();' – kapodamy