From: Kostas Chatzikokolakis Date: Sun, 27 Apr 2025 00:05:45 +0000 (+0300) Subject: Volume fixes for native announcements (#2151) X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=6bfe20a02561c71ea55773d3495402ef30dce82e;p=music-assistant-server.git Volume fixes for native announcements (#2151) --- diff --git a/music_assistant/providers/snapcast/__init__.py b/music_assistant/providers/snapcast/__init__.py index 015b9a7f..5a6e9d6a 100644 --- a/music_assistant/providers/snapcast/__init__.py +++ b/music_assistant/providers/snapcast/__init__.py @@ -650,9 +650,10 @@ class SnapCastProvider(PlayerProvider): # We go for the simplest solution: save the previous volume, change it, restore later # (with the downside that the change will be visible in the UI) player = self.mass.players.get(player_id) - orig_volume_level = player.volume_level - volume_level = self.mass.players.get_announcement_volume(player_id, volume_level) - await self.cmd_volume_set(player_id, volume_level) + orig_volume_level = player.volume_level # Note: might be None + + if volume_level is not None: + await self.cmd_volume_set(player_id, volume_level) input_format = DEFAULT_SNAPCAST_FORMAT audio_source = self.mass.streams.get_announcement_stream( @@ -690,9 +691,9 @@ class SnapCastProvider(PlayerProvider): # delete the announcement stream await self._delete_stream(stream_name) - # restore volume, if it is still the same we set above - # (the user did not change it while the announcement was playing) - if player.volume_level == volume_level and orig_volume_level is not None: + # restore volume, if we changed it above and it's still the same we set + # (the user did not change it himself while the announcement was playing) + if player.volume_level == volume_level and None not in [volume_level, orig_volume_level]: await self.cmd_volume_set(player_id, orig_volume_level) # and restore the group to either the default or the music stream diff --git a/music_assistant/providers/sonos/provider.py b/music_assistant/providers/sonos/provider.py index 1e056d05..2481cc6e 100644 --- a/music_assistant/providers/sonos/provider.py +++ b/music_assistant/providers/sonos/provider.py @@ -377,7 +377,6 @@ class SonosPlayerProvider(PlayerProvider): announcement.uri, sonos_player.mass_player.display_name, ) - volume_level = self.mass.players.get_announcement_volume(player_id, volume_level) await sonos_player.client.player.play_audio_clip( announcement.uri, volume_level, name="Announcement" )