Android 6.0+: No Sound Using the New MIDI API

余生颓废 提交于 2019-12-04 04:46:20

问题


I am using the new MIDI API in order to play some MIDI notes. However, I am unable to hear any sound, nor any exception is being thrown. The code for the same is as follows:

//initialising the MidiReceiver
private MidiReceiver midiReceiver;
midiReceiver = new MidiReceiver() {
    @Override
    public void onSend(byte[] msg, int offset, 
        int count, long timestamp) throws IOException {

    }
};

/*Then in my loop containing note_on or note_off events*/
byte[] buffer = new byte[32];
int numBytes = 0;
int channel = 2; // MIDI channels 1-16 are encoded as 0-15.               
// NOTE_STATUS is either 0x90 or 0x80
buffer[numBytes++] = (byte)(NOTE_STATUS + (channel - 1)); 
buffer[numBytes++] = (byte)noteValue; // the required MIDI pitch
buffer[numBytes++] = (byte)127; // max velocity
int offset = 0;
midiReceiver.send(buffer, offset, numBytes);

What am I doing wrong here? I think it must be because the onSend method is empty. How do I use it in order to make my app play back the note(s) within the Android device?


回答1:


I couldn't find any indication in the documentation that the new MIDI API actually let you synthesize audio, so, it seems you need to generate the sound yourself.

Maybe this library might be useful.



来源:https://stackoverflow.com/questions/44003644/android-6-0-no-sound-using-the-new-midi-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!