From b63199743aef01868a67be451e6d46a288264235 Mon Sep 17 00:00:00 2001 From: ashthespy Date: Sat, 9 May 2020 13:59:28 +0200 Subject: [PATCH] Skip unplayable tracks instead of stopping --- playback/src/player.rs | 65 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/playback/src/player.rs b/playback/src/player.rs index a26d3583..0a6fd41f 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -378,6 +378,7 @@ impl PlayerState { } } + #[allow(dead_code)] fn is_stopped(&self) -> bool { use self::PlayerState::*; match *self { @@ -386,6 +387,14 @@ impl PlayerState { } } + fn is_loading(&self) -> bool { + use self::PlayerState::*; + match *self { + Loading { .. } => true, + _ => false, + } + } + fn decoder(&mut self) -> Option<&mut Decoder> { use self::PlayerState::*; match *self { @@ -728,8 +737,14 @@ impl Future for PlayerInternal { } Ok(Async::NotReady) => (), Err(_) => { - self.handle_player_stop(); - assert!(self.state.is_stopped()); + warn!("Unable to load <{:?}>", track_id); + warn!("Skipping to next track"); + trace!("State: {:?}", self.state); + assert!(self.state.is_loading()); + self.send_event(PlayerEvent::EndOfTrack { + track_id, + play_request_id, + }) } } } @@ -749,6 +764,7 @@ impl Future for PlayerInternal { } Ok(Async::NotReady) => (), Err(_) => { + warn!("Unable to preload {:?}", track_id); self.preload = PlayerPreload::None; } } @@ -1523,6 +1539,51 @@ impl ::std::fmt::Debug for PlayerCommand { } } +impl ::std::fmt::Debug for PlayerState { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + use PlayerState::*; + match *self { + Stopped => f.debug_struct("Stopped").finish(), + Loading { + track_id, + play_request_id, + .. + } => f + .debug_struct("Loading") + .field("track_id", &track_id) + .field("play_request_id", &play_request_id) + .finish(), + Paused { + track_id, + play_request_id, + .. + } => f + .debug_struct("Paused") + .field("track_id", &track_id) + .field("play_request_id", &play_request_id) + .finish(), + Playing { + track_id, + play_request_id, + .. + } => f + .debug_struct("Playing") + .field("track_id", &track_id) + .field("play_request_id", &play_request_id) + .finish(), + EndOfTrack { + track_id, + play_request_id, + .. + } => f + .debug_struct("EndOfTrack") + .field("track_id", &track_id) + .field("play_request_id", &play_request_id) + .finish(), + Invalid => f.debug_struct("Invalid").finish(), + } + } +} struct Subfile { stream: T, offset: u64,