philippe44 / AirConnect

Use AirPlay to stream to UPnP/Sonos & Chromecast devices
Other
3.44k stars 217 forks source link

Media volume synchronisation #350

Closed scottie1 closed 1 year ago

scottie1 commented 3 years ago

Hello, Thank you for a fabulous project, I've been using it now for quite some time now.

I have a Raspberry 4 running airupnp which connects to a Sonos Play 1 and a Samsung HW-Q90R soundbar.

I find that when I connect to my Samsung soundbar the volume of the Apple device is applied to the soundbar, this can result in extremely loud volume settings as both devices don't use the same volume mapping. Would it be possible for airupnp to read the audio device (soundbar) volume setting and then apply this to the Apple media player? This way the volume would remain the same when the connection is first made, although it would still be possible adjust the volume setting from the Apple device.

If the above is not possible, perhaps a means to disable all volume changes and use the remote or volume buttons instead?

Many thanks Andy

philippe44 commented 3 years ago

The AirPlay controller guides the volume and normally it is memorized between sessions so it restarts always at the previous level. Then when volume is changed on the UPnP player, it is reflected to the AirPlay controller

scottie1 commented 3 years ago

I'm using airupnp on both iOS (14.6) and MacOS (11.4), I find that on both of these devices the volume of the UPnP player is set to 33% by the AirPlay controller when the AirPlay connection is established. It doesn't get memorised between sessions.

I have tested the behaviour on my HomePod using AirPlay 2 - when the AirPlay connection is established the AirPlay controller volume is set to the same volume as the HomePod, so if the HomePod volume is 5% then the Airplay controller volume is also set to 5%. When disconnected the volume of the AirPlay controller reverts back to the previous level prior to the AirPlay connection.

I have made a small change to file airupnp.c to comment out the CtrlSetVolume function call on lines 362 and 376 and rebuilt the code. The volume is now no longer altered by the AirPlay controller, so it has the desired effect, no more ruptured eardrums.

As mentioned in my first post, would it be possible to read the UPnP player volume and apply this to the AirPlay controller when the connection is established, so emulating the behaviour observed on my HomePod?

RyanMelenaNoesis commented 3 years ago

I'm seeing the same behavior of reverting to 33% volume on each connection running aircast-x86-64

philippe44 commented 3 years ago

I don't know what to say. I don't observe that with my iPhone or iTunes (Windows). The volume is memorized by the controller and set to that memorized value at every connection. This is the behavior that most users expect, not to have the value previously set on the speaker to take over. There is something with your setup that I don't understand. There is probably a problematic volume loop happening between the two.

scottie1 commented 3 years ago

As I mentioned, I modified the code to ignore volume change requests from the AirPlay controller, for me this is a satisfactory work around and I'm using this right now. Could this be incorporated into the main code base? It would be great if a command line argument could be added to enable/disable this mode.

philippe44 commented 3 years ago

There are already too many options. I'd rather figure out why you guys are experiencing that issue

RyanMelenaNoesis commented 3 years ago

Here is the command I'm using to start AirConnect: /opt/airconnect/aircast-x86-64 --noflush -c wav -z -f /var/log/airconnect.log

I'm using version 0.2.50.5 downloaded from https://github.com/philippe44/AirConnect/blob/master/bin/aircast-x86-64

I only have one iOS device to test with currently (which is the one I was experiencing the volume reset issue on) and it is an iPhone 7.