Shuffle: Start with random track if not selecting track directly
Starting a playlist, album or artist with shuffle enabled always starts on the first track in it and then plays the rest of the queue shuffled. This changes it so unless a track is picked directly, playback will start on a random track of the selection.
This commit is contained in:
committed by
Henrik Friedrichsen
parent
f292b939b3
commit
363e71242a
@@ -177,7 +177,7 @@ impl ListItem for Album {
|
||||
if let Some(tracks) = self.tracks.as_ref() {
|
||||
let tracks: Vec<&Track> = tracks.iter().collect();
|
||||
let index = queue.append_next(tracks);
|
||||
queue.play(index, true);
|
||||
queue.play(index, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ impl ListItem for Artist {
|
||||
|
||||
if let Some(tracks) = self.tracks() {
|
||||
let index = queue.append_next(tracks);
|
||||
queue.play(index, true);
|
||||
queue.play(index, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ impl ListItem for Playlist {
|
||||
|
||||
if let Some(tracks) = self.tracks.as_ref() {
|
||||
let index = queue.append_next(tracks.iter().collect());
|
||||
queue.play(index, true);
|
||||
queue.play(index, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
src/queue.rs
17
src/queue.rs
@@ -140,7 +140,7 @@ impl Queue {
|
||||
let current = *self.current_track.read().unwrap();
|
||||
if let Some(current_track) = current {
|
||||
if index == current_track {
|
||||
self.play(index, false);
|
||||
self.play(index, false, false);
|
||||
} else if index < current_track {
|
||||
let mut current = self.current_track.write().unwrap();
|
||||
current.replace(current_track - 1);
|
||||
@@ -187,7 +187,12 @@ impl Queue {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play(&self, index: usize, reshuffle: bool) {
|
||||
pub fn play(&self, mut index: usize, reshuffle: bool, shuffle_index: bool) {
|
||||
if shuffle_index && self.get_shuffle() {
|
||||
let mut rng = rand::thread_rng();
|
||||
index = rng.gen_range(0, &self.queue.read().unwrap().len());
|
||||
}
|
||||
|
||||
if let Some(track) = &self.queue.read().unwrap().get(index) {
|
||||
self.spotify.load(&track);
|
||||
let mut current = self.current_track.write().unwrap();
|
||||
@@ -218,13 +223,13 @@ impl Queue {
|
||||
|
||||
if repeat == RepeatSetting::RepeatTrack && !manual {
|
||||
if let Some(index) = current {
|
||||
self.play(index, false);
|
||||
self.play(index, false, false);
|
||||
}
|
||||
} else if let Some(index) = self.next_index() {
|
||||
self.play(index, false);
|
||||
self.play(index, false, false);
|
||||
} else if repeat == RepeatSetting::RepeatPlaylist && q.len() > 0 {
|
||||
let random_order = self.random_order.read().unwrap();
|
||||
self.play(random_order.as_ref().map(|o| o[0]).unwrap_or(0), false);
|
||||
self.play(random_order.as_ref().map(|o| o[0]).unwrap_or(0), false, false);
|
||||
} else {
|
||||
self.spotify.stop();
|
||||
}
|
||||
@@ -232,7 +237,7 @@ impl Queue {
|
||||
|
||||
pub fn previous(&self) {
|
||||
if let Some(index) = self.previous_index() {
|
||||
self.play(index, false);
|
||||
self.play(index, false, false);
|
||||
} else {
|
||||
self.spotify.stop();
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ impl ListItem for Track {
|
||||
|
||||
fn play(&mut self, queue: Arc<Queue>) {
|
||||
let index = queue.append_next(vec![self]);
|
||||
queue.play(index, true);
|
||||
queue.play(index, true, false);
|
||||
}
|
||||
|
||||
fn queue(&mut self, queue: Arc<Queue>) {
|
||||
|
||||
@@ -148,7 +148,7 @@ impl<I: ListItem> ListView<I> {
|
||||
if let Some(tracks) = any.downcast_ref::<Vec<Track>>() {
|
||||
let tracks: Vec<&Track> = tracks.iter().collect();
|
||||
let index = self.queue.append_next(tracks);
|
||||
self.queue.play(index + self.selected, true);
|
||||
self.queue.play(index + self.selected, true, false);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
@@ -92,7 +92,7 @@ impl ViewExt for QueueView {
|
||||
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
|
||||
match cmd {
|
||||
Command::Play => {
|
||||
self.queue.play(self.list.get_selected_index(), true);
|
||||
self.queue.play(self.list.get_selected_index(), true, false);
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
}
|
||||
Command::Queue => {
|
||||
|
||||
Reference in New Issue
Block a user