From 1a410f52c8a0a2680a2516f025ddb6f38c15e7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20St=C3=A4hli?= Date: Tue, 27 Feb 2024 14:42:09 +0100 Subject: [PATCH] Fix restart tracker when reaching EoF --- .../player/tracker/CurrentMediaItemTracker.kt | 1 + .../player/tracker/MediaItemTrackerTest.kt | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/CurrentMediaItemTracker.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/CurrentMediaItemTracker.kt index d2920c38a..5259e2257 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/CurrentMediaItemTracker.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/tracker/CurrentMediaItemTracker.kt @@ -134,6 +134,7 @@ internal class CurrentMediaItemTracker internal constructor( when (playbackState) { Player.STATE_ENDED -> stopSession(MediaItemTracker.StopReason.EoF) Player.STATE_IDLE -> stopSession(MediaItemTracker.StopReason.Stop) + Player.STATE_READY -> if (currentMediaItem == null) setMediaItem(player.currentMediaItem) else -> { // Nothing } diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/MediaItemTrackerTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/MediaItemTrackerTest.kt index 7d1bf3d78..d10681481 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/MediaItemTrackerTest.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/tracker/MediaItemTrackerTest.kt @@ -189,6 +189,35 @@ class MediaItemTrackerTest { confirmVerified(fakeMediaItemTracker) } + @Test + fun `one MediaItem with mediaId and url set reach eof then seek back`() { + val mediaId = FakeMediaItemSource.MEDIA_ID_1 + player.apply { + setMediaItem( + MediaItem.Builder() + .setMediaId(mediaId) + .setUri(FakeMediaItemSource.URL_MEDIA_1) + .build() + ) + prepare() + play() + } + + TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) + player.seekTo(FakeMediaItemSource.NEAR_END_POSITION_MS) + TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED) + player.seekBack() + TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) + TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(player) + + verifyOrder { + fakeMediaItemTracker.start(any(), FakeMediaItemTracker.Data(mediaId)) + fakeMediaItemTracker.stop(any(), MediaItemTracker.StopReason.EoF, player.duration) + fakeMediaItemTracker.start(any(), FakeMediaItemTracker.Data(mediaId)) + } + confirmVerified(fakeMediaItemTracker) + } + @Test fun `one MediaItem with mediaId and url set reach stop`() { val mediaId = FakeMediaItemSource.MEDIA_ID_1