Merge pull request #960 from JasonLG1979/fix-shuffle

Prevent shuffle crash
This commit is contained in:
Roderick van Domburg 2022-02-03 09:36:09 +01:00 committed by GitHub
commit c49415c3fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [core] Removed unsafe code (breaking) - [core] Removed unsafe code (breaking)
- [playback] Adhere to ReplayGain spec when calculating gain normalisation factor. - [playback] Adhere to ReplayGain spec when calculating gain normalisation factor.
- [playback] `alsa`: Use `--volume-range` overrides for softvol controls - [playback] `alsa`: Use `--volume-range` overrides for softvol controls
- [connect] Don't panic when activating shuffle without previous interaction.
### Removed ### Removed
- [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed. - [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed.

View file

@ -668,15 +668,15 @@ impl SpircTask {
self.state.set_shuffle(frame.get_state().get_shuffle()); self.state.set_shuffle(frame.get_state().get_shuffle());
if self.state.get_shuffle() { if self.state.get_shuffle() {
let current_index = self.state.get_playing_track_index(); let current_index = self.state.get_playing_track_index();
{
let tracks = self.state.mut_track(); let tracks = self.state.mut_track();
if !tracks.is_empty() {
tracks.swap(0, current_index as usize); tracks.swap(0, current_index as usize);
if let Some((_, rest)) = tracks.split_first_mut() { if let Some((_, rest)) = tracks.split_first_mut() {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
rest.shuffle(&mut rng); rest.shuffle(&mut rng);
} }
}
self.state.set_playing_track_index(0); self.state.set_playing_track_index(0);
}
} else { } else {
let context = self.state.get_context_uri(); let context = self.state.get_context_uri();
debug!("{:?}", context); debug!("{:?}", context);