I have tried MediaPlayer, ExoPlayer, SoundPool. All of them had a gap when looping 15secs long audio file. Is there any solution or library?
Asked
Active
Viewed 720 times
1
-
did you try this mediaPlayer.setLooping(true); ?? – shinilms Aug 25 '16 at 08:05
-
Of course. But there is a short gap between two plays. I need gapless looping. – Mladen Rakonjac Aug 25 '16 at 08:21
-
try this http://stackoverflow.com/a/13410499/5545429 – shinilms Aug 25 '16 at 08:57
2 Answers
0
the new release of Exoplayer2 supports gapless audio, reading all the informations from id3 headers. You only have to create a ConcatenatingMediaSource including all your tracks and if they contain the gapless info into the headers the player itself will combine them automatically.
using the Exoplayer2 demo:
String[] uriStrings = new String[]{
Environment.getExternalStorageDirectory()+"/Music/gapless/temp1.mp3",
Environment.getExternalStorageDirectory()+"/Music/gapless/temp2.mp3"
};
uris = new Uri[uriStrings.length];
for (int i = 0; i < uriStrings.length; i++) {
uris[i] = Uri.parse(uriStrings[i]);
}
MediaSource[] mediaSources = new MediaSource[uris.length];
for (int i = 0; i < uris.length; i++) {
mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
}
MediaSource mediaSource = new ConcatenatingMediaSource(mediaSources);
player.prepare(mediaSource, !shouldRestorePosition);
There are also LoopingMediaSource to manage the looping of MediaSources. You can combine all media sources in a tree.
The only issue with all this is that the structure of MediaSources you give to the player in the prepare is static.

Manuela
- 462
- 6
- 18
0
You can use LoopingMediaSource as source instead.
MediaSource source = new ExtractorMediaSource(videoUri, ...);
// Loops the video indefinitely.
LoopingMediaSource loopingSource = new LoopingMediaSource(source);
Ref: https://google.github.io/ExoPlayer/guide.html#seamlessly-looping-a-video

Deepti
- 934
- 12
- 18
-
I hear very distinct gaps on ExoPlayer 2. I have tried ogg as well – Oleksandr Albul May 04 '18 at 05:59