7

When I try to play mpd through pulseaudio, mpd.log reports:

pulse_output: Failed to enable "Pink ROCKI" [pulse]: pa_context_connect() has failed: Connection refused

  • Pulse seems to be working fine since pacmd list-sinks shows all my pulse sinks, meb browser audio plays fine through the default sink, and VLC can play sound through any of them.
  • mpd works fine if I send the output through alsa instead of pulse
  • Both mpd and pulseaudio are running under my account (fred).
  • fred, mpd, and pulseaudio are all members of the pulse, pulse-access, and audio groups.
  • I have even tried this with different builds of pulseaudio: the 4.0 that comes with Ubuntu 14.04, the experimental RAOP2 built with pulse 4.0, and the experimental RAOP2 built with pulse 5.0. mpd will not work with any of them.

My mpd.conf file is vanilla; the pulse section is the generic:

    audio_output { 
    type "pulse" 
    name "General Pulse" 
    }

Though as laugeo suggests below, I have also tried specifying an individual sink, both by name:

audio_output {
    type        "pulse"
    name        "ROCKI"
    sink        "raop_output.ASAP1826T.local"
}

and by index #:

audio_output {
    type        "pulse"
    name        "ROCKI"
    sink        "4"
}

What should I try next? Could configuring pulseaudio to run as a system service help?

This is on Ubuntu 14.04, pulseaudio 4.0 (and 5.0), Music Player Daemon 0.18.7

Update: I found this blog where the blogger Louiz seems to have solved the same (or very similar) problem:

MPD apparently tries to spawn a new pulseaudio process, as my own user, and it fails because it is already running. I could not understand why it could not just use the existing pulseaudio instance, without trying to spawn a new one.

I understood thanks to this post.

MPD could not find the already-running pulseaudio instance because the environment variable XDG_RUNTIME_DIR was not set, and thet’s where pulseaudio stores its files (the socket, the process pid, etc).

I tried his solution:

creating a new file /etc/systemd/system/mpd.service.d/fixenv.conf containing:

[Service] Environment=XDG_RUNTIME_DIR=/run/user/1000

(Replace 1000 by the UNIX id of your user.)

I rebooted and XDG_RUNTIME_DIR was set correctly, and pulse put its pid file in the /run/user/1000/pulse/ directory (my user id is 1000), but I still get the same error from mpd:

pulse_output: Failed to enable "ROCKI" [pulse]: pa_context_connect() has failed: Connection refused

I'm learning more about linux every day, but sockets, process pids, systemd (isn't Ubuntu supposed to use upstart? systemd seems to be running and launching things), etc. are all above my pay grade right now - I'm lost in the woods.

3
+50

Finally, better than pulseaudio daemon mode, the best solution is there: it is about running mpd as yourself (and not mpd user) so you have no problem to use your own session pulseaudio.

A different answer , but tested and also working:
configure pulseaudio to run as "daemon mode" instead of the standard "user mode"

  • in a terminal, run
    sudo gedit /etc/init/pulseaudio.conf
    then uncomment line 20 removing # to get:
    start on runlevel [2345]
    save and quit gedit.
  • Run this 2 commands in a terminal:
    sudo usermod -aG pulse,pulse-access mpd
    sudo usermod -aG pulse,pulse-access your-login
    In the 2nd command, replace "your-login"

Now reboot: hopefully , it will work.

Note: For info, this page lists reasons why you must avoid pulseaudio daemon mode, but i find it ok on a single user pc (especially I see no more cpu/memory usage than user mode).

  • 1
    ... and break who knows what along the way. Using daemon mode is discouraged, and, thus, not tested well. – Barafu Albino Nov 13 '14 at 10:48
  • yes, i edited the answer – laugeo Nov 13 '14 at 15:01
  • Well, since this pulseaudio install is already broken, I'm willing to try it. However I don't have a pulseaudio.conf in my /etc/init directory. I've search all the pulse config files and directories I'm aware of, and can't find any files with "start on runlevel [2345]", which is weird, because I know I saw a config file with that in it last week. It may have gotten whacked during my uninstalling/purging/reinstalling attempts. I'll see if I can find an example file somewhere... – Fred Hamilton Nov 13 '14 at 15:50
  • Put a clean pulseaudio.conf in /etc/init and got it working...but now pacmd doesn't work ("No PulseAudio daemon running, or not running as session daemon"), so I can't list-sinks. So it's still sort-of broken, but at least I mpd is playing nice with pulse. I wanted to get pulseaudio working "right" (the way the creators intended), but it seems the only way to solve my problem is to ignore their warnings and run it in system mode. – Fred Hamilton Nov 13 '14 at 23:55
  • The best way could be gmpc.wikia.com/wiki/MPD_INSTALL_USER_SERVICE_UBUNTU : it is about running mpd as yourself (and not mpd user) so it should have no problem to use your session pulseaudio . In this case revert pulseaudio to not-daemon mode – laugeo Nov 14 '14 at 11:17
3

The XDG_RUNTIME_DIR solution worked for me, but there is no need to create a file in /etc/systemd/system. Just add this line in /etc/init.d/mpd:

export XDG_RUNTIME_DIR=/run/user/1000

I already have specified mpd to run as my own user and "audio" group in /etc/mpd.conf.

  • What's "The XDG_RUNTIME_DIR solution"? – Karl Richter Jun 23 '15 at 15:49
  • It's described in the question, and also in my answer (slightly different). – user13097 Jun 25 '15 at 9:34
0

You can try to specify pulseaudio sink in MPD config file:

To display pulseaudio sinks, run this command in a terminal:
pactl list short sinks

It will output something like:

0   alsa_output.pci-0000_00_03.0.hdmi-stereo    module-alsa-card.c  s16le 2ch 44100Hz   IDLE
1   alsa_output.pci-0000_00_1b.0.analog-stereo  module-alsa-card.c  s16le 2ch 44100Hz   RUNNING

Choose your main sink (the 2nd one in my case because i have no HDMI sound) and copy its name in mpd.conf audio_output :

audio_output {

    type                    "pulse"
    name                    "MPD PulseAudio Output"
   sink                    "alsa_output.pci-0000_00_1b.0.analog-stereo"

}

  • Thanks, but I already tried that with both the name and the index # - neither worked. I don't think the mpd-pulse conversation gets even that far. But thanks for "pactl list short sinks" - I've been using "pacmd list-sinks"; yours is a lot more succinct. – Fred Hamilton Nov 3 '14 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.