Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- [connect] Add method `add_to_queue` to `Spirc` to add a track to the queue

### Changed

- [core] Made `SpotifyId::to_base62`, `SpotifyId::to_base16`, `FileId::to_base16`, `SpotifyUri::to_id`, `SpotifyUri::to_uri` infallible (breaking)
Expand Down
20 changes: 20 additions & 0 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
connect::{Cluster, ClusterUpdate, LogoutCommand, SetVolumeCommand},
context::Context,
explicit_content_pubsub::UserAttributesUpdate,
player::ProvidedTrack,
playlist4_external::PlaylistModificationInfo,
social_connect_v2::SessionUpdate,
transfer_state::TransferState,
Expand Down Expand Up @@ -132,6 +133,7 @@ enum SpircCommand {
Activate,
Transfer(Option<TransferRequest>),
Load(LoadRequest),
AddToQueue(String),
}

const CONTEXT_FETCH_THRESHOLD: usize = 2;
Expand Down Expand Up @@ -388,6 +390,15 @@ impl Spirc {
Ok(self.commands.send(SpircCommand::Load(command))?)
}

/// Adds a track to the queue.
///
/// Does nothing if we are not the active device.
///
/// The `track_uri` should be a valid Spotify track URI (e.g., `spotify:track:...`).
pub fn add_to_queue(&self, track_uri: String) -> Result<(), Error> {
Comment thread
photovoltex marked this conversation as resolved.
Outdated
Ok(self.commands.send(SpircCommand::AddToQueue(track_uri))?)
}

/// Disconnects the current device and pauses the playback according the value.
///
/// Does nothing if we are not the active device.
Expand Down Expand Up @@ -679,6 +690,7 @@ impl SpircTask {
SpircCommand::SetPosition(position) => self.handle_seek(position),
SpircCommand::SetVolume(volume) => self.set_volume(volume),
SpircCommand::Load(command) => self.handle_load(command, None, None).await?,
SpircCommand::AddToQueue(track_uri) => self.handle_add_to_queue(track_uri),
};

self.notify().await
Expand Down Expand Up @@ -1545,6 +1557,14 @@ impl SpircTask {
self.connect_state.set_repeat_track(repeat);
}

fn handle_add_to_queue(&mut self, track_uri: String) {
let track = ProvidedTrack {
uri: track_uri,
..Default::default()
};
self.connect_state.add_to_queue(track, true);
}

fn handle_preload_next_track(&mut self) {
// Requests the player thread to preload the next track
match self.play_status {
Expand Down
Loading