From 9137a9797a77690f6462d5beb23ffbe4f2ccb4a8 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 1 Mar 2025 00:55:52 +0100 Subject: [PATCH] Chore: require minimum amount of buffer before stream starts --- music_assistant/helpers/audio.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index 68d2c9d4..4e96c83c 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -144,8 +144,16 @@ class StreamCache: await self._fetch_task return # wait until the file is created - while not await asyncio.to_thread(os.path.exists, self._temp_path): + req_filesize = get_chunksize(self.streamdetails.audio_format, 30) + while True: await asyncio.sleep(0.2) + if not await asyncio.to_thread(os.path.exists, self._temp_path): + continue + if self._fetch_task is not None and not self._fetch_task.done(): + break + file_stats = await asyncio.to_thread(os.stat, self._temp_path) + if file_stats.st_size > req_filesize: + break async def _create_cache_file(self) -> None: time_start = time.time() -- 2.34.1