From 2f7bf54076aac614f33dff252b36f0cf280dc2aa Mon Sep 17 00:00:00 2001 From: maxthiel Date: Thu, 10 Dec 2020 21:17:41 +0000 Subject: [PATCH] Add a preload event to warn about new track coming soon --- playback/src/player.rs | 7 ++++++- src/player_event_handler.rs | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/playback/src/player.rs b/playback/src/player.rs index 404493f5..125184a0 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -101,6 +101,10 @@ pub enum PlayerEvent { track_id: SpotifyId, position_ms: u32, }, + // The player is preloading a track. + Preloading { + track_id: SpotifyId, + }, // The player is playing a track. // This event is issued at the start of playback of whenever the position must be communicated // because it is out of sync. This includes: @@ -173,7 +177,7 @@ impl PlayerEvent { | Stopped { play_request_id, .. } => Some(*play_request_id), - Changed { .. } | VolumeSet { .. } => None, + Changed { .. } | Preloading { .. } | VolumeSet { .. } => None, } } } @@ -799,6 +803,7 @@ impl Future for PlayerInternal { { match loader.poll() { Ok(Async::Ready(loaded_track)) => { + self.send_event(PlayerEvent::Preloading { track_id }); self.preload = PlayerPreload::Ready { track_id, loaded_track, diff --git a/src/player_event_handler.rs b/src/player_event_handler.rs index 00b6c09f..4ce66c5e 100644 --- a/src/player_event_handler.rs +++ b/src/player_event_handler.rs @@ -58,6 +58,10 @@ pub fn run_program_on_events(event: PlayerEvent, onevent: &str) -> Option { + env_vars.insert("PLAYER_EVENT", "preloading".to_string()); + env_vars.insert("TRACK_ID", track_id.to_base62()); + } PlayerEvent::VolumeSet { volume } => { env_vars.insert("PLAYER_EVENT", "volume_set".to_string()); env_vars.insert("VOLUME", volume.to_string());