mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-05 02:39:53 +02:00
Adjust: Allow repeat in combination with shuffle (#1561)
* fix: incorrect autoplay resolver behavior when shuffling * refactor: store the initial track in the remote context * adjust: shuffle repeat interaction * chore: update .gitignore * chore: rename internal error * adjust: shuffle behavior to ensure consistency * fix: prefer repeat context over autoplay * chore: update changelog * chore: reduce complexity of shuffle * chore: test shuffle with first
This commit is contained in:
parent
882ed7cf4f
commit
eff5ca3294
13 changed files with 193 additions and 65 deletions
|
@ -24,7 +24,6 @@ const SEARCH_IDENTIFIER: &str = "spotify:search";
|
|||
#[derive(Debug)]
|
||||
pub struct StateContext {
|
||||
pub tracks: ShuffleVec<ProvidedTrack>,
|
||||
pub skip_track: Option<ProvidedTrack>,
|
||||
pub metadata: HashMap<String, String>,
|
||||
pub restrictions: Option<Restrictions>,
|
||||
/// is used to keep track which tracks are already loaded into the next_tracks
|
||||
|
@ -108,6 +107,7 @@ impl ConnectState {
|
|||
|
||||
if let Ok(ctx) = self.get_context_mut(ContextType::Default) {
|
||||
ctx.remove_shuffle_seed();
|
||||
ctx.remove_initial_track();
|
||||
ctx.tracks.unshuffle()
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ impl ConnectState {
|
|||
error!("context didn't have any tracks: {context:#?}");
|
||||
Err(StateError::ContextHasNoTracks)?;
|
||||
} else if matches!(context.uri, Some(ref uri) if uri.starts_with(LOCAL_FILES_IDENTIFIER)) {
|
||||
Err(StateError::UnsupportedLocalPlayBack)?;
|
||||
Err(StateError::UnsupportedLocalPlayback)?;
|
||||
}
|
||||
|
||||
let mut next_contexts = Vec::new();
|
||||
|
@ -377,18 +377,23 @@ impl ConnectState {
|
|||
|
||||
StateContext {
|
||||
tracks: tracks.into(),
|
||||
skip_track: None,
|
||||
restrictions,
|
||||
metadata,
|
||||
index: ContextIndex::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_skip_track(&self, track: &ProvidedTrack) -> bool {
|
||||
self.get_context(self.active_context)
|
||||
.ok()
|
||||
.and_then(|t| t.skip_track.as_ref().map(|t| t.uri == track.uri))
|
||||
.unwrap_or(false)
|
||||
pub fn is_skip_track(&self, track: &ProvidedTrack, iteration: Option<u32>) -> bool {
|
||||
let ctx = match self.get_context(self.active_context).ok() {
|
||||
None => return false,
|
||||
Some(ctx) => ctx,
|
||||
};
|
||||
|
||||
if ctx.get_initial_track().is_none_or(|uri| uri != &track.uri) {
|
||||
return false;
|
||||
}
|
||||
|
||||
iteration.is_none_or(|i| i == 0)
|
||||
}
|
||||
|
||||
pub fn merge_context(&mut self, new_page: Option<ContextPage>) -> Option<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue