mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Add a preload event to warn about new track coming soon
This commit is contained in:
parent
89cafd7c86
commit
2f7bf54076
2 changed files with 10 additions and 1 deletions
|
@ -101,6 +101,10 @@ pub enum PlayerEvent {
|
||||||
track_id: SpotifyId,
|
track_id: SpotifyId,
|
||||||
position_ms: u32,
|
position_ms: u32,
|
||||||
},
|
},
|
||||||
|
// The player is preloading a track.
|
||||||
|
Preloading {
|
||||||
|
track_id: SpotifyId,
|
||||||
|
},
|
||||||
// The player is playing a track.
|
// The player is playing a track.
|
||||||
// This event is issued at the start of playback of whenever the position must be communicated
|
// This event is issued at the start of playback of whenever the position must be communicated
|
||||||
// because it is out of sync. This includes:
|
// because it is out of sync. This includes:
|
||||||
|
@ -173,7 +177,7 @@ impl PlayerEvent {
|
||||||
| Stopped {
|
| Stopped {
|
||||||
play_request_id, ..
|
play_request_id, ..
|
||||||
} => Some(*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() {
|
match loader.poll() {
|
||||||
Ok(Async::Ready(loaded_track)) => {
|
Ok(Async::Ready(loaded_track)) => {
|
||||||
|
self.send_event(PlayerEvent::Preloading { track_id });
|
||||||
self.preload = PlayerPreload::Ready {
|
self.preload = PlayerPreload::Ready {
|
||||||
track_id,
|
track_id,
|
||||||
loaded_track,
|
loaded_track,
|
||||||
|
|
|
@ -58,6 +58,10 @@ pub fn run_program_on_events(event: PlayerEvent, onevent: &str) -> Option<io::Re
|
||||||
env_vars.insert("DURATION_MS", duration_ms.to_string());
|
env_vars.insert("DURATION_MS", duration_ms.to_string());
|
||||||
env_vars.insert("POSITION_MS", position_ms.to_string());
|
env_vars.insert("POSITION_MS", position_ms.to_string());
|
||||||
}
|
}
|
||||||
|
PlayerEvent::Preloading { track_id, .. } => {
|
||||||
|
env_vars.insert("PLAYER_EVENT", "preloading".to_string());
|
||||||
|
env_vars.insert("TRACK_ID", track_id.to_base62());
|
||||||
|
}
|
||||||
PlayerEvent::VolumeSet { volume } => {
|
PlayerEvent::VolumeSet { volume } => {
|
||||||
env_vars.insert("PLAYER_EVENT", "volume_set".to_string());
|
env_vars.insert("PLAYER_EVENT", "volume_set".to_string());
|
||||||
env_vars.insert("VOLUME", volume.to_string());
|
env_vars.insert("VOLUME", volume.to_string());
|
||||||
|
|
Loading…
Reference in a new issue