fix(android): onEvents reads UPnP state so resume keeps duration
android / Build + lint + test (push) Has been cancelled
android / Build + lint + test (push) Has been cancelled
This commit is contained in:
@@ -429,15 +429,30 @@ class PlayerController @Inject constructor(
|
|||||||
?.getString(MINSTREL_SOURCE_KEY)
|
?.getString(MINSTREL_SOURCE_KEY)
|
||||||
val isUpnpLoading = activeUpnpHolder.target.value != null &&
|
val isUpnpLoading = activeUpnpHolder.target.value != null &&
|
||||||
activeUpnpHolder.active.value == null
|
activeUpnpHolder.active.value == null
|
||||||
|
// When UPnP is active, the wrapped ExoPlayer is paused with
|
||||||
|
// no real audio loaded -- player.duration / isPlaying /
|
||||||
|
// currentPosition all reflect that. Read from remoteState
|
||||||
|
// instead so an onEvents fire (e.g. activity resume) doesn't
|
||||||
|
// clobber the UI with zeros.
|
||||||
|
val upnpActive = activeUpnpHolder.active.value != null
|
||||||
uiStateInternal.value =
|
uiStateInternal.value =
|
||||||
PlayerUiState(
|
PlayerUiState(
|
||||||
currentTrack = current,
|
currentTrack = current,
|
||||||
queue = queueRefs,
|
queue = queueRefs,
|
||||||
queueIndex = idx,
|
queueIndex = idx,
|
||||||
isPlaying = player.isPlaying,
|
isPlaying = if (upnpActive) remoteState.isPlaying else player.isPlaying,
|
||||||
isBuffering = player.playbackState == Player.STATE_BUFFERING,
|
isBuffering = !upnpActive &&
|
||||||
positionMs = player.currentPosition.coerceAtLeast(0),
|
player.playbackState == Player.STATE_BUFFERING,
|
||||||
durationMs = player.duration.coerceAtLeast(0),
|
positionMs = if (upnpActive) {
|
||||||
|
remoteState.positionMs
|
||||||
|
} else {
|
||||||
|
player.currentPosition
|
||||||
|
}.coerceAtLeast(0),
|
||||||
|
durationMs = if (upnpActive) {
|
||||||
|
remoteState.durationMs
|
||||||
|
} else {
|
||||||
|
player.duration
|
||||||
|
}.coerceAtLeast(0),
|
||||||
bufferedPositionMs = player.bufferedPosition.coerceAtLeast(0),
|
bufferedPositionMs = player.bufferedPosition.coerceAtLeast(0),
|
||||||
playbackError = player.playerError?.message,
|
playbackError = player.playerError?.message,
|
||||||
currentSource = source,
|
currentSource = source,
|
||||||
|
|||||||
Reference in New Issue
Block a user