Skip to content

Commit

Permalink
Ensure new track plays from start after replacement
Browse files Browse the repository at this point in the history
Added a seek operation to reset the playback position when replacing a track in ExoPlayer. Previously, after replacing a track while in Player.STATE_ENDED, the player would maintain its position at the end of the old track. By seeking to the start of the newly added track, we ensure that playback begins from the beginning of the new media item.
  • Loading branch information
puckey committed Oct 19, 2023
1 parent 1d1dd0e commit 26defc7
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class QueuedAudioPlayer(
get() = items.getOrNull(currentIndex - 1)

override fun load(item: AudioItem, playWhenReady: Boolean) {
exoPlayer.playWhenReady = playWhenReady
load(item)
exoPlayer.playWhenReady = playWhenReady
}

override fun load(item: AudioItem) {
Expand All @@ -75,6 +75,7 @@ class QueuedAudioPlayer(
queue[currentIndex] = mediaSource
exoPlayer.addMediaSource(currentIndex + 1, mediaSource)
exoPlayer.removeMediaItem(currentIndex)
exoPlayer.seekTo(currentIndex, C.TIME_UNSET);
exoPlayer.prepare()
}
}
Expand Down

0 comments on commit 26defc7

Please sign in to comment.