From: Marcel van der Veldt Date: Fri, 28 Feb 2025 23:55:52 +0000 (+0100) Subject: Chore: require minimum amount of buffer before stream starts X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=9137a9797a77690f6462d5beb23ffbe4f2ccb4a8;p=music-assistant-server.git Chore: require minimum amount of buffer before stream starts --- 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()