You are not logged in.

#1 2012-12-31 13:43:52

count-corrupt
Member
From: Germany
Registered: 2009-02-01
Posts: 112

Making MPD and Pulseaudio play with systemd

The problem

After the switch to systemd, mpd does not output any sound through pulseaudio.  I have mpd running as a system service and pulseaudio is started with my session through .xinitrc (start-pulseaudio-x11).

Steps taken so far

I played around for a while and discovered a few things.

  • The system mpd runs as as user mpd which lacks appropriate rights to connect to my session-bound pulseaudio daemon.

  • Connecting to pulseaudio works by turning MPD into a user service.

  • User service mpd makes me lose the ability to kill X at will and still have my music playing. I don't log in on a vt before starting X but have the SLiM service started by systemd.

Partial solution

Adding the user mpd to the audio group works in one of two ways:

  1. Disabling autospawn in /etc/pulse/client.conf will make mpd connect to the right pulseaudio session, as long as the mpd service is started after I logged in

  2. Enabling autospawn in /etc/pulse/client.conf will make mpd work as expected but block audio for all my other programs once I logged in. I can only assume that mpd starts a new pulseaudio session that my user then lacks the rights to use.

Open questions

The problem clearly is the order in which services are started. I wouldn't mind having a system-level pulseaudio service but I guess there are reasons against that. Now the question is whether or not there is a way to make system-level mpd wait for my session-bound pulseaudio daemon and connect to that when I disable autospawn for pulse clients.
Or, more generally speaking, is there a proper way to make this work? All of the guides and forum hacks I found (and there are a lot of them) are just that, hacks and partial solutions. I'd like to find a way that works out of the box and is reliable.

Maybe there is a way I haven't seen yet or we can work something out here. In the meantime I guess I'll go the user service route with mpd. Even though this makes it only an ncurses amarok for me.


Edit: formatting

Last edited by count-corrupt (2012-12-31 13:44:10)

Offline

#2 2012-12-31 14:06:33

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,788
Website

Re: Making MPD and Pulseaudio play with systemd

Works fine here, but I run mpd as myself, rather than as a system daemon.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2012-12-31 19:07:05

cgar
Member
Registered: 2012-08-26
Posts: 10

Re: Making MPD and Pulseaudio play with systemd

As described in the MPD wiki article, the following works for me.

Users of PulseAudio will need to make the following modification:
/etc/mpd.conf
audio_output {
        type                    "pulse"
        name                    "pulse audio"
}

Offline

#4 2012-12-31 19:14:45

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: Making MPD and Pulseaudio play with systemd


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2012-12-31 20:20:45

count-corrupt
Member
From: Germany
Registered: 2009-02-01
Posts: 112

Re: Making MPD and Pulseaudio play with systemd

Maybe I haven't made myself clear enough. I know how to configure mpd. I have read the documentation. Read the arch wiki, read the mpd wiki and even part of the pulseaudio documentation. The problem is related to access rights between the system level mpd and session level pulseaudio. I'm looking for a clean way to make system level mod work with pulse. Be it system level pulse or a setup in which system level mod can use session level pulse.

Offline

#6 2012-12-31 21:03:33

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Making MPD and Pulseaudio play with systemd

I'm not sure if this helps your use case at all:

1. I start mpd from a system level systemd service file _as_ my normal user (User=firecat53)
2. In order to have the pulseaudio session that starts when I login to X (autologin) pick up the systemd-started mpd instance and still allow other sound-using applications to function at the same time, I had to uncomment these lines from /etc/pulse/default.pa:

### Publish connection data in the X11 root window
.ifexists module-x11-publish.so
.nofail
load-module module-x11-publish
.fail
.endif

3. While in X with mpd playing, if I switch to a non-logged in virtual terminal the music stops, but will restart with a quick 'mpc start' after I login. Once logged in to that VT, I can switch back and forth to/from X and the music continues just fine.

Hope that helps!
Scott

Offline

#7 2012-12-31 21:07:31

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Making MPD and Pulseaudio play with systemd

Offline

#8 2013-01-01 04:04:32

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Making MPD and Pulseaudio play with systemd

this changed with pulseaudio3.

There is no easy way i know of you can make mpd run as another user now.
Just make mpd run as your own user and make sure the mpd service file looks like this:

.include /usr/lib/systemd/system/mpd.service

[Unit]
After=network.target
After=sound.target

[Service]
User=YOUR_USER
PAMName=system-local-login

*Edit*

in theory every user can use the pulse session, by providing the appropriate XDG variable, but i dont know exactly how.

Last edited by Rasi (2013-01-01 04:05:14)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#9 2013-01-01 17:28:18

count-corrupt
Member
From: Germany
Registered: 2009-02-01
Posts: 112

Re: Making MPD and Pulseaudio play with systemd

firecat53 wrote:

I'm not sure if this helps your use case at all:

1. I start mpd from a system level systemd service file _as_ my normal user (User=firecat53)
2. In order to have the pulseaudio session that starts when I login to X (autologin) pick up the systemd-started mpd instance and still allow other sound-using applications to function at the same time, I had to uncomment these lines from /etc/pulse/default.pa:

Rasi wrote:

this changed with pulseaudio3.

There is no easy way i know of you can make mpd run as another user now.
Just make mpd run as your own user and make sure the mpd service file looks like this:

*Edit*

in theory every user can use the pulse session, by providing the appropriate XDG variable, but i dont know exactly how.

Appreciate the suggestions. But for some reason starting mpd as my user, system or user level, has never worked for me. As soon as I have the service started as my own user, the mpd-started pulse client fails with connection error messages. Plus, I'd rather not start the service as just one user. This should work for all users. I wonder why there isn't a systemd service to start a central pulseaudio instance. Maybe I'm misunderstanding the purpose of pulseaudio but I vaguely remember the old esd running as an init service. All this complexity and compromise I'm looking at right now seems to stem from pulse being started with X instead of at boot.

Offline

#10 2013-01-01 23:53:16

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: Making MPD and Pulseaudio play with systemd

A bit of a workaround (mentioned in the wiki as well) is to use the TCP plugins, that's what I'm doing currently. module-native-protocol-tcp on pulse side and just set localhost server on mpd's audio_output.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

Board footer

Powered by FluxBB