Volume fixes for native announcements (#2151)
authorKostas Chatzikokolakis <kostas@chatzi.org>
Sun, 27 Apr 2025 00:05:45 +0000 (03:05 +0300)
committerGitHub <noreply@github.com>
Sun, 27 Apr 2025 00:05:45 +0000 (02:05 +0200)
music_assistant/providers/snapcast/__init__.py
music_assistant/providers/sonos/provider.py

index 015b9a7f9659fb3332d0e29240b3dae5365a4cbb..5a6e9d6a97363a94ccfea67a546f3b9e37ac3903 100644 (file)
@@ -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
index 1e056d05704e73addb356421db1fe76db73a342b..2481cc6eb97223f8e3e6303c4a69885b267a73d4 100644 (file)
@@ -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"
         )