JUCE
JUCE copied to clipboard
[Bug]: Android: AudioPlaybackDemo isn't working on Android 10+
Detailed steps on how to reproduce the bug
Build the AudioPlaybackDemo project for Android and execute it on a device which runs Android 10+ (API 29+).
Result: createInputStream() returns false.
JUCE forum reference: link
I believe this is due to the fact that in Android 10 the way to access files has changed, please see my post here in the linked thread.
What is the expected behaviour?
The choosen audio files plays.
Operating systems
Android
What versions of the operating systems?
10+
Architectures
ARM
Stacktrace
No response
Plug-in formats (if applicable)
No response
Plug-in host applications (DAWs) (if applicable)
No response
Testing on the develop branch
The bug is present on the develop branch
Code of Conduct
- [X] I agree to follow the Code of Conduct
Looks like it would need to be updated to use the AndroidDocument class to work with Android 10+.
I believe this was fixed in https://github.com/juce-framework/juce/commit/f46b94b6ff2a128d4b1dacc12f4efaef5ab01f46
Hi @reuk,
sorry for the late feedback. Unfortunately the (unmodified) AudioPlaybackDemo is still not working for me in Android Studio (Windows) on current JUCE development branch (https://github.com/juce-framework/JUCE/commit/3816b095a8b6051521613baec8923392dfa669fc). It now triggers an assertion when trying to open an audio file (not sure if related to the original issue though, I could also open a new issue for it, if preferred.)

I'm guessing that AndroidDocument::fromDocument is failing for some reason, but I can't think why. If you stick a breakpoint in that function, can you find out which branch it takes?
It might also be helpful to see the output of logcat just before the assertion is hit, just in case any Java exceptions have been raised.
Thanks for the reply.
Here's stepping through (stepping 'over' actually, as too much calls to show with 'stepping into') from AndroidDocument::fromDocument until assert trigger.

And here's a logcat (as I'm quite new to Android dev I had to google how to do it lol, hope it's useful.) AudioPlaybackDemo logcat.txt
It looks like creating a reader for an mp3 file may fail if JUCE_USE_MP3AUDIOFORMAT=1 is missing from the preprocessor definitions. In that case, the demo tries to load an empty URL into the thumbnail view.
I've got a change staged that will update the demo to disallow loading mp3 files, and to allow loading flac files. The change will also prevent files from being loaded into the thumbnail view if they previously failed to load into the transport.
I'll update this thread once the change is public.
Thanks @reuk.
While you are tweaking the AudioPlaybackDemo for Android, maybe take also this into consideration? https://forum.juce.com/t/unmodified-exported-android-project-triggers-assertion/55099
(I don't understand why an Audio playback demo wants permission to record audio anyway... :))
The demo has now been updated, removing mp3 support and adding flac support to the file chooser:
https://github.com/juce-framework/JUCE/commit/8b708b348d44ab47b2bdefcba41d27d02a2b413c
It now works out of the box with flac files. Thanks!