Getting rid of pulseaudio autospawn problem

Well, yes, after latest updates, my audio system stopped working properly. I have a Raspberry PI B+ with the HiFiBerry add-on card, providing a very nice and clear sound to my HiFi system. So, what was going on?

$ journalctl -f

Dec 28 09:43:48 xxxx pulseaudio[3050]: [pulseaudio] pid.c: Daemon already running.
Dec 28 09:43:48 xxxx spotifyd[2650]: 09:43:48 [ERROR] Could not start audio: Connection refused

The log shows the problem with spotifyd, but it also affected the mpd instance that used to worked very nicely.

After spending some hours (!) tinkering with the pulseaudio client.conf,, reinstalling it, etc, trying to avoid the –system mode, well, I managed to work it out. Sharing it here for others to spend less time.

The problem is with the pulseaudio “autospawn” feature, I think. This is a known issue and google searches prompted forums and bug tickets about it. Others were simply and squarely recommending disabling pulseaudio. That’s not an option for me as I also use the TCP sink to stream music to my HiFi system from other computers via pulseaudio native-tcp plugin.

The architecture of my setup is:

  • Have a pulseaudio system service start under the mpd user
    • Have this instance offer system-wide connections from other processes from localhost
  • Disable autospawn for the mpd user
  • Configure mpd to connect to localhost
  • Configure pulseaudio for user mpd so any process launched under it won’t autospawn but will connect to localhost instead. This is useful for the Spotify Daemon, in may case

The configuration files are here:

Just edit the files shown in that gist. You may need to create the mpd user’s client.conf file. I’ve shown there the default path as installed on Raspbian. If you’ve customized mpd’s HOME directory, then please adjust the path so you end-up with ${HOME}/.config/pulse/client.conf

Don’t forget to enable the pulseaudio service so it automatically starts upon next boot. Then stop mpd and any other pulse client, kill all pulseaudio instances, start the pulseaudio service then mpd and the other music-related daemons and enjoy. Don’t forget to have a separate terminal monitoring the “journalctl -f” so you quickly spot problems.

Have fun!