From 8e737fae2e1f8fa69d40d2d13bb46d2c6340a3a4 Mon Sep 17 00:00:00 2001 From: TapTap Date: Thu, 19 Nov 2026 16:58:20 +0000 Subject: [PATCH] fix: mirror a live service timeline after the UI is recreated The media service can keep playing after the task is swiped. A new UI now adopts its queue, index and position instead of showing a stale paused state. Notification artwork also uses cached offline covers. Version 0.4.1. --- README.md | 2 +- composeApp/build.gradle.kts | 2 +- .../client/MediaControllerAudioPlayer.kt | 5 +++- .../client/playback/AudioPlayer.kt | 2 ++ .../musicmanager/client/store/AppStore.kt | 28 +++++++++++++++++++ .../musicmanager/client/ui/SettingsScreen.kt | 2 +- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb4aa56..333513a 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ Tagged builds (`v*`) publish to internal testing from CI. The Gitea secrets are: | `ANDROID_KEY_PASSWORD` | key password | | `PLAY_SERVICE_ACCOUNT_JSON` | contents of the service account JSON | -Then `git tag v0.4.0 && git push --tags` builds, signs and uploads the bundle. +Then `git tag v0.4.1 && git push --tags` builds, signs and uploads the bundle. Gradle Play Publisher asks Play for the next free `versionCode` (`ResolutionStrategy.AUTO`), so only the tag/version name needs to change. diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index b17bc66..b15ddde 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -41,7 +41,7 @@ val hasUploadKey = uploadKeyStore?.exists() == true && val appVersionCode = (System.getenv("VERSION_CODE") ?: localProperties.getProperty("VERSION_CODE") ?: "1").toInt() val appVersionName = System.getenv("VERSION_NAME") ?: localProperties.getProperty("VERSION_NAME") - ?: "0.4.0" + ?: "0.4.1" kotlin { androidTarget { diff --git a/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/MediaControllerAudioPlayer.kt b/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/MediaControllerAudioPlayer.kt index fa4541d..008be06 100644 --- a/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/MediaControllerAudioPlayer.kt +++ b/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/MediaControllerAudioPlayer.kt @@ -184,7 +184,10 @@ class MediaControllerAudioPlayer(context: Context) : AudioPlayer { Bundle().apply { putDouble(GAIN_DB_KEY, track.gainDb ?: 0.0) }, ) .apply { - if (!track.artworkUri.isNullOrBlank()) { + val bytes = track.artworkBytes + if (bytes != null && bytes.isNotEmpty()) { + setArtworkData(bytes, MediaMetadata.PICTURE_TYPE_FRONT_COVER) + } else if (!track.artworkUri.isNullOrBlank()) { setArtworkUri(Uri.parse(track.artworkUri)) } } diff --git a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/playback/AudioPlayer.kt b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/playback/AudioPlayer.kt index 5364dd1..97fec79 100644 --- a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/playback/AudioPlayer.kt +++ b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/playback/AudioPlayer.kt @@ -12,6 +12,8 @@ data class PlaybackTrack( val source: String, val local: Boolean, val artworkUri: String? = null, + /** Cached cover for offline playback; avoids a network fetch in the notification. */ + val artworkBytes: ByteArray? = null, /** Server-measured gain; null leaves the track untouched. */ val gainDb: Double? = null, ) diff --git a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt index 50fcb35..9cfe4b1 100644 --- a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt +++ b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt @@ -159,6 +159,33 @@ class AppStore( ) } + // The media service can outlive the UI (for example after the task + // is swiped). If it still owns a timeline, mirror it instead of + // showing the last persisted position as paused. + scope.launch { + repeat(20) { + kotlinx.coroutines.delay(250) + if (player.queueSize() > 0) { + if (timelineSongs.isNotEmpty()) { + playbackStarted = true + trackIndex = player.currentIndex().coerceIn(timelineSongs.indices) + applyTimelineState() + _state.update { + it.copy( + playing = player.isPlaying(), + positionSeconds = player.positionSeconds().coerceAtLeast(0.0), + durationSeconds = player.durationSeconds() + .takeIf { value -> value > 0 } + ?: it.durationSeconds, + ) + } + startPolling() + } + return@launch + } + } + } + if (session == null) return@launch api.restore(session.serverUrl, session.token) @@ -1368,6 +1395,7 @@ class AppStore( source = local ?: api.streamUrl(song.id), local = local != null, artworkUri = api.coverUrl(song.id), + artworkBytes = storage.artworkBytes(song.id), gainDb = if (_state.value.normalizationEnabled) song.gainDb else null, ) } diff --git a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/SettingsScreen.kt b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/SettingsScreen.kt index 7eb6513..c0b7e4f 100644 --- a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/SettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/SettingsScreen.kt @@ -193,7 +193,7 @@ fun SettingsScreen(state: AppState, store: AppStore) { Column(Modifier.padding(18.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) { Text("About", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold) Text( - "AudioManager 0.4.0 · $platformName", + "AudioManager 0.4.1 · $platformName", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, )