Skip to content

Commit

Permalink
Fix: extremely short audio clips are not working
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Mar 6, 2025
1 parent db348f8 commit 8bbaa94
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion music_assistant/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ async def serve_queue_item_stream(self, request: web.Request) -> web.Response:
# 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:
Expand Down
7 changes: 3 additions & 4 deletions music_assistant/helpers/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/helpers/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bbaa94

Please sign in to comment.