From 8bbaa942fe4a1b8e4fe56b69cf0d4719751e21f5 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 6 Mar 2025 19:16:20 +0100 Subject: [PATCH] Fix: extremely short audio clips are not working --- music_assistant/controllers/streams.py | 5 ++++- music_assistant/helpers/audio.py | 7 +++---- music_assistant/helpers/ffmpeg.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/music_assistant/controllers/streams.py b/music_assistant/controllers/streams.py index 411ed2a0..d3b37837 100644 --- a/music_assistant/controllers/streams.py +++ b/music_assistant/controllers/streams.py @@ -398,7 +398,10 @@ class StreamsController(CoreController): # some players do not like it when we dont return anything after an error # so we send some silence so they move on to the next track on their own (hopefully) async for chunk in get_silence(10, output_format): - await resp.write(chunk) + try: + await resp.write(chunk) + except (BrokenPipeError, ConnectionResetError, ConnectionError): + break return resp async def serve_queue_flow_stream(self, request: web.Request) -> web.Response: diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index 9630dbdc..a6aea760 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -691,10 +691,6 @@ async def get_media_stream( buffer = buffer[pcm_format.pcm_sample_size :] # end of audio/track reached - if bytes_sent == 0: - # edge case: no audio data was sent - raise AudioError("No audio was received") - logger.log(VERBOSE_LOG_LEVEL, "End of stream reached.") if strip_silence_end and buffer: # strip silence from end of audio @@ -710,6 +706,9 @@ async def get_media_stream( del buffer # wait until stderr also completed reading await ffmpeg_proc.wait_with_timeout(5) + if bytes_sent == 0: + # edge case: no audio data was sent + raise AudioError("No audio was received") finished = True except (Exception, GeneratorExit) as err: if isinstance(err, asyncio.CancelledError | GeneratorExit): diff --git a/music_assistant/helpers/ffmpeg.py b/music_assistant/helpers/ffmpeg.py index 204b36d5..bafa8e72 100644 --- a/music_assistant/helpers/ffmpeg.py +++ b/music_assistant/helpers/ffmpeg.py @@ -287,7 +287,7 @@ def get_ffmpeg_args( # noqa: PLR0915 "-f", output_format.content_type.value, ] - elif input_format == output_format and not extra_args: + elif input_format == output_format and not filter_params and not extra_args: # passthrough-mode (e.g. for creating the cache) if output_format.content_type in ( ContentType.MP4, -- 2.34.1