diff --git a/README.md b/README.md index 333513a..0b7a549 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.1 && git push --tags` builds, signs and uploads the bundle. +Then `git tag v0.4.2 && 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 b15ddde..1983bc3 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.1" + ?: "0.4.2" kotlin { androidTarget { 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 9cfe4b1..9f1e60d 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 @@ -1011,15 +1011,15 @@ class AppStore( fun setSleepAfterTrack() { val state = _state.value if (state.current == null) return - val remaining = (state.durationSeconds - state.positionSeconds) - .coerceAtLeast(0.0) - .let { kotlin.math.ceil(it).toLong() } - if (remaining <= 0) { + val remaining = (state.durationSeconds - state.positionSeconds).coerceAtLeast(0.0) + if (remaining <= 0.0) { player.pause() _state.update { it.copy(playing = false) } return } - setSleepCountdown(remaining, atTrackEnd = true) + // Stop slightly before the boundary so ExoPlayer cannot start the next + // item in the sub-second gap before the timer reaches the service. + setSleepCountdown((remaining - 0.5).toLong().coerceAtLeast(1L), atTrackEnd = true) } private fun setSleepCountdown(seconds: Long?, atTrackEnd: Boolean) { @@ -1543,15 +1543,9 @@ class AppStore( delay(500) return true } - // A prefetch may already have appended the next batch while ExoPlayer - // was finishing. Play it instead of requesting duplicates. - if (trackIndex + 1 < timelineSongs.size) { - report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) - suppressCompletion = true - player.playIndex(trackIndex + 1) - return true - } + // "Finish this track" must win over an already-prefetched next batch. if (_state.value.sleepAtTrackEnd) { + report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) sleepJob?.cancel() sleepJob = null player.scheduleSleepTimer(null) @@ -1565,8 +1559,15 @@ class AppStore( } return false } + // A prefetch may already have appended the next batch while ExoPlayer + // was finishing. Play it instead of requesting duplicates. + if (trackIndex + 1 < timelineSongs.size) { + report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) + suppressCompletion = true + player.playIndex(trackIndex + 1) + return true + } val session = _state.value.session - val current = timelineSongs.getOrNull(trackIndex) if (session == null) { report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) _state.update { it.copy(playing = false) } diff --git a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/MoodSettingsScreen.kt b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/MoodSettingsScreen.kt index 28b566d..5716f41 100644 --- a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/MoodSettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/MoodSettingsScreen.kt @@ -72,6 +72,7 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) { var hours by remember(mood.id) { mutableStateOf(mood.refreshHours.toString()) } var confirmDelete by remember { mutableStateOf(false) } val offline = mood.id in state.offlineMoods + val offlineDownloaded = detail.songs.count { it.song.id in state.downloads } LazyColumn( modifier = Modifier.fillMaxSize(), @@ -200,7 +201,12 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) { Text("Keep this mood offline", style = MaterialTheme.typography.bodyMedium) } Text( - "Downloads every song and keeps new additions in sync on Wi-Fi.", + if (offline) { + "$offlineDownloaded of ${detail.songs.size} downloaded · " + + "new songs sync on Wi-Fi" + } else { + "Downloads every song and keeps new additions in sync on Wi-Fi." + }, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, ) 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 c0b7e4f..a7ecb21 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.1 · $platformName", + "AudioManager 0.4.2 · $platformName", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, ) diff --git a/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt b/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt index 4907a24..db9a29b 100644 --- a/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt +++ b/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt @@ -480,6 +480,34 @@ class AppStoreTest { store.release() } + @Test + fun `finish this track does not start the prefetched next song`() = runTest { + val storage = MemoryStorage() + val cache = AppCache(storage) + cache.saveSession(SessionState("http://music", "token", User("alice", admin = false))) + cache.savePlayback( + PlaybackSnapshot( + current = song("a", duration = 180), + queue = listOf(song("b", duration = 180)), + ), + ) + val player = FakePlayer() + val store = store(storage, cache, player) + runCurrent() + store.togglePlayPause() + awaitState { store.state.value.playing } + + store.setSleepAfterTrack() + player.finish() + advanceTimeBy(600) + runCurrent() + + assertFalse(store.state.value.playing) + assertEquals("a", store.state.value.current?.id) + assertEquals(listOf("b"), store.state.value.queue.map { it.id }) + store.release() + } + @Test fun `logout clears the session and the mood cache`() = runTest { val storage = MemoryStorage() diff --git a/composeApp/src/desktopMain/kotlin/win/taptap/musicmanager/client/DesktopAudioPlayer.kt b/composeApp/src/desktopMain/kotlin/win/taptap/musicmanager/client/DesktopAudioPlayer.kt index f268960..d79b95f 100644 --- a/composeApp/src/desktopMain/kotlin/win/taptap/musicmanager/client/DesktopAudioPlayer.kt +++ b/composeApp/src/desktopMain/kotlin/win/taptap/musicmanager/client/DesktopAudioPlayer.kt @@ -85,7 +85,7 @@ class DesktopAudioPlayer : AudioPlayer { val track = tracks.getOrNull(index) ?: return this.index = index currentTrack = track - gain = track.gainDb?.let { 10.0.pow(it / 20.0).toFloat() }?.coerceIn(0f, 2f) ?: 1f + gain = track.gainDb?.let { 10.0.pow(it / 20.0).toFloat() }?.coerceIn(0f, 4f) ?: 1f start(track, startAtSeconds) }