AudioRecordingDemo and Android problems

Hello! I’m having an issue running AudioRecordingDemo on a Emulated Device on Android Studio.

All the RuntimePermissions are granted including “Virtual microphone uses host audio input” on the emulated device Extended Controls, and I can see the recordingThumbnail being updated in real time but whenever I click the Record button, the recordButton.setButtonText (“Stop”) is not called and I hit the following Assertion Failure:

I/JUCE: JUCE Assertion failure in juce_android_RuntimePermissions.cpp:209

In physical devices the demo does run.

I’m building an app that hits the same Assertion Failure and I’m clueless on how to solve it.

If I missed anything please let me know.

Thanks!

Sounds like you forgot to set “Audio Input Required” to enabled in the Projucer, can that be? Also, if you have built the project without the setting enabled, then make sure you clean your build folder.

It is enabled.

Then I would investigate if it has to do with the writeExternalStorage permissions. Your problem sounds similar to this: Problem with writeExternalStorage runtime permissions on Android Hope this helps in some way.

Unfortunately not. I’ve been through this thread and the problem is different than mine =(

No one managed to make AudioRecordingDemo run on Android ??

The AudioRecordingDemo works just fine on Android, both on the emulator and on actual devices. I suggest you compile the Demorunner, since it is configured properly for all platforms (unlike the individual demos which usually require some tweaking) and it contains all the demos. See if that works and look under the hood. Good luck.

Thanks for trying to help. But why does the AudioRecordingDemo runs fine on your android and your actual devices but in any other that I’ve tested it doesnt? What android phone model are you using on the emulator of Android Studio?

I don’t understand why a Demo which actually have specifications inside the code for Android doesn’t even run on Android… Why no one is able to help me ? I’ve posted this on Discord many times and asked a lot of different people, what is wrong ?

Have you tried getting the Demorunner to run on Android?

It doesn’t even compile, also, the Demorunner uses the exact same code as the examples folder because it simply includes them using the DemoPIPs1.cpp

Do you really can make the AudioRecordingDemo work properly in an emulated device on Android Studio ?

Yes it works.

Now, if you can’t get the Demorunner to compile then you have something misconfigured and it will be easier to find out what it is if you try getting the Demorunner to compile.

What errors do you get?

One problem I found is that on API > 28 checking the RuntimePermissions::writeExternalStorage causes an assert.

To actually save the recorded audio to a file instead of sharing it, replace the last stopRecording() method with the following:

std::unique_ptr<FileChooser> fileChooser;

void stopRecording()
{
    recorder.stop();
    
    fileChooser.reset (new FileChooser ("Choose a file to save"));
    
    fileChooser->launchAsync (FileBrowserComponent::saveMode 
                             | FileBrowserComponent::canSelectFiles 
                             | FileBrowserComponent::warnAboutOverwriting,
        [this] (const FileChooser& fc) mutable 
        {
            if (fc.getURLResults().size() > 0) 
            {   
                auto url = fc.getURLResult();
            
               #if JUCE_ANDROID             
                auto androidDocument = AndroidDocument::fromDocument (url);
                auto outputStream = androidDocument.createOutputStream();
               #elif ! JUCE_IOS
                auto outputStream = url.getLocalFile().createOutputStream();
               #else
                auto outputStream = url.createOutputStream();
               #endif
                
                FileInputStream fileInputStream (lastRecording);
                outputStream->writeFromInputStream (fileInputStream, -1);
            }
        });

    recordButton.setButtonText ("Record");
    recordingThumbnail.setDisplayFullThumbnail (true);
}

Thanks for bringing this to our attention. The demo needed updating for compatibility with newer Android versions, where the WRITE_EXTERNAL_STORAGE permission should no longer be used.

Nice! Thanks!