mirror of
https://github.com/talwat/lowfi
synced 2025-01-13 11:51:27 +00:00
fix: refine loading indicator
This commit is contained in:
parent
120ac3f972
commit
ddc572b405
@ -219,16 +219,28 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This will play the next track, as well as refilling the buffer in the background.
|
/// This will play the next track, as well as refilling the buffer in the background.
|
||||||
|
///
|
||||||
|
/// This will also set `current` to the newly loaded song.
|
||||||
pub async fn next(&self) -> eyre::Result<tracks::Decoded> {
|
pub async fn next(&self) -> eyre::Result<tracks::Decoded> {
|
||||||
let track = match self.tracks.write().await.pop_front() {
|
let track = match self.tracks.write().await.pop_front() {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
// If the queue is completely empty, then fallback to simply getting a new track.
|
// If the queue is completely empty, then fallback to simply getting a new track.
|
||||||
// This is relevant particularly at the first song.
|
// This is relevant particularly at the first song.
|
||||||
None => self.list.random(&self.client).await?,
|
None => {
|
||||||
|
// Serves as an indicator that the queue is "loading".
|
||||||
|
// We're doing it here so that we don't get the "loading" display
|
||||||
|
// for only a frame in the other case that the buffer is not empty.
|
||||||
|
self.current.store(None);
|
||||||
|
|
||||||
|
self.list.random(&self.client).await?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let decoded = track.decode()?;
|
let decoded = track.decode()?;
|
||||||
|
|
||||||
|
// Set the current track.
|
||||||
|
self.set_current(decoded.info.clone()).await?;
|
||||||
|
|
||||||
Ok(decoded)
|
Ok(decoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,9 +255,6 @@ impl Player {
|
|||||||
itx: Sender<()>,
|
itx: Sender<()>,
|
||||||
tx: Sender<Messages>,
|
tx: Sender<Messages>,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
// Serves as an indicator that the queue is "loading".
|
|
||||||
player.current.store(None);
|
|
||||||
|
|
||||||
// Stop the sink.
|
// Stop the sink.
|
||||||
player.sink.stop();
|
player.sink.stop();
|
||||||
|
|
||||||
@ -253,12 +262,7 @@ impl Player {
|
|||||||
|
|
||||||
match track {
|
match track {
|
||||||
Ok(track) => {
|
Ok(track) => {
|
||||||
// Set the current track.
|
// Start playing the new track.
|
||||||
player.set_current(track.info.clone()).await?;
|
|
||||||
|
|
||||||
// Actually start playing it, this is done later so that the amount
|
|
||||||
// or times where "loading" appears briefly even though the track is
|
|
||||||
// from the buffer is minimized.
|
|
||||||
player.sink.append(track.data);
|
player.sink.append(track.data);
|
||||||
|
|
||||||
// Notify the background downloader that there's an empty spot
|
// Notify the background downloader that there's an empty spot
|
||||||
|
@ -89,7 +89,7 @@ async fn interface(player: Arc<Player>, minimalist: bool) -> eyre::Result<()> {
|
|||||||
vec![action, middle, controls]
|
vec![action, middle, controls]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Formats the menu properly
|
// Formats the menu properly.
|
||||||
let menu: Vec<String> = menu
|
let menu: Vec<String> = menu
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| format!("│ {} │\r\n", x.reset()).to_string())
|
.map(|x| format!("│ {} │\r\n", x.reset()).to_string())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user