MPD with pulseaudio
I have recently made a clean install of Ubuntu 14.10 and once again I am left with trouble with MPD. I think I had managed to fix it last time, but I am not sure how.
My issue is to be able to use an external bluetooth speaker with MPD. Even better, I would like to be able to use both the plugged and the bluetooth speaker at the same time.
Unfortunately, MPD does not show under the applications that are producing audio under Gnome audio settings, and hence it ignores my directive to use the bluetooth speaker. I think this is because MPD is using Alsa instead of Pulseaudio.
Now, in my mpd.conf I have the lines
audio_output {
type "pulse"
name "MPD"
# server "localhost"
}
I have also tried to decomment the server line, but in this case, MPD does not even start.
To clarify, MPD is running under the user mpd
, which is under the groups pulse
and pulse-access
, but this does not seem to be enough.
Now, I believe I can run MPD under my own user, and this could fix some of the issues, but I'd rather not, as other users of this PC may want to listen to music as well.
What is the right way to make MPD use Pulseaudio (or do whatever is necessary to connect it to other speakers than the default?)
Solution 1:
Unlike MPD in system wide mode PulseAudio is running in userspace. This means, all pulseaudio settings including Bluetooth discovery and providing a Bluetooth audio sink is done from a user session.
The MPD daemon, when running system wide, is unable to access Pulse Audio devices running in a user session. As it is in theory possible to run Pulse Audio in system wide mode, this is not recommended, at least we should not do so in a desktop setup. It would then be a much better option to run MPD from userspace.
To still be able to make use of devices a running PulseAudio server provides we use of TCP streaming capabilites of both, PulseAudio and MPD.
This requires the following in /etc/mpd.conf
:
audio_output {
type "pulse"
name "My PULSE Device"
server "localhost"
}
Then we also need to load the TCP protocol to stream to a running PulseAudio server. This can be added to the /etc/pulse/default.pa
to be loaded every time a user logs in (or started from CLI for testing with pacmd load-module
).
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 # IP of localhost
Disclaimer: This should work for switching to a Bluetooth audio device but I could not test this because my Bluetooth dongle has issues on my 14.10 test system.
Solution 2:
The solution proposed by @Takkat also worked for me with a little modification:
On Debian Buster, I just had to replace localhost
with 127.0.0.1
in mpd.conf server
option, overwise mpd tried to connect with the IPv6 address ::1
and failed with:
ERROR: Failed to open "My PULSE Device" [pulse]; failed to connect: Access denied
(Sorry for the answer instead of comment, I'm new here and doesn't have enough points yet to comment. No problem for me if someone moves or remove this message).