Problems with stuck connections over BLE MIDI

67 views
Skip to first unread message

Andrew Timberlake

unread,
Dec 19, 2023, 8:36:06 PM12/19/23
to android-midi
I am battling to figure out a bug and would appreciate some help.
At first I thought that my app was holding on to connections and I searched for memory leaks but then I was able to reproduce the problem using the MIDI+BTLE app.

What happens is roughly this:
1. Scan for BLE MIDI device (In my case I’ve tested with a CME WIDI Jack and a Yamaha MD-BT01)
2. Connect to the device
3. Kill the app (the device eventually disconnects)
4. Scan and connect again (the device connects) (At this point in my app I can open an input port and send MIDI commands but nothing is transmitted. From this point on even though the device never connects again, Android seems to report it as a linked device, allows me to open an input port and communicate with the device but it remains physically disconnected the entire time)
5. Kill the app (the device does not disconnect)
6. Can’t see the device in scan because it’s still connected
7. Turn off Bluetooth on the phone
8. The device disconnects
9. Scan for the device and connect (It says it’s connected but the device remains disconnected)
10. Unpair the device
11. Scan for device and connect (It says it’s connected but the device remains disconnected. You can actually see the device in the scan even though it’s seen as connected in the MIDI-BTLE app)

I have recorded a video of the behaviour at https://youtu.be/84t5mfWTLio
The phone is a Galaxy A33 running Android 13 (API level 33)

Is this an Android bug? Has anyone seen this behaviour?

Lee T. Davy

unread,
Dec 20, 2023, 9:00:01 AM12/20/23
to android-midi
The BLE MIDI app is not an app that uses the MIDI interface so it is an incomplete test.
At 1:50 in your video you show WIDI JACK as known and therefore becomes a previous paired device so SCAN will not see it as "ADD NEW DEVICE".

The gear on the BLUETOOTH screen next to WIDI JACK is the point to (re-)connect to make blue light solid not scan as blue light is falsely implying.
There also should be TRUST in the gear settings that says pair and reconnect again when device signal is detected nearby.

On the Android BLUETOOTH screen there is sometimes Previously connected devices that are not currently detected or not set as trusted.
This is similar to WIFI connections that are remembered when not near the connection and not set as automatically connect.

So the steps to BLUETOOTH are:
  1. Turn on radio (Bluetooth on Android)
  2. SCAN for new devices and reconnect any trusted devices.
  3. WIDI JACK is alone in the nearby devices and is either unknown or previously paired
  4. PAIR either first time or again
  5. CONNECT to PAIRED device
  6. Use GEAR to make TRUSTED to PAIR and CONNECT next time seen when RADIO is on nearby
  7. Run an app that issues commands or data to the TRUSTED and CONNECTED device
Think like a phone headset or buds where there could be a whole room full of devices to pick from.
MIDI is on par with ear buds so can be thought to be at the same level of TRUST and CONNECTION.

Until you answer the call or play music the BLUETOOTH is trusted, paired, connected and awaiting use including powered down device condition.

Even another way is think of it as a wire with a plug and socket designed to do one thing.
Terms are SOURCE and SINK for some connections.

Hope this helps as the WIDI JACK looks like an expensive wire that satisfies it's intended purpose to replace the hardwire.



Phil Burk

unread,
Dec 20, 2023, 1:52:58 PM12/20/23
to androi...@googlegroups.com
Hello Andrew,

I wrote the MIDI+BTLE app. I'm sorry that it has been giving you trouble. There are a couple things you should know.

1) The normal Bluetooth pairing UI on Android does not support BLE-MIDI. It can see the BLE-MIDI devices but when it connects, it does not enable the MIDI connection for the device. So it can actually interfere with the MIDI+BTLE app. This is a known issue that we have been trying to get fixed for quite a while.

2) You should leave the MIDI+BTLE app running in the background. Closing it may cause the MIDI connection to time out.

3) It looks like you are running an old version of the app. You can update it on Play Store at:

I will add on-screen instructions to the MIDI+BTLE app so this is more clear.

Just FYI, the MIDI+BTLE app source code is on GitHub: https://github.com/philburk/android-midisuite
You can file bugs in the Issues tab.

When the app connects to the BLE-MIDI device it calls:

That makes it available for other apps to open and use the BLE-MIDI device.

There is a test procedure at:

Thanks for reporting these problems. I will work on the MIDI+BTLE app over the holiday.

Phil Burk

--
You received this message because you are subscribed to the Google Groups "android-midi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-midi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-midi/77569f04-2086-47ab-afeb-460a88b1da78n%40googlegroups.com.

Andrew Timberlake

unread,
Dec 26, 2023, 6:37:15 PM12/26/23
to android-midi
Hi Phil

Thanks for your response. I don’t believe it’s a bug in the MIDI+BTLE app, I’m concerned that there is a bug in the connection handling in Android.

I have written an app (BBFF) which uses MIDI over bluetooth and I have gotten reports of the connection hanging and then not being able to reconnect. I went over my MIDI code with a fine toothed comb and couldn’t find any indication that I was doing anything wrong, like keeping connections open (though that remains a strong possibility).
I then turned to the MIDI+BTLE app as a reference and my video shows me able to create the same hanging situation using that app without my app even installed on the phone.

It appears to me that Android establishes a connection and then, even after the device has been disconnected (physically turned off) it remains visible within Android. Android reports it as an available device when querying MidiManager.devices, the app can open the device and open an input port without error, but obviously nothing happens because the device is no longer connected.
From that point, if I plug the MIDI adapter back in, there is nothing I can do to get it to correctly reconnect, whether I turn Bluetooth off and on again, Android continues to see the “old” device until I restart the phone.

I hope that helps explain my situation better.

—Andrew

 --
 You received this message because you are subscribed to a topic in the Google Groups "android-midi" group.
 To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-midi/RdxL54PFJuw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-midi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-midi/CACL%3DQ7xQB0FAaXL%2BTcGQQ_qXhFUgjGnE4UJwE9chiAdLXRPJBQ%40mail.gmail.com.

phil...@google.com

unread,
Dec 26, 2023, 6:45:51 PM12/26/23
to android-midi
Hello Andrew,

>  I don’t believe it’s a bug in the MIDI+BTLE app, I’m concerned that there is a bug in the connection handling in Android.

I agree. The new MIDI+BTLE app fixes some UI issues that sometimes hid the (X) button. It also updated the target SDK so it can be installed on new OS versions.
But those changes are not bugs related to this connection issue.


>  I’m concerned that there is a bug in the connection handling in Android.

I agree. The Bluetooth Settings does not understand MIDI. You can connect to a MIDI device but if you do then it becomes unusable.
We have been trying to get that fixed for years. But there are other higher priority items in the BT work queue.

If the problem survives rebooting BOTH the Android device and the MIDI device then the problem is certainly related to something stored in BT Settings.
Try to use the BT Settings to "FORGET" the MIDI device. Then maybe it will start working again using the MIDI+BTLE app.

After that, please avoid using the BT Settings to connect to BLE-MIDI devices.

Phil Burk

phil...@google.com

unread,
Dec 26, 2023, 7:15:03 PM12/26/23
to android-midi
It appears to me that Android establishes a connection and then, even after the device has been disconnected (physically turned off) it remains visible within Android. 

I did a test using the MIDI+BTLE app.

I connected using MIDI+BTLE app.
I swiped the HOME key then started my MIDI Synth Example app.
The Akai LPK25 Wireless appeared so I selected it.
I powered off the PLK25.
I waited 5-10 seconds.
The LPK25 automatically disappeared from the app device menu and disconnected.
I returned to the MIDI+BTLE app and the LPK25 was gone.


Reply all
Reply to author
Forward
0 new messages