Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [player] `preload` function changed from accepting a `SpotifyId` to accepting a `SpotifyUri` (breaking)
- [spclient] `get_radio_for_track` function changed from accepting a `SpotifyId` to accepting a `SpotifyUri` (breaking)

### Fixed

- [connect] Use the provided index or the first as fallback value to always play a track on loading

### Removed

Expand Down
28 changes: 23 additions & 5 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ impl SpircTask {
SpircCommand::RepeatTrack(repeat) => self.handle_repeat_track(repeat),
SpircCommand::SetPosition(position) => self.handle_seek(position),
SpircCommand::SetVolume(volume) => self.set_volume(volume),
SpircCommand::Load(command) => self.handle_load(command, None).await?,
SpircCommand::Load(command) => self.handle_load(command, None, None).await?,
};

self.notify().await
Expand Down Expand Up @@ -998,6 +998,13 @@ impl SpircTask {
.map(Into::into)
.map(LoadContextOptions::Options);

let fallback_index = play
.options
.skip_to
.as_ref()
.and_then(|s| s.track_index)
.map(|i| i as usize);

self.handle_load(
LoadRequest {
context,
Expand All @@ -1009,6 +1016,7 @@ impl SpircTask {
},
},
play.context.pages.pop(),
fallback_index,
)
.await?;

Expand Down Expand Up @@ -1217,6 +1225,7 @@ impl SpircTask {
&mut self,
cmd: LoadRequest,
page: Option<ContextPage>,
fallback_index: Option<usize>,
) -> Result<(), Error> {
self.connect_state
.reset_context(if let PlayContext::Uri(ref uri) = cmd.context {
Expand Down Expand Up @@ -1253,17 +1262,26 @@ impl SpircTask {
let index = match cmd_options.playing_track {
None => None,
Some(ref playing_track) => Some(match playing_track {
PlayingTrack::Index(i) => *i as usize,
PlayingTrack::Index(i) => Ok(*i as usize),
PlayingTrack::Uri(uri) => {
let ctx = self.connect_state.get_context(ContextType::Default)?;
ConnectState::find_index_in_context(ctx, |t| &t.uri == uri)?
ConnectState::find_index_in_context(ctx, |t| &t.uri == uri)
}
PlayingTrack::Uid(uid) => {
let ctx = self.connect_state.get_context(ContextType::Default)?;
ConnectState::find_index_in_context(ctx, |t| &t.uid == uid)?
ConnectState::find_index_in_context(ctx, |t| &t.uid == uid)
}
}),
};
}
.map(|i| {
i.unwrap_or_else(|why| {
warn!(
"Failed to resolve index by {:?}, using fallback index: {:?} (Error: {why})",
cmd_options.playing_track, fallback_index
);
fallback_index.unwrap_or_default()
})
});

if let Some(LoadContextOptions::Options(ref options)) = cmd_options.context_options {
debug!(
Expand Down
2 changes: 1 addition & 1 deletion discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fn launch_libmdns(
}
.map_err(|e| DiscoveryError::DnsSdError(Box::new(e)))?;

let svc = responder.register(&DNS_SD_SERVICE_NAME, &name, port, &TXT_RECORD);
let svc = responder.register(DNS_SD_SERVICE_NAME, &name, port, &TXT_RECORD);

let _ = shutdown_rx.blocking_recv();

Expand Down
Loading