From 39bbbdc230d3599f9dcead817b21180205b69b3d Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 16 Feb 2026 21:36:07 -0600 Subject: [PATCH] fix(playback): reduce mpris desync and stale playback event lag refs #85 cx --- src-tauri/src/commands_v2.rs | 1 - src-tauri/src/lib.rs | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index 383ee8fd3..7b8786677 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -4191,7 +4191,6 @@ pub async fn v2_set_media_metadata( duration_secs, cover_url, ); - app_state.media_controls.set_playback_with_progress(true, 0); Ok(()) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4d60dce58..d72860ab8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -458,19 +458,6 @@ pub fn run() { ) }; - // Adaptive polling: - // - fast (250ms) when playing - improves seekbar/lyrics sync - // - slow (1000ms) when paused/stopped with a track loaded - // - very slow (5000ms) when no track is loaded (idle) - let sleep_duration = if is_playing { - std::time::Duration::from_millis(250) - } else if track_id == 0 { - std::time::Duration::from_millis(5000) - } else { - std::time::Duration::from_millis(1000) - }; - tokio::time::sleep(sleep_duration).await; - // Emit when: // 1) normal in-track state changes/position updates, or // 2) terminal transition to no-track (track_id becomes 0). @@ -524,6 +511,19 @@ pub fn run() { media_controls.set_playback_with_progress(is_playing, position); } } + + // Adaptive polling: + // - fast (250ms) when playing - improves seekbar/lyrics sync + // - slow (1000ms) when paused/stopped with a track loaded + // - very slow (5000ms) when no track is loaded (idle) + let sleep_duration = if is_playing { + std::time::Duration::from_millis(250) + } else if track_id == 0 { + std::time::Duration::from_millis(5000) + } else { + std::time::Duration::from_millis(1000) + }; + tokio::time::sleep(sleep_duration).await; } });