Skip to content

Commit

Permalink
Add buffering UI notification, reduce log noise when buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
compenguy committed May 24, 2024
1 parent da390db commit b6f9ee2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub(crate) enum State {
Disconnected,
AddStation(String, String),
Tuned(String),
Buffering,
TrackCaching(Track),
TrackStarting(Track),
#[allow(dead_code)]
Expand Down
6 changes: 4 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl Model {
debug!("Track already started.");
} else {
debug!("No tracks started yet. Starting next track.");
info!(
debug!(
"playlist length: {} + {} pending",
self.playlist_len(),
self.pending_len()
Expand All @@ -657,7 +657,9 @@ impl Model {
self.notify_playing().await?;
self.notify_next().await?;
} else {
warn!("requested to start track, but no tracks are ready");
debug!("requested to start track, but no tracks are ready");
self.publish_state(State::Buffering)
.await?;
}
}
Ok(())
Expand Down
23 changes: 23 additions & 0 deletions src/term_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,28 @@ impl Terminal {
self.dirty |= true;
}

fn update_state_buffering(&mut self) {
self.active_track = None;
self.siv
.call_on_name("playing", |v: &mut Panel<LinearLayout>| {
trace!("Playing panel title: buffering");
v.set_title(format!("Buffering..."));
});
self.siv.call_on_name("title", |v: &mut TextView| {
debug!("No track, clearing title");
v.set_content(String::default());
});
self.siv.call_on_name("artist", |v: &mut TextView| {
debug!("No track, clearing artist");
v.set_content(String::default());
});
self.siv.call_on_name("album", |v: &mut TextView| {
debug!("No track, clearing album");
v.set_content(String::default());
});
self.dirty |= true;
}

fn update_volume(&mut self, volume: f32) {
trace!("Updating volume...");
self.siv.call_on_name("volume", |v: &mut SliderView| {
Expand Down Expand Up @@ -325,6 +347,7 @@ impl Terminal {
State::Volume(v) => self.update_volume(v),
State::Paused(elapsed) => self.update_playing(elapsed, true),
State::Stopped(r) => self.update_state_stopped(r),
State::Buffering => self.update_state_buffering(),
State::TrackCaching(_) => (),
State::Muted => (),
State::Unmuted => (),
Expand Down

0 comments on commit b6f9ee2

Please sign in to comment.