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,