diff --git a/Cargo.lock b/Cargo.lock index f063dc0..cb2d155 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1167,9 +1167,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets", diff --git a/src/player/current.rs b/src/player/current.rs index 5e0e193..2850e2e 100644 --- a/src/player/current.rs +++ b/src/player/current.rs @@ -12,6 +12,7 @@ pub struct Metadata { pub cover: DynamicImage, pub size: u32, pub bytes_received: u32, + pub bytes_handled: u32, } impl Metadata { @@ -26,6 +27,7 @@ impl Metadata { cover: default_cover(), size: 0, bytes_received: 0, + bytes_handled: 0, } } diff --git a/src/player/mod.rs b/src/player/mod.rs index f5d1eee..b9ae20f 100644 --- a/src/player/mod.rs +++ b/src/player/mod.rs @@ -16,6 +16,8 @@ use crate::{ utils::Error, }; +pub const AUDIO_FILE_BUFFER: u32 = 5_000_000; // 5MB + pub enum PlayerEvent { AddSongList(Vec), UpdateCover(DynamicImage), diff --git a/src/player/player.rs b/src/player/player.rs index 07862c6..1f40985 100644 --- a/src/player/player.rs +++ b/src/player/player.rs @@ -9,7 +9,7 @@ use crate::{ utils::{default_cover, Error}, }; -use super::{errors::PlayerError, Player, PlayerEvent}; +use super::{errors::PlayerError, Player, PlayerEvent, AUDIO_FILE_BUFFER}; impl Player { pub fn begin(&mut self) -> Result<(), Error> { @@ -100,6 +100,14 @@ impl Player { } fn recv_chunk(&mut self, chunk: Vec) -> Result<(), Error> { + if self.tui_root.metadata.bytes_received - self.tui_root.metadata.bytes_handled + > AUDIO_FILE_BUFFER + { + // requeue the new chunk since we don't need it decoded just yet. Mostly for massive hr+ files + self.player_chan_in + .send(PlayerEvent::AddAudioChunk(chunk))?; + return Ok(()); + } self.tui_root.metadata.bytes_received += chunk.len() as u32; self.audio_chan.send(AudioEvent::DecodeChunk(chunk))?; if self.tui_root.metadata.bytes_pending() {