Skip to content

Commit

Permalink
Force update currentTime after seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
tvanlaerhoven committed Oct 3, 2024
1 parent 9bd6159 commit 8694a36
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PlaybackStateProvider(private val connector: MediaSessionConnector) {
addEventListener(PlayerEventTypes.ERROR, onError)
addEventListener(PlayerEventTypes.WAITING, onWaiting)
addEventListener(PlayerEventTypes.ENDED, onEnded)
addEventListener(PlayerEventTypes.SEEKED, onSeeked)
addEventListener(PlayerEventTypes.DURATIONCHANGE, onDurationChange)
}
}
Expand All @@ -67,6 +68,7 @@ class PlaybackStateProvider(private val connector: MediaSessionConnector) {
removeEventListener(PlayerEventTypes.ERROR, onError)
removeEventListener(PlayerEventTypes.WAITING, onWaiting)
removeEventListener(PlayerEventTypes.ENDED, onEnded)
removeEventListener(PlayerEventTypes.SEEKED, onSeeked)
removeEventListener(PlayerEventTypes.DURATIONCHANGE, onDurationChange)
}
}
Expand Down Expand Up @@ -116,6 +118,14 @@ class PlaybackStateProvider(private val connector: MediaSessionConnector) {
updatePlaybackState(PlaybackStateCompat.STATE_PAUSED)
}

private val onSeeked = { _: SeekedEvent ->
// Some clients listening to the mediaSession, such as Notifications, do not update the
// currentTime until playbackState becomes PLAYING, so force it.
val oldPlaybackState = playbackState
updatePlaybackState(PlaybackStateCompat.STATE_PLAYING)
updatePlaybackState(oldPlaybackState)
}

private val onDurationChange = { _: DurationChangeEvent ->
connector.invalidateMediaSessionMetadata()
}
Expand Down

0 comments on commit 8694a36

Please sign in to comment.