From 8990d037b8787bbd1bdc82fc002788be2456121b Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 10 Apr 2025 13:35:30 +0200 Subject: [PATCH] Fix playing announcements on snapcast --- .../providers/snapcast/__init__.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/music_assistant/providers/snapcast/__init__.py b/music_assistant/providers/snapcast/__init__.py index a55fb304..6c57939d 100644 --- a/music_assistant/providers/snapcast/__init__.py +++ b/music_assistant/providers/snapcast/__init__.py @@ -460,31 +460,21 @@ class SnapCastProvider(PlayerProvider): async def cmd_stop(self, player_id: str) -> None: """Send STOP command to given player.""" player = self.mass.players.get(player_id, raise_unavailable=False) + + await self._get_snapgroup(player_id).set_stream("default") + await self._delete_current_snapstream(self._get_snapstream(player_id)) + if stream_task := self._stream_tasks.pop(player_id, None): if not stream_task.done(): stream_task.cancel() with suppress(asyncio.CancelledError): await stream_task - player.state = PlayerState.IDLE player.current_media = None player.active_source = None self._set_childs_state(player_id) self.mass.players.update(player_id) - # assign default/empty stream to the player - # this removed the player/group specific MA stream which was dynamically created - # and assigns the default stream to the player - # we do this delayed so we can reuse the stream if a new play command is issued - async def clear_stream(): - with suppress(KeyError): - await self._get_snapgroup(player_id).set_stream("default") - await self._delete_current_snapstream(self._get_snapstream(player_id)) - - self.mass.call_later( - 30, self.mass.create_task, clear_stream, task_id=f"snapcast_clear_stream_{player_id}" - ) - async def cmd_volume_mute(self, player_id: str, muted: bool) -> None: """Send MUTE command to given player.""" ma_player = self.mass.players.get(player_id, raise_unavailable=False) @@ -543,7 +533,7 @@ class SnapCastProvider(PlayerProvider): await stream_task # get stream or create new one - stream = await self._get_or_create_stream(player_id, media.queue_id) + stream = await self._get_or_create_stream(player_id, media.queue_id or player_id) snap_group = self._get_snapgroup(player_id) await snap_group.set_stream(stream.identifier) @@ -618,6 +608,7 @@ class SnapCastProvider(PlayerProvider): self.mass.players.update(player_id) self._set_childs_state(player_id) await ffmpeg_proc.wait() + self.logger.debug("Finished streaming to %s", stream_path) # we need to wait a bit for the stream status to become idle # to ensure that all snapclients have consumed the audio -- 2.34.1