Skip to content

Commit

Permalink
- remember and restore previous playback state
Browse files Browse the repository at this point in the history
- add comments
  • Loading branch information
t-nil committed Sep 2, 2023
1 parent b5b6c97 commit fd02fe4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ impl MprisPlayer {
self.event.trigger();
}

#[dbus_interface(property)]
fn randomize(&self) {
/*#[dbus_interface(property)]
fn randomize(&self, _b: bool) {
self.queue.randomize();
self.event.trigger();
}
}*/

#[dbus_interface(property)]
fn volume(&self) -> f64 {
Expand Down
18 changes: 16 additions & 2 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,26 @@ impl Queue {
///
/// This deactivates `Shuffle`.
pub fn randomize(&self) {
let mut queue = self.queue.write().unwrap();
queue.shuffle(&mut thread_rng());
// stop playlist, because we completely invalidate any playing order
let previous_playback_state = self.cfg.state().playback_state.clone();
self.stop();

// deactivate `Shuffle` feature, because it usually wouldn't make sense to use both
if self.get_shuffle() == true {
self.set_shuffle(false);
}

// permutate the queue Vec
let mut queue = self.queue.write().unwrap();
queue.shuffle(&mut thread_rng());

// resetting playing position to start of queue doesn't seem necessary
// my guess is that stop() does that

// resume playback if we were playing before
if previous_playback_state == PlaybackState::Playing {
self.toggleplayback();
}
}

/// Handle events that are specific to the queue.
Expand Down

0 comments on commit fd02fe4

Please sign in to comment.