No sound on android with mp3s as binary resource


#1

Hi all,
I created an audio application using JUCE.
I edited the https://juce.com/doc/tutorial_playing_sound_files
Instead of selecting sound files I added mp3s as binary resources using
projucer.
It works fine on OSX.
I am trying to get it to work on android.
I have a samsung phone running android version 7.0
The application will load and run and looks pretty but doesn’t make any sound .
I can share all the code for the entire project if needed.

Perhaps if I rewrote the whole shebang and loading files instead it would work ? Then I guess I could add the resources directly in android studio. I am a git better with gradle, intellij and java than C++ and JUCE …
Perhaps someone has an idea?
I can’t find much info on the web about this …
Juce is a great tool which I really want to learn …
I could probably code the whole thing in JAVA but in the long run this is more fun …
Sean

This is the relevant classes I think …

public:
MainContentComponent()
:   state (Stopped)

{
// I had already changed this ..
// a previous JUCE community thread suggested it as a fix
setAudioChannels (0, 2);
}

// in binary data header  ..

namespace BinaryData
{
extern const char*   _36_mp3;
const int            _36_mp3Size = 22968;


// chooses file from namedResourceList
// all the mp3 files are the same size
// this is an edited version of
// https://juce.com/doc/tutorial_playing_sound_files

void playfile(int n)
{
AudioFormatReader* reader = formatManager.createReaderFor( new MemoryInputStream(BinaryData::getNamedResource(BinaryData::namedResourceList[n], mp3Size), mp3Size, false));
if (reader != nullptr)
{
ScopedPointer<AudioFormatReaderSource> newSource = new AudioFormatReaderSource (reader, true);
transportSource.setSource (newSource, 0, nullptr, reader->sampleRate);
playButton.setEnabled (true);
readerSource = newSource.release();
}
if (reader == nullptr)
{
playButton.setEnabled (false);
}
transportSource.setPosition (0.0);
changeState (Starting);

// I set it up with no audio input
setAudioChannels (0, 2);


void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override
{
transportSource.prepareToPlay (samplesPerBlockExpected, sampleRate);
}

void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
if (readerSource == nullptr)
{
bufferToFill.clearActiveBufferRegion();
return;
}


transportSource.getNextAudioBlock (bufferToFill);
}


// I  use std:vector
// and int choice1 = Random::getSystemRandom().nextInt(2); to randomly select files ..

// these classes are called

AudioFormatManager formatManager;
ScopedPointer<AudioFormatReaderSource> readerSource;
AudioTransportSource transportSource;

#2

I have tried 2 different samsung galaxy android phones …
The application runs fine on an old IPAD …
no luck with Android…
It looks fine and the GUI works as expected but no audio …


#3

Did it not occur to you to debug it, and step through what happens when you try to open/play the file, so you can just watch and see exactly what’s failing? I know android studio’s a bit clunky, but it does have a debugger!


#4

Yes thanks Jules I spent quite a bit if time with that debugger and also
looking at what code is generated and comparing the sample rates and bit
rate with what the DAC on the phone. There is lots of JUCE code and
variables and assembly to sift through. I will keep battling. Very
inexperienced programmer here who has never needed a debugger before…


#5

I think if you get down to the assembly then you’ve gone too far! But you can learn a lot from the juce code if you watch it run.

You did enable JUCE_USE_MP3AUDIOFORMAT, right?


#6

woohoo it’s working Jules!! so kind of you to provide all this software and troubleshoot it !! That flag was set to “default” and setting it to “enable” got it to work !! So cool thanks !!