Skip to content

Commit 289b4f9

Browse files
committed
Fix behavior after last track of an album/playlist
* When autoplay is disabled, then loop back to the first track instead of 10 tracks back. Continue or stop playing depending on the state of the repeat button. * When autoplay is enabled, then extend the playlist *after* the last track. #844 broke this such that the last track of an album or playlist was never played. Fixes: #434
1 parent 095536f commit 289b4f9

2 files changed

Lines changed: 16 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646

4747
### Fixed
4848
- [connect] Fix step size on volume up/down events
49+
- [connect] Fix looping back to the first track after the last track of an album or playlist
4950
- [playback] Incorrect `PlayerConfig::default().normalisation_threshold` caused distortion when using dynamic volume normalisation downstream
5051
- [playback] Fix `log` and `cubic` volume controls to be mute at zero volume
5152
- [playback] Fix `S24_3` format on big-endian systems

connect/src/spirc.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ struct SpircTaskConfig {
8484
autoplay: bool,
8585
}
8686

87-
const CONTEXT_TRACKS_HISTORY: usize = 10;
8887
const CONTEXT_FETCH_THRESHOLD: u32 = 5;
8988

9089
const VOLUME_STEPS: i64 = 64;
@@ -887,8 +886,8 @@ impl SpircTask {
887886
let tracks_len = self.state.get_track().len() as u32;
888887
debug!(
889888
"At track {:?} of {:?} <{:?}> update [{}]",
890-
new_index,
891-
self.state.get_track().len(),
889+
new_index + 1,
890+
tracks_len,
892891
self.state.get_context_uri(),
893892
tracks_len - new_index < CONTEXT_FETCH_THRESHOLD
894893
);
@@ -902,27 +901,25 @@ impl SpircTask {
902901
self.context_fut = self.resolve_station(&context_uri);
903902
self.update_tracks_from_context();
904903
}
905-
let last_track = new_index == tracks_len - 1;
906-
if self.config.autoplay && last_track {
907-
// Extend the playlist
908-
// Note: This doesn't seem to reflect in the UI
909-
// the additional tracks in the frame don't show up as with station view
910-
debug!("Extending playlist <{}>", context_uri);
911-
self.update_tracks_from_context();
912-
}
913904
if new_index >= tracks_len {
914-
new_index = 0; // Loop around back to start
915-
continue_playing = self.state.get_repeat();
905+
if self.config.autoplay {
906+
// Extend the playlist
907+
debug!("Extending playlist <{}>", context_uri);
908+
self.update_tracks_from_context();
909+
self.player.set_auto_normalise_as_album(false);
910+
} else {
911+
new_index = 0;
912+
continue_playing = self.state.get_repeat();
913+
debug!(
914+
"Looping around back to start, repeat is {}",
915+
continue_playing
916+
);
917+
}
916918
}
917919

918920
if tracks_len > 0 {
919921
self.state.set_playing_track_index(new_index);
920922
self.load_track(continue_playing, 0);
921-
if self.config.autoplay && last_track {
922-
// If we're now playing the last track of an album, then
923-
// switch to track normalisation mode for the autoplay to come.
924-
self.player.set_auto_normalise_as_album(false);
925-
}
926923
} else {
927924
info!("Not playing next track because there are no more tracks left in queue.");
928925
self.state.set_playing_track_index(0);
@@ -1054,21 +1051,9 @@ impl SpircTask {
10541051
let new_tracks = &context.tracks;
10551052
debug!("Adding {:?} tracks from context to frame", new_tracks.len());
10561053
let mut track_vec = self.state.take_track().into_vec();
1057-
if let Some(head) = track_vec.len().checked_sub(CONTEXT_TRACKS_HISTORY) {
1058-
track_vec.drain(0..head);
1059-
}
10601054
track_vec.extend_from_slice(new_tracks);
10611055
self.state
10621056
.set_track(protobuf::RepeatedField::from_vec(track_vec));
1063-
1064-
// Update playing index
1065-
if let Some(new_index) = self
1066-
.state
1067-
.get_playing_track_index()
1068-
.checked_sub(CONTEXT_TRACKS_HISTORY as u32)
1069-
{
1070-
self.state.set_playing_track_index(new_index);
1071-
}
10721057
} else {
10731058
warn!("No context to update from!");
10741059
}

0 commit comments

Comments
 (0)