Search code examples
androiddebuggingreleasesoundpool

Android Soundpool.play() not working in release buld


I'm trying to build an app that records sounds and then plays them back. The recording part works perfectly but when I try to replay the sound it does nothing. When I run it in the debugger and step trough the steps to play the audio, it works. When I remove all breakpoints and run the program in debug, it does not.

The problem is probably caused by some things that are done in the background and are not completed before I try to run the audio, but I'm not entirely sure.

Any help would be greatly appreciated.

Here are the relevant parts of the source code.

Creating the Soundpool

mSoundPool = new SoundPool(16, AudioManager.STREAM_MUSIC, 0);

Playing from the soundpool

int soundId = mSoundPool.load(mAudioRecorder.stop(), 0);
if(soundId > 0){
    mSoundPool.play(soundId, 0.99f, 0.99f, 0, -1, 1.0f);
}

Audiorecorder.java the output file is .mp4

mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);


public String stop() throws IOException {
    mRecorder.stop();
    return mPath;
}

Solution

  • I had the same problem yesterday - the reason of not proper working in RELEASE mode, is the fact that you have to wait for SoundPool.load(...) function to perform.

    I solved it with loading sounds in menu activity before executing activities/fragments in which I am going to play some music with SoundPool.play(...) function.

    In DEBUG mode app have a lot of time to perform SoundPool.load(...) function, so it works then.