Skip to content

Commit

Permalink
Fix restart tracker when reaching EoF
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Feb 27, 2024
1 parent 764d8e3 commit 1a410f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a410f5

Please sign in to comment.