Bluetooth audio issue on android
Report from discord:
The audio through speakers in my phone seems fine, but when playing with my bluetooth ear phones, the audio is delayed by 0.5-1 second. The delay seems longer when there has not been played any sound for a while. Different sounds also seem to get overlayed when the speaker had been inactive (e.g. a move and a capture being heard at the same time after about 10 seconds of no sounds playing, while visually, the delay between the actual moves is quite noticeable.) Have not had this issue with the current Lichess app. Delays are shorter (although still there due to the bluetooth connection), and the delay is always consistent on there. Android 10 On a MI 9 Bluetooth earbuds are Sennheiser CX True Wireless
I have no bluetooth speakers to test this. So I can't do much about it right now.
I can provide some feedback here, maybe try to revive this issue a little bit. Using Airpods pro 2 on Android, Bluetooth delay is consistently around 300ms (0.3 of a second). However the piece's sound delay ranges from half a second to sometimes multiple seconds. This inconsistency in timing leads me to believe that the majority of this delay stems from the app itself.
I was able to get this delay on video with a screen capturer. Because of the inconsistent timings of piece sounds, I'll share a few moments of long delays, and shorter delays.
Here's a long delay: these only happen occasionally, maybe 5% of the time. https://github.com/lichess-org/mobile/assets/108140722/36b6eb38-adc5-44f1-be06-23116726f7fb
Here's a medium delay, these happen frequently, yet sporadically: https://github.com/lichess-org/mobile/assets/108140722/2daab366-f072-43ad-b112-645b043ed081
Finally, here are some examples where delay isn't really present: https://github.com/lichess-org/mobile/assets/108140722/8c04ecab-db50-417b-99ca-6653d830ed1e
All of these examples were taken from the same game while using Airpods pro 2 on Android 14.
To add to this, I have noticed the same trend, where the longer the interval between when a move was last played and the next move, the larger the delay heard. The large delay, as shown above, was played after 11 seconds of thinking.
If it's coming from the app, no idea where it comes from. But this where to look at: https://github.com/lichess-org/flutter-soundpool
Two ideas that I saw there were sound cache issues, and Bluetooth going into a low power state, and having to wake up, causing a delay. I was able to replicate the delay by waiting around 15 seconds before making a move. The longer I waited the more delay I could get. https://github.com/lichess-org/mobile/assets/108140722/c379bb36-a48e-4f27-a088-0d2b3e5be5b2
Hey i would like to pick this if its open for a public contribution
Sure. Do you have an idea on how to fix this?
I believe that gathering logs and data initially would be beneficial to better understand the issue. Obtaining specific benchmarks or error logs could significantly streamline the problem-solving process here.