(Re)store currently playing track + shuffle state

Solves #448
This commit is contained in:
Henrik Friedrichsen
2021-04-09 19:10:34 +02:00
parent d0db141c2d
commit cea5228245
5 changed files with 61 additions and 25 deletions

View File

@@ -18,7 +18,7 @@ use std::pin::Pin;
use std::time::Duration;
pub(crate) enum WorkerCommand {
Load(Playable),
Load(Playable, bool, u32),
Play,
Pause,
Stop,
@@ -90,21 +90,23 @@ impl futures::Future for Worker {
progress = true;
debug!("message received!");
match cmd {
WorkerCommand::Load(playable) => match SpotifyId::from_uri(&playable.uri()) {
Ok(id) => {
info!("player loading track: {:?}", id);
if id.audio_type == SpotifyAudioType::NonPlayable {
warn!("track is not playable");
WorkerCommand::Load(playable, start_playing, position_ms) => {
match SpotifyId::from_uri(&playable.uri()) {
Ok(id) => {
info!("player loading track: {:?}", id);
if id.audio_type == SpotifyAudioType::NonPlayable {
warn!("track is not playable");
self.events.send(Event::Player(PlayerEvent::FinishedTrack));
} else {
self.player.load(id, start_playing, position_ms);
}
}
Err(e) => {
error!("error parsing uri: {:?}", e);
self.events.send(Event::Player(PlayerEvent::FinishedTrack));
} else {
self.player.load(id, true, 0);
}
}
Err(e) => {
error!("error parsing uri: {:?}", e);
self.events.send(Event::Player(PlayerEvent::FinishedTrack));
}
},
}
WorkerCommand::Play => {
self.player.play();
}