Chore: require minimum amount of buffer before stream starts
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 28 Feb 2025 23:55:52 +0000 (00:55 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 28 Feb 2025 23:55:52 +0000 (00:55 +0100)
music_assistant/helpers/audio.py

index 68d2c9d475ada8fadc4bc6299526d1ad82ddf51c..4e96c83cc775daa6975bd021c6ab3149a998f777 100644 (file)
@@ -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()