mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Support for enabling shuffle.
This commit is contained in:
parent
5581289351
commit
628df27292
1 changed files with 23 additions and 0 deletions
23
src/spirc.rs
23
src/spirc.rs
|
@ -17,6 +17,9 @@ use protocol::spirc::{PlayStatus, State, MessageType, Frame, DeviceState};
|
|||
use mixer::Mixer;
|
||||
use player::Player;
|
||||
|
||||
use rand;
|
||||
use rand::Rng;
|
||||
|
||||
pub struct SpircTask {
|
||||
player: Player,
|
||||
mixer: Box<Mixer>,
|
||||
|
@ -401,6 +404,26 @@ impl SpircTask {
|
|||
self.notify(None);
|
||||
}
|
||||
|
||||
MessageType::kMessageTypeShuffle => {
|
||||
self.state.set_shuffle(frame.get_state().get_shuffle());
|
||||
if self.state.get_shuffle()
|
||||
{
|
||||
let current_index = self.state.get_playing_track_index();
|
||||
{
|
||||
let tracks = self.state.mut_track();
|
||||
tracks.swap(0, current_index as usize);
|
||||
if let Some((_, rest)) = tracks.split_first_mut() {
|
||||
rand::thread_rng().shuffle(rest);
|
||||
}
|
||||
}
|
||||
self.state.set_playing_track_index(0);
|
||||
} else {
|
||||
let context = self.state.get_context_uri();
|
||||
debug!("{:?}", context);
|
||||
}
|
||||
self.notify(None);
|
||||
}
|
||||
|
||||
MessageType::kMessageTypeSeek => {
|
||||
let position = frame.get_position();
|
||||
|
||||
|
|
Loading…
Reference in a new issue