Suppress sending loading state to Spotify unless we actually need to load a track.

This commit is contained in:
Konstantin Seiler 2020-02-07 21:11:49 +11:00
parent 18d1181bf5
commit 3f111a9778

View file

@ -484,7 +484,7 @@ impl SpircTask {
SpircCommand::Play => { SpircCommand::Play => {
if active { if active {
self.handle_play(); self.handle_play();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypePlay).send(); CommandSender::new(self, MessageType::kMessageTypePlay).send();
} }
@ -492,7 +492,7 @@ impl SpircTask {
SpircCommand::PlayPause => { SpircCommand::PlayPause => {
if active { if active {
self.handle_play_pause(); self.handle_play_pause();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypePlayPause).send(); CommandSender::new(self, MessageType::kMessageTypePlayPause).send();
} }
@ -500,7 +500,7 @@ impl SpircTask {
SpircCommand::Pause => { SpircCommand::Pause => {
if active { if active {
self.handle_pause(); self.handle_pause();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypePause).send(); CommandSender::new(self, MessageType::kMessageTypePause).send();
} }
@ -508,7 +508,7 @@ impl SpircTask {
SpircCommand::Prev => { SpircCommand::Prev => {
if active { if active {
self.handle_prev(); self.handle_prev();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypePrev).send(); CommandSender::new(self, MessageType::kMessageTypePrev).send();
} }
@ -516,7 +516,7 @@ impl SpircTask {
SpircCommand::Next => { SpircCommand::Next => {
if active { if active {
self.handle_next(); self.handle_next();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypeNext).send(); CommandSender::new(self, MessageType::kMessageTypeNext).send();
} }
@ -524,7 +524,7 @@ impl SpircTask {
SpircCommand::VolumeUp => { SpircCommand::VolumeUp => {
if active { if active {
self.handle_volume_up(); self.handle_volume_up();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypeVolumeUp).send(); CommandSender::new(self, MessageType::kMessageTypeVolumeUp).send();
} }
@ -532,7 +532,7 @@ impl SpircTask {
SpircCommand::VolumeDown => { SpircCommand::VolumeDown => {
if active { if active {
self.handle_volume_down(); self.handle_volume_down();
self.notify(None); self.notify(None, true);
} else { } else {
CommandSender::new(self, MessageType::kMessageTypeVolumeDown).send(); CommandSender::new(self, MessageType::kMessageTypeVolumeDown).send();
} }
@ -554,7 +554,7 @@ impl SpircTask {
if Some(play_request_id) == self.play_request_id { if Some(play_request_id) == self.play_request_id {
match event { match event {
PlayerEvent::EndOfTrack { .. } => self.handle_end_of_track(), PlayerEvent::EndOfTrack { .. } => self.handle_end_of_track(),
PlayerEvent::Loading { .. } => (), PlayerEvent::Loading { .. } => self.notify(None, false),
PlayerEvent::Playing { position_ms, .. } => { PlayerEvent::Playing { position_ms, .. } => {
let new_nominal_start_time = self.now_ms() - position_ms as i64; let new_nominal_start_time = self.now_ms() - position_ms as i64;
match self.play_status { match self.play_status {
@ -565,14 +565,14 @@ impl SpircTask {
if (*nominal_start_time - new_nominal_start_time).abs() > 100 { if (*nominal_start_time - new_nominal_start_time).abs() > 100 {
*nominal_start_time = new_nominal_start_time; *nominal_start_time = new_nominal_start_time;
self.update_state_position(position_ms); self.update_state_position(position_ms);
self.notify(None); self.notify(None, true);
} }
} }
SpircPlayStatus::LoadingPlay { .. } SpircPlayStatus::LoadingPlay { .. }
| SpircPlayStatus::LoadingPause { .. } => { | SpircPlayStatus::LoadingPause { .. } => {
self.state.set_status(PlayStatus::kPlayStatusPlay); self.state.set_status(PlayStatus::kPlayStatusPlay);
self.update_state_position(position_ms); self.update_state_position(position_ms);
self.notify(None); self.notify(None, true);
self.play_status = SpircPlayStatus::Playing { self.play_status = SpircPlayStatus::Playing {
nominal_start_time: new_nominal_start_time, nominal_start_time: new_nominal_start_time,
preloading_of_next_track_triggered: false, preloading_of_next_track_triggered: false,
@ -594,14 +594,14 @@ impl SpircTask {
if *position_ms != new_position_ms { if *position_ms != new_position_ms {
*position_ms = new_position_ms; *position_ms = new_position_ms;
self.update_state_position(new_position_ms); self.update_state_position(new_position_ms);
self.notify(None); self.notify(None, true);
} }
} }
SpircPlayStatus::LoadingPlay { .. } SpircPlayStatus::LoadingPlay { .. }
| SpircPlayStatus::LoadingPause { .. } => { | SpircPlayStatus::LoadingPause { .. } => {
self.state.set_status(PlayStatus::kPlayStatusPause); self.state.set_status(PlayStatus::kPlayStatusPause);
self.update_state_position(new_position_ms); self.update_state_position(new_position_ms);
self.notify(None); self.notify(None, true);
self.play_status = SpircPlayStatus::Paused { self.play_status = SpircPlayStatus::Paused {
position_ms: new_position_ms, position_ms: new_position_ms,
preloading_of_next_track_triggered: false, preloading_of_next_track_triggered: false,
@ -617,7 +617,7 @@ impl SpircTask {
warn!("The player has stopped unexpentedly."); warn!("The player has stopped unexpentedly.");
self.state.set_status(PlayStatus::kPlayStatusStop); self.state.set_status(PlayStatus::kPlayStatusStop);
self.ensure_mixer_stopped(); self.ensure_mixer_stopped();
self.notify(None); self.notify(None, true);
self.play_status = SpircPlayStatus::Stopped; self.play_status = SpircPlayStatus::Stopped;
} }
}, },
@ -671,7 +671,7 @@ impl SpircTask {
match frame.get_typ() { match frame.get_typ() {
MessageType::kMessageTypeHello => { MessageType::kMessageTypeHello => {
self.notify(Some(frame.get_ident())); self.notify(Some(frame.get_ident()), true);
} }
MessageType::kMessageTypeLoad => { MessageType::kMessageTypeLoad => {
@ -695,47 +695,47 @@ impl SpircTask {
self.play_status = SpircPlayStatus::Stopped; self.play_status = SpircPlayStatus::Stopped;
} }
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypePlay => { MessageType::kMessageTypePlay => {
self.handle_play(); self.handle_play();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypePlayPause => { MessageType::kMessageTypePlayPause => {
self.handle_play_pause(); self.handle_play_pause();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypePause => { MessageType::kMessageTypePause => {
self.handle_pause(); self.handle_pause();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeNext => { MessageType::kMessageTypeNext => {
self.handle_next(); self.handle_next();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypePrev => { MessageType::kMessageTypePrev => {
self.handle_prev(); self.handle_prev();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeVolumeUp => { MessageType::kMessageTypeVolumeUp => {
self.handle_volume_up(); self.handle_volume_up();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeVolumeDown => { MessageType::kMessageTypeVolumeDown => {
self.handle_volume_down(); self.handle_volume_down();
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeRepeat => { MessageType::kMessageTypeRepeat => {
self.state.set_repeat(frame.get_state().get_repeat()); self.state.set_repeat(frame.get_state().get_repeat());
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeShuffle => { MessageType::kMessageTypeShuffle => {
@ -755,17 +755,17 @@ impl SpircTask {
let context = self.state.get_context_uri(); let context = self.state.get_context_uri();
debug!("{:?}", context); debug!("{:?}", context);
} }
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeSeek => { MessageType::kMessageTypeSeek => {
self.handle_seek(frame.get_position()); self.handle_seek(frame.get_position());
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeReplace => { MessageType::kMessageTypeReplace => {
self.update_tracks(&frame); self.update_tracks(&frame);
self.notify(None); self.notify(None, true);
if let SpircPlayStatus::Playing { if let SpircPlayStatus::Playing {
preloading_of_next_track_triggered, preloading_of_next_track_triggered,
@ -786,7 +786,7 @@ impl SpircTask {
MessageType::kMessageTypeVolume => { MessageType::kMessageTypeVolume => {
self.set_volume(frame.get_volume() as u16); self.set_volume(frame.get_volume() as u16);
self.notify(None); self.notify(None, true);
} }
MessageType::kMessageTypeNotify => { MessageType::kMessageTypeNotify => {
@ -1005,7 +1005,7 @@ impl SpircTask {
fn handle_end_of_track(&mut self) { fn handle_end_of_track(&mut self) {
self.handle_next(); self.handle_next();
self.notify(None); self.notify(None, true);
} }
fn position(&mut self) -> u32 { fn position(&mut self) -> u32 {
@ -1201,7 +1201,10 @@ impl SpircTask {
CommandSender::new(self, MessageType::kMessageTypeHello).send(); CommandSender::new(self, MessageType::kMessageTypeHello).send();
} }
fn notify(&mut self, recipient: Option<&str>) { fn notify(&mut self, recipient: Option<&str>, suppress_loading_status: bool) {
if suppress_loading_status && (self.state.get_status() == PlayStatus::kPlayStatusLoading) {
return;
};
let status_string = match self.state.get_status() { let status_string = match self.state.get_status() {
PlayStatus::kPlayStatusLoading => "kPlayStatusLoading", PlayStatus::kPlayStatusLoading => "kPlayStatusLoading",
PlayStatus::kPlayStatusPause => "kPlayStatusPause", PlayStatus::kPlayStatusPause => "kPlayStatusPause",