AudioPlaybackDemo is not loading files: permission denied

Hi there. I’m on develop branch and I’m facing new problem with Android (gradle 5.4.1, plug-in 3.5.2)

While loading file createInputStream always returns nullptr. I have RuntimePermissions and I see the permission dialog, and all is granted. I’ve tried using URL::createInputStream - no luck.
File::existsAsFile() returns true. So everything is fine, but while creating input stream i’m tracking result with error “Permission denied”.
So I’ve checked AudioPlaybackDemo and there is the same issue. The problem is present on real devices (Pixel 2, Nexus 7), as well as on emulated Pixel 3.

any ideas?

Hello. Can anyone confirm that AudioPlaybackDemo is loading files without problems on Android 10 devices?
Thank you

I have exactly the same problem.
I figured out that if I compress files into a .zip container then it is possible to create an InputStream from files within it.
Hope there will be a fix for this soon.

I’m running into the same issue I think.
I’m trying to run the AudioPlaybackDemo on Android, but it seems the file chooser doesn’t work properly (i.e. it doesn’t recognize when an audio file, specifically mp3, is choosen).
Here’s a screencap of the app running in the emulator, but it behaves the same when running on my physical phone (Galaxy S5, running LineageOS, Android 12):

Summary

AudioPlaybackDemo.gif

Android Studio Bumblebee | 2021.1.1 Patch 2
JUCE 6.1.6 on master branch

Yes its working on android

@fazalurrehmansharif

Still not working for me, createInputStream() fails with Permission denied.
I’m trying reading a .wav from internal storage (Downloads).
On which Android version are you running it?
I’m trying on Android 10/API 29.

edit:
On Android 10+ the file access seems to have changed, looks like need to use Storage Access Framework now (unless using requestLegacyExternalStorage=true but that is deprecated in Android 11+).

Does JUCE currently even support these new file APIs?

edit:
Created an issue on GitHub:

I finally found the missing bit of information. :slight_smile:

But I got not far with this either.
I modified the AudioPlaybackDemo like this, but it crashes.

edit:
Logcat says this:

2022-07-11 18:09:17.963 8632-8632/com.juce.audioplaybackdemo A/libc: stack corruption detected (-fstack-protector)
2022-07-11 18:09:17.963 8632-8632/com.juce.audioplaybackdemo A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 8632 (dioplaybackdemo), pid 8632 (dioplaybackdemo)

bool loadURLIntoTransport (const URL& audioURL)
{
// unload the previous file source and delete it…
transportSource.stop();
transportSource.setSource (nullptr);
currentAudioFileSource.reset();

AudioFormatReader* reader = nullptr;

#if ! JUCE_IOS
if (audioURL.isLocalFile())
{
if (androidDocument.hasValue()) // this is true
reader = formatManager.createReaderFor (androidDocument.createInputStream()); // this crashes
}
else
#endif
{
if (reader == nullptr)
reader = formatManager.createReaderFor (audioURL.createInputStream (URL::InputStreamOptions (URL::ParameterHandling::inAddress)));
}

if (reader != nullptr)
{
	currentAudioFileSource.reset (new AudioFormatReaderSource (reader, true));

	// ..and plug it into our transport source
	transportSource.setSource (currentAudioFileSource.get(),
							   32768,                   // tells it to buffer this many samples ahead
							   &thread,                 // this is the background thread to use for reading-ahead
							   reader->sampleRate);     // allows for sample rate correction

	return true;
}

return false;

}

Is anyone using the `AndroidDocument` class successfully for playing an audio file and could help me out?