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;