fix(android): onEvents reads UPnP state so resume keeps duration
android / Build + lint + test (push) Has been cancelled

This commit is contained in:
2026-06-03 23:48:52 -04:00
parent eae5dcad23
commit e62fac3a0e
@@ -429,15 +429,30 @@ class PlayerController @Inject constructor(
?.getString(MINSTREL_SOURCE_KEY)
val isUpnpLoading = activeUpnpHolder.target.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 =
PlayerUiState(
currentTrack = current,
queue = queueRefs,
queueIndex = idx,
isPlaying = player.isPlaying,
isBuffering = player.playbackState == Player.STATE_BUFFERING,
positionMs = player.currentPosition.coerceAtLeast(0),
durationMs = player.duration.coerceAtLeast(0),
isPlaying = if (upnpActive) remoteState.isPlaying else player.isPlaying,
isBuffering = !upnpActive &&
player.playbackState == Player.STATE_BUFFERING,
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),
playbackError = player.playerError?.message,
currentSource = source,