fixed bugs with playback when paused

This commit is contained in:
Mark 2023-08-24 17:07:04 +02:00
parent f625233a1b
commit 55590a1549

View File

@ -82,8 +82,6 @@ impl Player {
// db.playing, but no song in queue... // db.playing, but no song in queue...
db.apply_command(Command::Stop); db.apply_command(Command::Stop);
} }
} else if !db.playing && self.source.is_some() {
self.current_song_id = SongOpt::New(None);
} else if let Some((_source, notif)) = &mut self.source { } else if let Some((_source, notif)) = &mut self.source {
if let Ok(()) = notif.try_recv() { if let Ok(()) = notif.try_recv() {
// song has finished playing // song has finished playing
@ -121,21 +119,27 @@ impl Player {
Some(s) => s.to_str().unwrap_or(""), Some(s) => s.to_str().unwrap_or(""),
None => "", None => "",
}; };
if let Some(bytes) = song.cached_data_now(db) { if db.playing {
match Self::sound_from_bytes(ext, bytes) { if let Some(bytes) = song.cached_data_now(db) {
Ok(v) => { match Self::sound_from_bytes(ext, bytes) {
let (sound, notif) = v.pausable().with_async_completion_notifier(); Ok(v) => {
// add it let (sound, notif) =
let (sound, controller) = sound.controllable(); v.pausable().with_async_completion_notifier();
self.source = Some((controller, notif)); // add it
// and play it let (sound, controller) = sound.controllable();
self.manager.play(Box::new(sound)); self.source = Some((controller, notif));
} // and play it
Err(e) => { self.manager.play(Box::new(sound));
eprintln!("[player] Can't play, skipping! {e}"); }
db.apply_command(Command::NextSong); Err(e) => {
eprintln!("[player] Can't play, skipping! {e}");
db.apply_command(Command::NextSong);
}
} }
} }
} else {
self.source = None;
song.cache_data_start_thread(&db);
} }
} else { } else {
panic!("invalid song ID: current_song_id not found in DB!"); panic!("invalid song ID: current_song_id not found in DB!");