From acc2b39d322105380a78eb488ce5d2fa5285259c Mon Sep 17 00:00:00 2001 From: Felix Prillwitz Date: Sun, 22 Dec 2024 15:51:49 +0100 Subject: [PATCH] connect: fix incorrect playing and paused --- connect/src/spirc.rs | 6 +++--- connect/src/state.rs | 16 ++++++++++++++++ connect/src/state/restrictions.rs | 8 ++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index adc24d226..53a362c8e 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -1350,7 +1350,7 @@ impl SpircTask { } fn handle_next(&mut self, track_uri: Option) -> Result<(), Error> { - let continue_playing = self.connect_state.player().is_playing; + let continue_playing = self.connect_state.is_playing(); let current_uri = self.connect_state.current_track(|t| &t.uri); let mut has_next_track = @@ -1391,7 +1391,7 @@ impl SpircTask { self.connect_state.reset_playback_to_position(None)?; self.handle_stop() } - Some(_) => self.load_track(self.connect_state.player().is_playing, 0)?, + Some(_) => self.load_track(self.connect_state.is_playing(), 0)?, } } else { self.handle_seek(0); @@ -1515,7 +1515,7 @@ impl SpircTask { async fn notify(&mut self) -> Result<(), Error> { self.connect_state.set_status(&self.play_status); - if self.connect_state.player().is_playing { + if self.connect_state.is_playing() { self.connect_state .update_position_in_relation(self.now_ms()); } diff --git a/connect/src/state.rs b/connect/src/state.rs index 0d9e89b96..60691534b 100644 --- a/connect/src/state.rs +++ b/connect/src/state.rs @@ -233,6 +233,22 @@ impl ConnectState { self.request.is_active } + /// Returns the `is_playing` value as perceived by other connect devices + /// + /// see [ConnectState::set_status] + pub fn is_playing(&self) -> bool { + let player = self.player(); + player.is_playing && !player.is_paused + } + + /// Returns the `is_paused` state value as perceived by other connect devices + /// + /// see [ConnectState::set_status] + pub fn is_pause(&self) -> bool { + let player = self.player(); + player.is_playing && player.is_paused && player.is_buffering + } + pub fn set_volume(&mut self, volume: u32) { self.device_mut() .device_info diff --git a/connect/src/state/restrictions.rs b/connect/src/state/restrictions.rs index a0f269331..03495c680 100644 --- a/connect/src/state/restrictions.rs +++ b/connect/src/state/restrictions.rs @@ -17,14 +17,18 @@ impl ConnectState { const ENDLESS_CONTEXT: &str = "endless_context"; let prev_tracks_is_empty = self.prev_tracks().is_empty(); + + let is_paused = self.is_pause(); + let is_playing = self.is_playing(); + let player = self.player_mut(); if let Some(restrictions) = player.restrictions.as_mut() { - if player.is_playing { + if is_playing { restrictions.disallow_pausing_reasons.clear(); restrictions.disallow_resuming_reasons = vec!["not_paused".to_string()] } - if player.is_paused { + if is_paused { restrictions.disallow_resuming_reasons.clear(); restrictions.disallow_pausing_reasons = vec!["not_playing".to_string()] }