Skip to content

Commit

Permalink
Merge pull request #37 from THEOplayer/bugfix/mediasession/currenttim…
Browse files Browse the repository at this point in the history
…e_after_seeking

Force update currentTime after seeking
  • Loading branch information
tvanlaerhoven authored Oct 3, 2024
2 parents 8303ca7 + 8694a36 commit d1e963a
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 d1e963a

Please sign in to comment.