mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-03 17:59:24 +02:00
fix: uses the index as fallback value
This commit is contained in:
parent
eb7c65e77b
commit
3dee97321b
1 changed files with 23 additions and 5 deletions
|
@ -651,7 +651,7 @@ impl SpircTask {
|
||||||
SpircCommand::RepeatTrack(repeat) => self.handle_repeat_track(repeat),
|
SpircCommand::RepeatTrack(repeat) => self.handle_repeat_track(repeat),
|
||||||
SpircCommand::SetPosition(position) => self.handle_seek(position),
|
SpircCommand::SetPosition(position) => self.handle_seek(position),
|
||||||
SpircCommand::SetVolume(volume) => self.set_volume(volume),
|
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
|
self.notify().await
|
||||||
|
@ -998,6 +998,13 @@ impl SpircTask {
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.map(LoadContextOptions::Options);
|
.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(
|
self.handle_load(
|
||||||
LoadRequest {
|
LoadRequest {
|
||||||
context,
|
context,
|
||||||
|
@ -1009,6 +1016,7 @@ impl SpircTask {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
play.context.pages.pop(),
|
play.context.pages.pop(),
|
||||||
|
fallback_index,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -1217,6 +1225,7 @@ impl SpircTask {
|
||||||
&mut self,
|
&mut self,
|
||||||
cmd: LoadRequest,
|
cmd: LoadRequest,
|
||||||
page: Option<ContextPage>,
|
page: Option<ContextPage>,
|
||||||
|
fallback_index: Option<usize>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.connect_state
|
self.connect_state
|
||||||
.reset_context(if let PlayContext::Uri(ref uri) = cmd.context {
|
.reset_context(if let PlayContext::Uri(ref uri) = cmd.context {
|
||||||
|
@ -1253,17 +1262,26 @@ impl SpircTask {
|
||||||
let index = match cmd_options.playing_track {
|
let index = match cmd_options.playing_track {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref playing_track) => Some(match playing_track {
|
Some(ref playing_track) => Some(match playing_track {
|
||||||
PlayingTrack::Index(i) => *i as usize,
|
PlayingTrack::Index(i) => Ok(*i as usize),
|
||||||
PlayingTrack::Uri(uri) => {
|
PlayingTrack::Uri(uri) => {
|
||||||
let ctx = self.connect_state.get_context(ContextType::Default)?;
|
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) => {
|
PlayingTrack::Uid(uid) => {
|
||||||
let ctx = self.connect_state.get_context(ContextType::Default)?;
|
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 {
|
if let Some(LoadContextOptions::Options(ref options)) = cmd_options.context_options {
|
||||||
debug!(
|
debug!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue