Skip to content

Commit

Permalink
connect: fix incorrect playing and paused
Browse files Browse the repository at this point in the history
  • Loading branch information
photovoltex committed Dec 23, 2024
1 parent eb14e46 commit acc2b39
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ impl SpircTask {
}

fn handle_next(&mut self, track_uri: Option<String>) -> 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 =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down
16 changes: 16 additions & 0 deletions connect/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions connect/src/state/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
}
Expand Down

0 comments on commit acc2b39

Please sign in to comment.