Skip to content

Commit

Permalink
Chore: try to workaround strange airplay volume pingpong
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Feb 5, 2025
1 parent 39d914e commit 95ea65f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions music_assistant/providers/airplay/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ async def _handle_dacp_request( # noqa: PLR0915
# to prevent an endless pingpong of volume changes
raop_volume = float(path.split("dmcp.device-volume=", 1)[-1])
volume = convert_airplay_volume(raop_volume)
assert mass_player.volume_level
assert mass_player.volume_level is not None
if (
abs(mass_player.volume_level - volume) > 5
or (time.time() - airplay_player.last_command_sent) < 2
abs(mass_player.volume_level - volume) > 3
or (time.time() - airplay_player.last_command_sent) > 3
):
self.mass.create_task(self.cmd_volume_set(player_id, volume))
else:
Expand All @@ -600,10 +600,12 @@ async def _handle_dacp_request( # noqa: PLR0915
elif "dmcp.volume=" in path:
# volume change request from device (e.g. volume buttons)
volume = int(path.split("dmcp.volume=", 1)[-1])
if volume != mass_player.volume_level:
assert mass_player.volume_level is not None
if (
abs(mass_player.volume_level - volume) > 2
or (time.time() - airplay_player.last_command_sent) > 3
):
self.mass.create_task(self.cmd_volume_set(player_id, volume))
# optimistically set the new volume to prevent bouncing around
mass_player.volume_level = volume
elif "device-prevent-playback=1" in path:
# device switched to another source (or is powered off)
if raop_stream := airplay_player.raop_stream:
Expand Down

0 comments on commit 95ea65f

Please sign in to comment.