Skip to content

Commit

Permalink
Adjust buffer for youtube music (#412)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marcelveldt authored Jul 13, 2022
1 parent 563f54a commit 05d2960
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion music_assistant/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 05d2960

Please sign in to comment.