问题
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