Skip to content

Commit

Permalink
Merge pull request #822 from Automattic/update/mediasession-duration
Browse files Browse the repository at this point in the history
Update the playing episode in the media session if the duration changes.
  • Loading branch information
mchowning authored Mar 8, 2023
2 parents 5595476 + 0c6006d commit cbc7784
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
([#817](https://github.com/Automattic/pocket-casts-android/pull/817)).
* Fixed Automotive Up Next podcast images not loading.
([#819](https://github.com/Automattic/pocket-casts-android/pull/819)).
* Fixed missing seek bar in the notification drawer and Android Automotive.
([#822](https://github.com/Automattic/pocket-casts-android/pull/822)).

7.34
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ class MediaSessionManager(
observePlaybackState()
observeCustomMediaActionsVisibility()
observeMediaNotificationControls()
playbackManager.upNextQueue.changesObservable
playbackManager.upNextQueue.getChangesObservableWithLiveCurrentEpisode(episodeManager, podcastManager)
// ignore the playing episode progress updates, but update when the media player read the duration from the file.
.distinctUntilChanged { stateOne, stateTwo ->
UpNextQueue.State.isEqualWithEpisodeCompare(stateOne, stateTwo) { episodeOne, episodeTwo ->
episodeOne.uuid == episodeTwo.uuid && episodeOne.duration == episodeTwo.duration
}
}
.observeOn(Schedulers.io())
.doOnNext { updateUpNext(it) }
.subscribeBy(onError = { Timber.e(it) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ interface UpNextQueue {
fun queueSize(): Int {
return if (this is Loaded) queue.size else 0
}

companion object {
fun isEqualWithEpisodeCompare(stateOne: State, stateTwo: State, isPlayingEpisodeEqual: (Playable, Playable) -> Boolean): Boolean {
return when {
stateOne is Empty && stateTwo is Empty -> true
stateOne is Loaded && stateTwo is Loaded -> {
stateOne.queue.map { it.uuid } == stateTwo.queue.map { it.uuid } &&
isPlayingEpisodeEqual(stateOne.episode, stateTwo.episode)
}
else -> false
}
}
}
}

fun setup()
Expand Down

0 comments on commit cbc7784

Please sign in to comment.