Skip to content

Commit

Permalink
add log for shuffle seed
Browse files Browse the repository at this point in the history
  • Loading branch information
photovoltex committed Jan 23, 2025
1 parent 581e4fb commit f57fdf9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion connect/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct ConnectState {
/// the context from which we play, is used to top up prev and next tracks
context: Option<StateContext>,
/// seed extracted in [ConnectState::handle_initial_transfer] and used in [ConnectState::finish_transfer]
transfer_shuffle_seed: Option<String>,
transfer_shuffle_seed: Option<u64>,

/// a context to keep track of the autoplay context
autoplay_context: Option<StateContext>,
Expand Down
25 changes: 16 additions & 9 deletions connect/src/state/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ impl ConnectState {
player.play_origin = session.play_origin.take().map(Into::into).into();
player.suppressions = session.suppressions.take().map(Into::into).into();

if let Some(mut ctx) = session.context.take() {
if let Some(seed) = ctx.get_shuffle_seed() {
let _ = shuffle_seed.insert(seed.clone());
}
// maybe at some point we can use the shuffle seed provided by spotify,
// but I doubt it, as spotify doesn't use true randomness but rather an algorithm
// based shuffle
trace!(
"shuffle_seed: <{:?}> (spotify), <{:?}> (own)",
session.shuffle_seed,
session.context.get_shuffle_seed()
);

shuffle_seed = session
.context
.get_shuffle_seed()
.and_then(|seed| seed.parse().ok());

if let Some(mut ctx) = session.context.take() {
player.restrictions = ctx.restrictions.take().map(Into::into).into();
for (key, value) in ctx.metadata {
player.context_metadata.insert(key, value);
Expand Down Expand Up @@ -150,13 +160,10 @@ impl ConnectState {
}

if self.shuffling_context() {
let previous_seed = self
.transfer_shuffle_seed
.take()
.and_then(|s| s.parse().ok());

self.set_current_track(current_index.unwrap_or_default())?;
self.set_shuffle(true);

let previous_seed = self.transfer_shuffle_seed.take();
self.shuffle(previous_seed)?;
} else {
self.reset_playback_to_position(current_index)?;
Expand Down

0 comments on commit f57fdf9

Please sign in to comment.