# No sound on android with mp3s as binary resource

**URL:** <https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060>\
**Category:** Android\
**Created:** [November 9, 2017, 1:19am UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060 "2017-11-09T01:19:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanwayland](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/seanwayland/32/3192_2.png) [@seanwayland](https://forum.juce.com/u/seanwayland)\
**Post date:** [November 9, 2017, 1:19am UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060/1 "2017-11-09T01:19:50Z")

</div>

Hi all,  
I created an audio application using JUCE.  
I edited the [https://juce.com/doc/tutorial\_playing\_sound\_files](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 …

```auto
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;
```

---

<div class="post-metadata">

**Author:** ![seanwayland](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/seanwayland/32/3192_2.png) [@seanwayland](https://forum.juce.com/u/seanwayland)\
**Post date:** [November 11, 2017, 3:26am UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060/2 "2017-11-11T03:26:09Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 11, 2017, 1:09pm UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060/3 "2017-11-11T13:09:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![seanwayland](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/seanwayland/32/3192_2.png) [@seanwayland](https://forum.juce.com/u/seanwayland)\
**Post date:** [November 11, 2017, 1:41pm UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060/4 "2017-11-11T13:41:50Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 11, 2017, 1:48pm UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060/5 "2017-11-11T13:48:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![seanwayland](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/seanwayland/32/3192_2.png) [@seanwayland](https://forum.juce.com/u/seanwayland)\
**Post date:** [November 11, 2017, 3:56pm UTC](https://forum.juce.com/t/no-sound-on-android-with-mp3s-as-binary-resource/25060/6 "2017-11-11T15:56:47Z")

</div>

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 !!
