From: Marcel van der Veldt Date: Tue, 4 Nov 2025 18:48:59 +0000 (+0100) Subject: Prevent old streamdetails being reused when buffer still present X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=a5d696daaccc1ffba44390fe8b7596990cba6a25;p=music-assistant-server.git Prevent old streamdetails being reused when buffer still present --- diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index 1a339d81..4661b5ec 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -334,9 +334,10 @@ async def get_stream_details( raise MediaNotFoundError( f"Unable to retrieve streamdetails for {queue_item.name} ({queue_item.uri})" ) + buffer: AudioBuffer | None = None if queue_item.streamdetails and ( (utc() - queue_item.streamdetails.created_at).seconds < STREAMDETAILS_EXPIRATION - or queue_item.streamdetails.buffer + or ((buffer := queue_item.streamdetails.buffer) and buffer.is_valid(seek_position)) ): # already got a fresh/unused (or cached) streamdetails # we assume that the streamdetails are valid for max STREAMDETAILS_EXPIRATION seconds diff --git a/music_assistant/helpers/audio_buffer.py b/music_assistant/helpers/audio_buffer.py index 836cd1f3..ace103dd 100644 --- a/music_assistant/helpers/audio_buffer.py +++ b/music_assistant/helpers/audio_buffer.py @@ -86,7 +86,7 @@ class AudioBuffer: """Return number of seconds of audio currently available in the buffer.""" return len(self._chunks) - def is_valid(self, checksum: str, seek_position: int = 0) -> bool: + def is_valid(self, checksum: str | None = None, seek_position: int = 0) -> bool: """ Validate the buffer's checksum and check if seek position is available. @@ -100,7 +100,7 @@ class AudioBuffer: if self.cancelled: return False - if self.checksum != checksum: + if checksum is not None and self.checksum != checksum: return False # Check if buffer is close to inactivity timeout (within 30 seconds)