Android 6.0+:使用新的MIDI API不会发出声音 [英] Android 6.0+: No Sound Using the New MIDI API

查看:181
本文介绍了Android 6.0+:使用新的MIDI API不会发出声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的MIDI API 为了播放一些MIDI音符.但是,我听不到任何声音,也没有抛出任何异常.相同的代码如下:

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

我在这里做错了什么?我认为一定是因为onSend方法为空.如何使用它来使我的应用在Android设备中播放笔记?

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?

推荐答案

我在

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.

也许此库可能有用.

这篇关于Android 6.0+:使用新的MIDI API不会发出声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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