From e62fac3a0eab564d56b65aed3d0c9c113d173ce8 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 3 Jun 2026 23:48:52 -0400 Subject: [PATCH] fix(android): onEvents reads UPnP state so resume keeps duration --- .../minstrel/player/PlayerController.kt | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/player/PlayerController.kt b/android/app/src/main/java/com/fabledsword/minstrel/player/PlayerController.kt index 3db7a6e5..b8602717 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/player/PlayerController.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/player/PlayerController.kt @@ -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,