3

I'm trying to loop a ~30 seconds audio track multiple times. I'm using a MediaPlayer to play the sounds, here is the code where its created:

mAnimalMediaPlayer = MediaPlayer.create(mContext, fish.getSound());

I then call:

mAnimalMediaPlayer.setLooping(true);
mAnimalMediaPlayer.start();

when a play button is clicked. When the track loops, there is a small but noticeable pause between the track ending and the new loop beginning. I am positive that the audio file im using does not contain any actual pause.

Here is an android bug report which has been up for some time: https://code.google.com/p/android/issues/detail?id=18756

I've tried a few workarounds (such as using .ogg files instead of .mp3) but the problem persists.

I'm looking for any possible workaround that will allow me to seamlessly loop the playback multiple times.

Orbit
  • 2,985
  • 9
  • 49
  • 106
  • If you're willing to go all-out on this, consider using MediaCodec to decode the audio to raw pcm and pump that into a streaming mode AudioTrack. This a non-trivial amount of code, but gives you full control over the audio that gets rendered. – Doug Stevenson Mar 20 '16 at 03:09
  • 1
    Possible duplicate of [Cant able to achieve Gapless audio looping so far on Android](http://stackoverflow.com/questions/26274182/cant-able-to-achieve-gapless-audio-looping-so-far-on-android) – Mattia Maestrini Mar 20 '16 at 20:24

1 Answers1

1

There is a very noticeable pause. However, I have just discovered through experimentation on an emulator running level 25 that if one prepares two identical players and alternately starts them one after the other when the other has finished then the gap becomes much more difficult to hear.