How to loop a sound without gaps in Android?-ThrowExceptions

Exception or error:

I want to loop a sound without gaps in android.
I tried to use the code mediaplayer.setLooping(true) to loop the sound, but there is always a little pause when the first sound is over and the next sound start.

How to solve:

Try using the .ogg file format for the sound files in your application. I had this same issue, and after a lot of research , i tried the .ogg format and it loops without any gaps in android.

Info about .ogg format:

You can easily convert your sound file from .mp3 or what have you, to .ogg using the popular open source app VLC Media Player.


this is a bug in the android operating system 🙁


Also worth noting is that gapless playback was added with Jelly Bean (API level 16). It allows you to set a secondary mediaplayer that should be used for playing a next audio stream, as long as the primary player hasn’t finished playing the current audio yet. This could potentially be used to create a gapless ‘loop’ too.

public void setNextMediaPlayer (MediaPlayer next)

Obviously this won’t be of much help for most of the market (currently < 3% of the devices is running JB), but nevertheless worth mentioning.


It usually works just fine, unless you have a really slow phone.

I would double check the sound file with an audio editor like Audacity, to verify that it doesn’t have any silence at the beginning or end of the file.

Leave a Reply

Your email address will not be published. Required fields are marked *