From 55e3f04e2c4fb48044d900bb76207234b4b05d62 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 11 Dec 2025 16:20:14 +0100 Subject: [PATCH] Fix auto-play next track during pause/unpause transitions When rapidly pressing play/pause, MPV briefly reports idle-active as true during state transitions. Combined with our player_state being set to Playing after unpause, this incorrectly triggered the auto-play next track logic. Fix: Add is_paused() check to auto-play condition to ensure we only advance to next track when the current track actually ends, not during pause state transitions. --- Cargo.toml | 2 +- src/main.rs | 3 ++- src/player/mod.rs | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c6cf477..8744bf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-player" -version = "0.1.21" +version = "0.1.22" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 74fe2f6..e59d125 100644 --- a/src/main.rs +++ b/src/main.rs @@ -304,7 +304,8 @@ async fn run_app( // Check if track ended and play next (but only if track was actually loaded AND played) // Require position > 0.5 to ensure track actually started playing (not just loaded) - if player.is_idle() && state.player_state == PlayerState::Playing && state.current_duration > 0.0 && state.current_position > 0.5 { + // Also check !is_paused to avoid triggering during pause/unpause transitions + if player.is_idle() && !player.is_paused() && state.player_state == PlayerState::Playing && state.current_duration > 0.0 && state.current_position > 0.5 { state.play_next(); // play_next() handles the play mode and may stop if in Normal mode at end if state.player_state == PlayerState::Playing { diff --git a/src/player/mod.rs b/src/player/mod.rs index c4ea300..84970e8 100644 --- a/src/player/mod.rs +++ b/src/player/mod.rs @@ -327,6 +327,10 @@ impl Player { self.is_idle } + pub fn is_paused(&self) -> bool { + self.is_paused + } + pub fn is_process_alive(&mut self) -> bool { // Check if mpv process is still running match self.process.try_wait() {