Android MIDI issue - MIDI_SERVICE returns null


#1

Hi Folks,

Trying to use MIDI USB on Android, with Huawei Android device running Android 6.0

This call returns null.

    public MidiDeviceManager getAndroidMidiDeviceManager()
    {
        if (getSystemService (MIDI_SERVICE) == null)
            return null;

Has anybody else seen this issue?

I wonder if this particular device doesn’t support MIDI for some reason … :frowning:

Pete


#2

Can anybody please let me know of an Android device they’ve used successfully with USB MIDI (and Juce)? Thanks in advance! :slight_smile:

Pete


#3

Hi. My Asus Zenpad is fine.

Have you tried running your code against the simulator to check it’s ok there?


#4

Hi - thanks for helping out!

I didn’t actually think to try the Emulator - I’ll try that in a bit - great idea.

For the record, I can confirm that my second-hand Nexus 5X by LG reports the MIDI service! Unfortunately, the device has a USB-C port, so I need to get an adaptor before I can test it with external MIDI hardware :slight_smile:

It seems that not all Marshmallow devices are equal; I suspect that for many of the cheaper ones, the USB connector might not be capable of acting as a host, and therefore the MIDI service won’t be enabled. This is a bit of a minefield for Android developers and users wanting to work with MIDI!

Anyhow, I think it’d be useful if other Juce Android developers could add their devices to this thread, on which they’ve found Juce MIDi to work. Might be a useful resource.

I’d be really interested to know if Chromebooks (with Android capability) support MIDI devices, for example…

Best to all,

Pete


#5

Just for the record, the Simulator shows the MIDI service; but doesn’t pick-up any of the devices connected to the Mac.


#6

In case anybody is interested, I’ve found a few things

  • your users might need to have developer mode enabled, in order to configure the USB port to work with MIDI data
  • not all cables and adaptors work - this is particularly hard to track down - good luck!
  • even though a device has Marshmallow, and claims to support MIDI USB - it might not work; I’ve only yet seen it work with Nexus 5X; that might be due to cables/adaptors, of course…
  • when you open the Juce MIDI device, you cannot query it immediately for devices; you need to wait a bit before trying this (as the underlying Java API is asynchronous in this regard). Note to devs: ideally, the Juce MIDI API would allow a listener to be attached, so the app can be notified as devices come-and-go - that’d be far nicer than having a timer-base poller.

Hoping this helps somebody!

Pete


#7

Hi, interesting findings. TBH, i’ve got a number of users on a number of different devices and never had any issues reported such as you describe in points 1-3.


#8

Interesting findings Pete, thanks. Yes, it is frustrating that the behaviour is not consistent across Android devices, and it’s often the case for other functionalities too. A listener for MIDI devices becoming available / unavailable is a good feature request. We will add it to the backlog.


#9

Thank you, Lukasz! :slight_smile:

Another request: would it be possible for a Juce Android project to be configured such that it could run on (say) Android 4.4, but support MIDI if the device were running Android 6 or later? My understanding is that this isn’t possible right now with Juce. If I’m wrong, please let me know :slight_smile:

Best wishes,

Pete


#10

Yes this is also something we are actively working on.


#11

That is really good news, and has made my day. Many thanks! Pete


#12

Hi Fabian,

Have you got a rough date for when this feature might arrive?

The reason I’m so interested, is that it affects our ability to sell effectively though the Amazon App Store (where really, you’re limited to Android 5 as a baseline for apps… due to the fact that FireOS (used by Kindles) is based on 5.1.1…)

Thanks in advance!

Pete


#13

Sorry I can’t give you an ETA at the moment.


#14

Hi Fabian, OK, that is a shame :slight_smile:

For my own interest, I’ve dug-around, and see that code like this:
DECLARE_JNI_CLASS (MidiDeviceManager, JUCE_ANDROID_ACTIVITY_CLASSPATH “$MidiDeviceManager”)

… wasn’t designed to work with optional classes. I guess that’ll be the sort of thing you’re having to tidy-up right now!

Pete


#15

That’s exactly the stuff we are tidying up - we will basically access the classes either through reflection or only load bytecode if we now that the depending classes are available.


#16

Hi Fabian,

It is very kind of you to explain - and it really sounds like a very exciting development!

With best wishes,

Pete