fix(queue): tracks not ending sometimes

This commit is contained in:
2024-11-27 03:56:22 +01:00
parent c71d3128e2
commit 22e6fe31b3

View File

@@ -49,13 +49,16 @@ impl AudioPlayer {
tokio::spawn(async move {
loop {
if let Some(current_track) = current_track.lock().await.as_mut() {
if current_track.duration as u128 <= sink.lock().await.get_pos().as_millis()
let sink = sink.lock().await;
if sink.empty()
|| current_track.duration as u128 <= sink.get_pos().as_millis()
{
if let Err(_) = tx.send(queue.lock().await.pop_front()).await {
break;
}
}
}
tokio::time::sleep(Self::WATCH_SLEEP_TIME).await;
}
}),