My Mac loses connection to AirPlay speakers after inactivity

Situation:
I play music through my AirPlay speakers “Office” (2 HomePods). When I pause the audio and step away from the computer for a while, I come back to silence, ie no sound at all, regardless of volume level. However, if I switch to the built-in speakers and then back to AirPlay, everything works again.

This has been going on for several years, across different Macs and different versions of macOS. The Mac simply drops the AirPlay connection when I’m not around. Even if I leave audio playing, the connection eventually breaks (though I’m not sure exactly how long that takes, probably a few hours).

I have reported this to Apple multiple times with no result.

What I’ve tried:
Since switching to built-in audio and back fixes it, I thought a Keyboard Maestro script could automate that workaround. Unfortunately, KM’s “Set Audio Output Device” action doesn’t support AirPlay devices. I also looked into SwitchAudioSource (via Homebrew) and AppleScript, but neither offers a clean solution without additional installs or fragile UI automation.

Does anyone have a reliable workaround for keeping AirPlay connected, or a way to programmatically switch audio output to AirPlay on macOS?

I’m getting really tired of this… :frowning:

I have something similar where it will happily be playing music via my HomePod mini and then I realise it’s all gone quiet, a look at my iPhone shows it happily playing, but no sound.

If I then hit back (to the beginning of the song) it works again, I don’t even need to swap to a different output, just restart the current song.

Check your network setup. AirPlay is very sensitive to mDNS (multicast DNS), which is not used by most other network products/services, so a problem with network gear can be a hidden issue.

The most common mDNS problem is failure to see the device at all or random dropout of the connection. Both problems are non-deterministic, which means not easy to diagnose and no simple workaround, although rebooting everything does brute-force tend to temporarily clear things up.

The mDNS problem is more common with Wi-Fi than wired Ethernet, but HomePods, unlike Sonos and other gear, doesn’t have an Ethernet option.

If more than just annoying, solutions tend to be $$$ and buying directly attached speakers to the Mac or other audio solutions avoiding HomePods and/or AirPlay. (Not ideal, but some people simply want something that always works, even if less elegent)