1

I have tried MediaPlayer, ExoPlayer, SoundPool. All of them had a gap when looping 15secs long audio file. Is there any solution or library?

Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55

2 Answers2

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