INNER CODE UNIT · Rust
new_session
aome510/spotify-player · spotify_player/src/client/mod.rs:256
pub async fn new_session(&self, state: Option<&SharedState>, reauth: bool) -> Result<()> {
// Capture whether playback was active *before* tearing down any existing streaming
// connection. Shutting down the old `librespot` spirc pauses playback Spotify-side
// (and a broken session leaves it paused too), so we use this to resume on the new
// device rather than reconnecting in a paused state.
let was_playing = state.is_some_and(|state| {
state
.player
.read()
.buffered_playback
.as_ref()
.is_some_and(|p| p.is_playing)
});
let session = self.auth_config.session();
let creds = auth::get_creds(&self.auth_config, reauth, true).context("get credentials")?;
self.spotify.set_session(session.clone()).await;