Java 如何在Android中正确打开MIDI设备并发送MIDI消息?

Java 如何在Android中正确打开MIDI设备并发送MIDI消息?,java,android,midi,Java,Android,Midi,我正在开发一个应用程序,将Android智能手机上的Midi信息发送到USB2.0-Midi电缆接口,该接口通过OTG电缆与手机相连。我仍然停留在打开MIDI输入/输出端口上,没有这些端口我就无法继续前进。 我已经尝试了我想到的一切。MIDI库并没有得到很好的介绍,我做了大量的研究,读了一些Android MIDI示例,但在这里的最后我请求帮助。我的实现似乎是正确的,与Android在原始MidScope和MidSynth示例中的实现非常相似 此时,流程的每个步骤都会被记录下来。我发现,在调用方

我正在开发一个应用程序,将Android智能手机上的Midi信息发送到USB2.0-Midi电缆接口,该接口通过OTG电缆与手机相连。我仍然停留在打开MIDI输入/输出端口上,没有这些端口我就无法继续前进。 我已经尝试了我想到的一切。MIDI库并没有得到很好的介绍,我做了大量的研究,读了一些Android MIDI示例,但在这里的最后我请求帮助。我的实现似乎是正确的,与Android在原始MidScope和MidSynth示例中的实现非常相似

此时,流程的每个步骤都会被记录下来。我发现,在调用方法device.openInputPort(port nr)之前,一切正常。在那之后,什么也没有发生。helperIN仍然带有null赋值,尽管mOpenDevice已正确打开所有属性

mManager.openDevice(midiDeviceInfo,
new MidiManager.OnDeviceOpenedListener() {
    @Override
    public void onDeviceOpened(MidiDevice device) {
        Log.i("OnDeviceOpened", "before if");
        if (device == null) {
            Log.e("OnDeviceOpened", "cound not open" + midiDeviceInfo);
        } else {
            mOpenDevice = device;
            Log.i("OnDeviceOpened", "opened: " + mOpenDevice.getInfo().getProperties().getString(MidiDeviceInfo.PROPERTY_NAME));

            mListInput = new LinkedList<>();
            MidiInputPort helperIN = null;
            Log.i("OpenInputPort", "inPort Count: " + mOpenDevice.getInfo().getInputPortCount());

            for (int i = 0; i < mOpenDevice.getInfo().getInputPortCount(); i++) {
                Log.i("OpenInputPort", "Trying to open inPort nr: " + i); //last log seen
                helperIN = device.openInputPort(i); //stuck right here!
                Log.i("OpenInputPort", "Opened inPort nr: " + i); //this not seen
                mListInput.add(helperIN);
                if (helperIN == null) {
                    Log.e("openInputPort", "cound not open input port nr: " + i + " " + midiDeviceInfo.getPorts());
                    return;
                }else
                    Log.i("openInputPort", "Port nr: " + i + "connected");
                helperIN = null;
            }
        }
    }
}, null);
实际日志如下所示:

04-01 09:42:11.704 3712-3712/com.example.anthonylp.midiandoridtest I/MidiWhenAdded: Class created
04-01 09:42:52.788 3712-3712/com.example.anthonylp.midiandoridtest I/Midi Info: Name: null
Name: USB2.0-MIDI
04-01 09:42:52.788 3712-3712/com.example.anthonylp.midiandoridtest I/openMidiDevice: midiDeviceInfo not null
04-01 09:42:52.789 3712-3741/com.example.anthonylp.midiandoridtest I/OnDeviceOpened: before if
opened: USB2.0-MIDI
04-01 09:42:52.789 3712-3741/com.example.anthonylp.midiandoridtest I/OpenInputPort: inPort Count: 2
Trying to open inPort nr: 0
似乎再也没有什么结果了。 我希望代码打开设备MidiInputPort并将其分配给helperIN,然后将其添加到mListInput。
非常感谢你的帮助

日志输出是什么?编辑:添加日志。USB接口应该只有一个端口(每个方向)。请显示middeviceinfo中报告的所有内容。(为什么还有没有名字的设备?)我现在无法访问手机和midi接口。这两个设备,以及每个方向的两个端口,这可能是低成本的中国USB2.0-MIDI电缆的属性吗?哦,实际上是这根电缆,所以这可能与您的问题无关。日志输出是什么?编辑:添加日志。USB接口应该只有一个端口(每个方向)。请显示middeviceinfo中报告的所有内容。(为什么还有没有名字的设备?)我现在无法访问手机和midi接口。这两个设备,以及每个方向的两个端口,这可能是低成本中国USB2.0-MIDI电缆的特性吗?哦,实际上是这根电缆,所以这可能与您的问题无关。
04-01 09:42:11.704 3712-3712/com.example.anthonylp.midiandoridtest I/MidiWhenAdded: Class created
04-01 09:42:52.788 3712-3712/com.example.anthonylp.midiandoridtest I/Midi Info: Name: null
Name: USB2.0-MIDI
04-01 09:42:52.788 3712-3712/com.example.anthonylp.midiandoridtest I/openMidiDevice: midiDeviceInfo not null
04-01 09:42:52.789 3712-3741/com.example.anthonylp.midiandoridtest I/OnDeviceOpened: before if
opened: USB2.0-MIDI
04-01 09:42:52.789 3712-3741/com.example.anthonylp.midiandoridtest I/OpenInputPort: inPort Count: 2
Trying to open inPort nr: 0