Android: How to play Gapless audio loop in MediaPlayer?
Asked Answered
R

0

7

I know this question asked multiple times in this platform but none of them are solving my issue. I was trying to play a sound file in a loop but when a loop is complete first time there is a noticeable gap.

I have sound files in .M4A format.

I was trying to solve this for a week now and I have tried below solutions.

1) I tried using mediaPlayer.setLooping(true); and mediaPlayer.setNextMediaPlayer(mediaPlayer1)

2) Tried different file formats OGG, WAV and MP3.

3) Tried different players Exoplayer and Oboe.

4) Tried this article https://medium.com/@viksaaskool/gappless-sound-loop-on-android-1ddeccc563de

5) Tried this article as well https://medium.com/@tonyowen/playing-local-r-raw-files-with-exoplayer2-1a62276ebeaa

Also, I already check StackOverflow Q&A.

1) Not able to achieve Gapless audio looping so far on Android

2) Gapless Playback with android MediaPlayer

3) How to loop a sound without gaps in Android?

4) Android: Gapless playback of a looped audio file in MediaPlayer

But from above none of them worked.

Any help will highly appreciate.

Thanks in Advance

Retch answered 24/3, 2020 at 7:30 Comment(6)
Maybe not the answer you are looking for but you could use the Superpowered Audio SDK. (superpowered.com/audio-overview). You need to write a simple player in C++ though and builld a JNI to communicate with the player. I used it some time ago and you can loop audio without a gap.Transgress
Thank you for your answer but I am looking for something open source.Retch
Hi, can i see the code as well?. Are you using onCompletion(MediaPlayer mediaPlayer) method? there have you reset the media player by mediaPlayer.reset();?Neighborhood
I ran into a similar issue trying to loop a video in Flash a few years back. The issue was related to stream buffers taking a bit to be ready (even with local disk streams). I ended up adding an extra second or so at the end, performing time checks and resetting the current time to 0. Another possible solution would be to have the audio loaded in memory with a custom player, but don't know if that would fit your purpose.Imperception
I tried all of your mentioned approaches and the only working solution for me was 5) Exoplayer. I used mp3 files from asset folder. On which device/android version did you test it? If duration of sound is short (~3 seconds) then SoundPool will work as well as long ogg file was exported in low quality.Nomography
@Nomography Thank you for your response, As you said got my solution using ExoplayerRetch

© 2022 - 2024 — McMap. All rights reserved.