Skip to content

Commit

Permalink
connect: set track position when shuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
photovoltex committed Dec 19, 2024
1 parent 1873e2c commit fbe1657
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,21 +1148,19 @@ impl SpircTask {

debug!("play track <{:?}>", cmd.playing_track);

let index = cmd.playing_track.map(|p| match p {
PlayingTrack::Index(i) => Ok(i as usize),
PlayingTrack::Uri(uri) => {
let ctx = self.connect_state.get_context(ContextType::Default)?;
ConnectState::find_index_in_context(ctx, |t| t.uri == uri)
}
PlayingTrack::Uid(uid) => {
let ctx = self.connect_state.get_context(ContextType::Default)?;
ConnectState::find_index_in_context(ctx, |t| t.uid == uid)
}
});

let index = match index {
Some(value) => Some(value?),
let index = match cmd.playing_track {
None => None,
Some(playing_track) => Some(match playing_track {
PlayingTrack::Index(i) => i as usize,
PlayingTrack::Uri(uri) => {
let ctx = self.connect_state.get_context(ContextType::Default)?;
ConnectState::find_index_in_context(ctx, |t| t.uri == uri)?
}
PlayingTrack::Uid(uid) => {
let ctx = self.connect_state.get_context(ContextType::Default)?;
ConnectState::find_index_in_context(ctx, |t| t.uid == uid)?
}
}),
};

debug!(
Expand All @@ -1175,7 +1173,9 @@ impl SpircTask {
self.connect_state.set_repeat_track(cmd.repeat_track);

if cmd.shuffle {
if index.is_none() {
if let Some(index) = index {
self.connect_state.set_current_track(index)?;
} else {
self.connect_state.set_current_track_random()?;
}

Expand Down

0 comments on commit fbe1657

Please sign in to comment.