From 05d2960aabfd2219af7708f16fc1b052d5ab3235 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 14 Jul 2022 01:57:36 +0200 Subject: [PATCH] Adjust buffer for youtube music (#412) * Decrease the buffer a bit to better support Youtube Music which throttles the music stream so we can't buffer too far ahead * allow more buffer for next tracks --- music_assistant/controllers/streams.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/music_assistant/controllers/streams.py b/music_assistant/controllers/streams.py index 98073956b..77fd25838 100644 --- a/music_assistant/controllers/streams.py +++ b/music_assistant/controllers/streams.py @@ -629,7 +629,7 @@ async def _get_queue_stream( crossfade_duration = self.queue.settings.crossfade_duration crossfade_size = sample_size_per_second * crossfade_duration # buffer_duration has some overhead to account for padded silence - buffer_duration = (crossfade_duration or 2) * 2 + buffer_duration = (crossfade_duration or 2) * 2 if track_count > 1 else 1 # predict total size to expect for this track from duration stream_duration = (queue_track.duration or 0) - seek_position @@ -672,7 +672,13 @@ async def _get_queue_stream( if ( streamdetails.media_type == MediaType.ANNOUNCEMENT or not stream_duration + or stream_duration < buffer_duration ): + # handle edge case where we have a previous chunk in buffer + # and the next track is too short + if last_fadeout_part: + yield last_fadeout_part + last_fadeout_part = b"" yield chunk bytes_written += len(chunk) continue