From 9013b374c7eeffeb00537cb091557b863b19abe6 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Mon, 20 Jul 2026 17:45:47 +0600 Subject: [PATCH] feat: add current time management in AudioPlayer for improved playback control --- .../dev/krtirtho/spotube/core/audioplayer/AudioPlayer.jvm.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/core/audioplayer/AudioPlayer.jvm.kt b/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/core/audioplayer/AudioPlayer.jvm.kt index 990248de..e06ecda9 100644 --- a/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/core/audioplayer/AudioPlayer.jvm.kt +++ b/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/core/audioplayer/AudioPlayer.jvm.kt @@ -309,6 +309,7 @@ actual class AudioPlayer actual constructor(context: Any) : KoinComponent { val wasPlaying = _playerState.value == PlayerState.PLAYING val wasPaused = _playerState.value == PlayerState.PAUSED val currentItem = _currentMediaItem.value + val currentTimeMs = mediaPlayer.status().time().coerceAtLeast(0) val rebuilt = if (enabled) { if (currentItem != null) { @@ -331,7 +332,6 @@ actual class AudioPlayer actual constructor(context: Any) : KoinComponent { val nextIndex = when { currentItem == null -> if (currentPlaylist.isEmpty()) -1 else 0 - enabled -> 0 else -> currentPlaylist.indexOfFirst { it.url == currentItem.url } .takeIf { it >= 0 } ?: 0 } @@ -341,6 +341,9 @@ actual class AudioPlayer actual constructor(context: Any) : KoinComponent { if (nextIndex >= 0 && (wasPlaying || wasPaused)) { mediaListPlayer.controls().play(nextIndex) + if (currentTimeMs > 0) { + mediaPlayer.controls().setTime(currentTimeMs) + } if (wasPaused) { mediaListPlayer.controls().setPause(true) }