Error play audio file in Android

It’s been a week since my first attempt trying to play an audio file in Android and i still can’t get it done. Now i’m desperate for help. Here’s my AudioEngine which extend AudioSource class:

AudioEngine::AudioEngine(){
#if JUCE_ANDROID
    AudioDeviceManager::AudioDeviceSetup deviceSetup = AudioDeviceManager::AudioDeviceSetup();
    deviceSetup.bufferSize = 7168;
    deviceSetup.sampleRate = 44100;
    String err = deviceManager->initialise(0, 2, nullptr, true, "", &deviceSetup);
#else
    String err = deviceManager->initialiseWithDefaultDevices (0, 2);
#endif

    formatManager.registerBasicFormats();
    player.setSource(this);
    deviceManager->addAudioCallback(&player);
}

AudioEngine::~AudioEngine() {
    stop();
    deviceManager->removeAudioCallback(&player);
}

void AudioEngine::play(const juce::File &audioToPlay) {
    Log::e("starting playing");
    stop();

    AudioFormatReader *reader = formatManager.createReaderFor(audioToPlay);
    std::unique_ptr<AudioFormatReaderSource> newSource(new AudioFormatReaderSource (reader, false));
    transportSource.setSource(newSource.get(), 0, nullptr, reader->sampleRate);
    transportSource.setPosition(0.0);
    readerSource.reset(newSource.release());
    transportSource.start();
}
void AudioEngine::prepareToPlay(int samplesPerBlockExpected, double sampleRate) {
    transportSource.prepareToPlay (samplesPerBlockExpected, sampleRate);
}

void AudioEngine::releaseResources() {
    transportSource.releaseResources();
}

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

    transportSource.getNextAudioBlock (bufferToFill);
}

And whenever i call AudioEngine::play(), it threw this error:

I’ve examined several example but they pretty much outdated, or throwing the same error when i call deviceManager.initialiseWithDefaultDevice(0,2)

Appreciate any help. Thank you

I haven’t done any Android dev in a bit, but that stack trace looks strange with the calls to the AudioDeviceManger destructor? and is that the entire stack?

Yes, that’s all i’ve got from the stack, there’s still a little bit on the top but just my application package name

The error is fixed, it turn out that my audioDeviceManager was not initialised

1 Like