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;
}