Achieving seamless playback while also setting pauseAtEndOfMediaItems = true
@microkatz is already working on this.
Since Mar 18, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
I have a use case where I want to control playback using pauseAtEndOfMediaItems = true, but in some circumstances (not known ahead of time) I want to listen to a onPlayWhenReadyChanged PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM event and immediately resume playback. The code would look something like this:
player.pauseAtEndOfMediaItems = true;
player.addMediaItem(video1);
player.addMediaItem(video2);
player.prepare();
player.playWhenReady = true;
player.addListener(object : Listener {
override fun onPlayWhenReadyChanged(playWhenReady: Boolean, reason: Int) {
if (/* shouldImmediatelyResumePlayback && */
!playWhenReady
&& reason == Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM) {
player.playWhenReady = true
}
}
})
I have observed that pauseAtEndOfMediaItems = true causes a buffering delay between 100-300ms between each media item. It does not appear to matter whether I pre-prepare the media item or not, or whether the media is on disk or not. Setting bufferForPlaybackMs in load control to 0 does not mitigate this. Essentially seamless/gapless playback is unavailable no matter how "fast" I am at attempting to listen to the media item end event, and resuming playback: there is always a slight but noticeable stutter during playback.
If I set pauseAtEndOfMediaItems = false the delay between each video is gone as expected.
Observing the logs I can see that some form of buffering/decoding is occuring. I thought that perhaps this was a first playthrough issue, and that seeking back to the start of playlist after a full playlist playthrough would remove these delays, but this is not the case.
I would like to know if there's any behaviour or steps I can take to restore gapless playback while still keeping pauseAtEndOfMediaItems = true. I realise this request is unusual - for our use case, the client code will make a determination during the currently playing video whether it wants to append another video to the playlist, and whether it wants that video to immediately start playing without any gaps.
Thank you for your assistance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.