Android ExoPlayer : Does it solve gapless / seamless playback issue that is broken for the Android Media Player
Asked Answered
J

4

30

Has anyone tried using ExoPlayer to achieve this? I tried looking online with no success.

When I say gapless playback, I am referring to the problem of using the media player to play local videos back to back. After the first video is done playing, there is a noticeable delay of 1 second before the second video starts.

Hoping this question helps in understanding this issue further. For reference please look at the following question:

Android: MediaPlayer gapless or seamless Video Playing

Jeavons answered 7/8, 2015 at 0:56 Comment(0)
R
4

ExoPlayer 2, which is now officially released, seems to support gapless playback using the ConcatenatingMediaSource class. From its developer guide:

Transitions between sources are seamless. There is no requirement that the sources being concatenated are of the same format (e.g. it’s fine to concatenate a video file containing 480p H264 with one that contains 720p VP9). The sources may even be of different types (e.g. it’s fine to concatenate a video with an audio only stream).

And the example code:

MediaSource firstSource = new ExtractorMediaSource(firstVideoUri, ...);
MediaSource secondSource = new ExtractorMediaSource(secondVideoUri, ...);
// Plays the first video, then the second video.
ConcatenatingMediaSource concatenatedSource =
    new ConcatenatingMediaSource(firstSource, secondSource);
Runstadler answered 20/9, 2016 at 4:42 Comment(2)
This is awesome. Will try it out soon.Jeavons
This isn't awesome, what about common scenarios like I'm writing a streaming music player (for instance) and when I start the first song I don't know which songs are going to be next (user adds to queue during playback)Waiwaif
B
4

EDIT: ExoPlayer 2 supports gapless playback, but as of the time of writing is still unreleased as a stable version.

You will most likely never be able to achieve perfect gapless playback of multiple tracks with ExoPlayer or Android Media Player. Neither have been written to support starting multiple tracks and I imagine it will stay out of scope for both of them.

You can achieve gapless playback by using 2 different player instances, once you have started and played the first, you can load the second and start playback once the first finishes. Using this method you could have a gapless solution, as long as you prepare the second video during playback of the first.

To take it further, you can also use 2 different surface textures for rendering the multiple videos, once the first video reaches the end you could fade out the texture and fade in the new one. Resulting in a nice seamless video effect.

Because of the nature of playing multiple videos at once you will most likely want to create your own timer for incrementing the time and deciding when to switch to the next video, rather than trying to use the callbacks from ExoPlayer or Android Media. This will allow you to keep track of the time in a more accurate fashion, without needing to keep talking to multiple video codecs.

Blackguardly answered 7/6, 2016 at 10:24 Comment(1)
With MediaPlayer, you can just create and prepare a second one and then play that in the onFinished callback of the first MediaPlayer. I have done this with great success.Calcicole
R
4

ExoPlayer 2, which is now officially released, seems to support gapless playback using the ConcatenatingMediaSource class. From its developer guide:

Transitions between sources are seamless. There is no requirement that the sources being concatenated are of the same format (e.g. it’s fine to concatenate a video file containing 480p H264 with one that contains 720p VP9). The sources may even be of different types (e.g. it’s fine to concatenate a video with an audio only stream).

And the example code:

MediaSource firstSource = new ExtractorMediaSource(firstVideoUri, ...);
MediaSource secondSource = new ExtractorMediaSource(secondVideoUri, ...);
// Plays the first video, then the second video.
ConcatenatingMediaSource concatenatedSource =
    new ConcatenatingMediaSource(firstSource, secondSource);
Runstadler answered 20/9, 2016 at 4:42 Comment(2)
This is awesome. Will try it out soon.Jeavons
This isn't awesome, what about common scenarios like I'm writing a streaming music player (for instance) and when I start the first song I don't know which songs are going to be next (user adds to queue during playback)Waiwaif
N
0

I know this is not the answer you've been looking for, but it's the only reasonable answer. The sole way to ensure no gaps in playback is to download the entire file first and begin playback when it's done. Otherwise, in the event that you lose connectivity before the file is finished downloading, pausing is inescapable.

Newsman answered 17/8, 2015 at 1:4 Comment(1)
I think my question is very vauge and misleading. I updated it. my apologies.Jeavons
C
0

I just tried switching to ExoPlayer from the standard MediaPlayer implementation and the gap is the same if not worse. However I have used a very simple method of restarting the player when the status changes to ended. I don't know if there's a better proper way to do it, perhaps with 2 different ExoPlayers.

Cockrell answered 25/1, 2016 at 19:24 Comment(3)
Interesting. Post a follow up here if you come across a better. ThanksJeavons
Here's someone trying to work on a solution for ExoPlayer: github.com/google/ExoPlayer/pull/1070Cockrell
I can now confirm that you can have gapless video playback (at least of the same video) with the new looping mode in ExoPlayer2.Cockrell

© 2022 - 2024 — McMap. All rights reserved.