Update http_streamer.py
authormarcelveldt <marcelvanderveldt@MacBook-Silvia.local>
Sun, 13 Oct 2019 02:12:41 +0000 (04:12 +0200)
committermarcelveldt <marcelvanderveldt@MacBook-Silvia.local>
Sun, 13 Oct 2019 02:12:41 +0000 (04:12 +0200)
fix singe track

music_assistant/http_streamer.py

index 5d9b819a37d0f357d0bb7b98e1b3c09f5392b2f4..f28e24fc83cf5a78dc71cbcaad326c6478a70cda 100755 (executable)
@@ -75,12 +75,17 @@ class HTTPStreamer():
         try:
             audio_stream = self.__get_audio_stream(player, queue_item, cancelled)
             async for is_last_chunk, audio_chunk in audio_stream:
-                await buffer.put(audio_chunk)
+                asyncio.run_coroutine_threadsafe(
+                        buffer.put(audio_chunk), 
+                        self.mass.event_loop)
                 # wait for the queue to consume the data
                 # this prevents that the entire track is sitting in memory
-                # while buffer.qsize() > 1 and not cancelled.is_set():
-                #     await asyncio.sleep(1)
-            await buffer.put(b'') # EOF
+                while buffer.qsize() > 2 and not cancelled.is_set():
+                    await asyncio.sleep(1)
+            # indicate EOF if no more data
+            asyncio.run_coroutine_threadsafe(
+                    buffer.put(b''), 
+                    self.mass.event_loop)
         except (asyncio.CancelledError, asyncio.TimeoutError):
             cancelled.set()
             LOGGER.info("stream_track interrupted for %s" % queue_item.name)