diff --git a/src/mpris.rs b/src/mpris.rs index 3dbdd9ee1..afa2b4701 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -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 { diff --git a/src/queue.rs b/src/queue.rs index e7af001b2..f21a9e0a0 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -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.