You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Watch the shairport mpris stream for volume changes and update amplipi volume info accordingly"""
28
+
whileTrue:
29
+
try:
30
+
ifself.volume!=self.mpris.Volume:
31
+
self.logger.debug(f"Airplay volume changed from {self.volume} to {self.mpris.Volume}")
32
+
self.volume=float(self.mpris.Volume)
33
+
self.schedule_event(VolEvents.CHANGE_AMPLIPI)
34
+
# self.delta = self.mpris.Volume - self.volume
35
+
36
+
exceptExceptionase:
37
+
self.logger.exception(f"Error: {e}")
38
+
return
39
+
sleep(0.1)
40
+
41
+
defset_vol(self, amplipi_volume: float, vol_set_point: float) ->float: # This has unused variable vol_set_point to keep up with the underlying StreamData.set_vol function schema
42
+
"""Update Airplay's volume slider to match AmpliPi"""
43
+
try:
44
+
# Airplay does not allow external devices to set the volume of a users system
45
+
46
+
# Airplay is a fully authoritative volume source, meaning it forces amplipi volume to equal its volume now. If that ever changes, this will be relevant:
47
+
# There are two values this could realistically be returned and become the new vol_set_point, and they each have their own drawbacks:
48
+
49
+
# amplipi_volume: If amplipi_volume is the new set point, any changes to airplay volume will send the volume to an odd
50
+
# spot as it just sets the vol average of amplipi to be the same as the value of airplay's vol
51
+
52
+
# vol_set_point: if vol_set_point is retained as the set point, any changes to amplipi will reflect for 1-2 seconds at most and then
53
+
# bounce back to where it had been, resulting in a glitchy front end interface
54
+
55
+
# In any future MPRIS based volume synchronizers, you can check if self.mpris.CanControl is true and then potentially directly set self.mpris.Volume
56
+
# Note that we cannot do this due to this line: <property name='Volume' type='d' access='read'/>
57
+
# That exists in the MPRIS config xml at https://github.com/mikebrady/shairport-sync/blob/master/org.mpris.MediaPlayer2.xml
58
+
59
+
# self.dbus.Set(
60
+
# 'org.mpris.MediaPlayer2',
61
+
# 'Volume',
62
+
# Variant("d", amplipi_volume)
63
+
# )
64
+
65
+
returnamplipi_volume
66
+
exceptExceptionase:
67
+
self.logger.exception(f"Exception: {e}")
68
+
69
+
70
+
if__name__=="__main__":
71
+
72
+
parser=argparse.ArgumentParser(description="Read metadata from a given URL and write it to a file.")
73
+
74
+
parser.add_argument("service_suffix", help="Name of mpris instance", type=str)
75
+
parser.add_argument("config_dir", help="The directory of the vsrc config", type=str)
76
+
parser.add_argument("--debug", action="store_true", help="Change log level from WARNING to DEBUG")
0 commit comments