You are not logged in.

#1 2017-07-17 09:19:20

paddybu
Member
Registered: 2012-03-30
Posts: 13

mpd and ALSA - connection refused

Hi!
I'm trying to get mpd to work properly, but I'm not finding any solutions for the following problem.
When I start mpd directly as root from terminal, it seems to work fine, I can play music etc and there are no errors. But when I try starting it with systemd, it starts, but I can't play anything with cantata. Using mpc gives following output:

 [paused]  #1/1   0:00/4:48 (0%)
volume: n/a   repeat: off   random: off   single: off   consume: on 
ERROR: Failed to open "alsa pulse" [alsa]; Failed to open ALSA device "pulse": Connection refused

I thought this is only a permission problem, since using root works perfectly, but I don't know where to set permissions so that the mpd user can access alsa devices, except from adding mpd to the group audio, which is done.

# groups mpd
audio mpd

Does someone have an idea how to fix this? Thank you in advance.

/etc/mpd.conf

# groups mpdpid_file "/run/mpd/mpd.pid"
db_file "/var/lib/mpd/mpd.db"
state_file "/var/lib/mpd/mpdstate"
playlist_directory "/var/lib/mpd/playlists"

bind_to_address "192.168.0.15"
bind_to_address "127.0.0.1"

music_directory "/mnt/home/Musik/Sammlung"

audio_output {
	type			"alsa"
	name			"alsa pulse"
	device			"pulse"	# optional
	format			"44100:16:2"	# optional
	mixer_type		"hardware"
	mixer_device		"default"
	mixer_control		"PCM"
}

Offline

#2 2017-07-17 10:25:53

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: mpd and ALSA - connection refused

are you using pulseaudio?

Offline

#3 2017-07-17 10:33:06

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: mpd and ALSA - connection refused

systemctl cat mpd.service

This will tell you, "User=mpd", change it to your user, or give the user mpd proper permissions to your music directory.

Last edited by Docbroke (2017-07-17 10:34:58)

Offline

#4 2017-07-17 10:42:09

paddybu
Member
Registered: 2012-03-30
Posts: 13

Re: mpd and ALSA - connection refused

HiImTye wrote:

are you using pulseaudio?

yes, I tried connecting to pulseaudio directly, but that didn't work out. I tried configuring it like this:  https://wiki.archlinux.org/index.php/Mu … pd_user.29, but for unknown reasons it didn't work out. I used this method in an earlier setup of mpd and it worked, but I don't know what I did back then. So I thought using the alsa pulseaudio card could be a solution that fulfills my needs.

# systemctl cat mpd.service

# /usr/lib/systemd/system/mpd.service
[Unit]
Description=Music Player Daemon
Documentation=man:mpd(1) man:mpd.conf(5)
After=network.target sound.target

[Service]
User=mpd
Type=notify
ExecStart=/usr/bin/mpd --no-daemon

# allow MPD to use real-time priority 50
LimitRTPRIO=50
LimitRTTIME=infinity

# disallow writing to /usr, /bin, /sbin, ...
ProtectSystem=yes

# more paranoid security settings
NoNewPrivileges=yes
ProtectKernelTunables=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
# AF_NETLINK is required by libsmbclient, or it will exit() .. *sigh*
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
RestrictNamespaces=yes

[Install]
WantedBy=default.target
Also=mpd.socket

The mpd user has permissions to the music directory and is, as said earlier, in the audio group.
Changing the User attribute to my user name results in mpd not starting anymore and dropping

fatal_error: Failed to create pid file "/run/mpd/mpd.pid": Permission denied

Last edited by paddybu (2017-07-17 10:46:49)

Offline

#5 2017-07-19 18:59:53

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: mpd and ALSA - connection refused

it seems that you've got three different problems to work out, depending on which way you want to do things.

1) pulseaudio is being run as a user service and therefore the mpd user doesn't have permissions to connect to it, or
2) the permissions of /run/mpd/ need to be changed to allow your user to modify them (or possibly don't exist), or
3) you need to change the pid file to another location

each of these will have a different solution

Last edited by HiImTye (2017-07-19 19:00:35)

Offline

#6 2017-07-20 13:49:27

paddybu
Member
Registered: 2012-03-30
Posts: 13

Re: mpd and ALSA - connection refused

According to your list, I have changed permissions of /run/mpd and /var/lib/mpd so that my user id has rw-access to everything in there. I changed the mpd.service file so that mpd gets started as my own user:

# ps aux | grep mpd
patrick   6824  0.6  0.5 867600 43200 ?        Ssl  15:37   0:00 /usr/bin/mpd --no-daemon

The pid-file error is not occurring anymore of course, but the initial error is still there: 

[paused]  #1/1   0:00/4:48 (0%)
volume: n/a   repeat: off   random: off   single: off   consume: on 
ERROR: Failed to open "alsa pulse" [alsa]; Failed to open ALSA device "pulse": Connection refused

When I add a pulseaudio output to mpd.conf it doesn't play audio either (it instead skips very fast through the queued songs for some reason), but mpd also isn't dropping an error message anywhere I looked for.

audio_output {
	type	"pulse"
	name	"direct pulse"
	server	"127.0.0.1"
}

Offline

#7 2017-07-20 14:49:10

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

Re: mpd and ALSA - connection refused

verbose output of mpd? (start mpd manually with mpd --verbose --stdout --no-daemon), please include the line with the actual command smile

Last edited by Rasi (2017-07-20 14:49:30)


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

#8 2017-07-20 17:53:28

paddybu
Member
Registered: 2012-03-30
Posts: 13

Re: mpd and ALSA - connection refused

This is the output of the exact command you wrote:

$ mpd --verbose --stdout --no-daemon
config_file: loading file /etc/mpd.conf
libsamplerate: libsamplerate converter 'Fastest Sinc Interpolator'
vorbis: Xiph.Org libVorbis 1.3.5
opus: libopus 1.2.1
sndfile: libsndfile-1.0.28
simple_db: reading DB
curl: version 7.54.1
curl: with OpenSSL/1.1.0f
avahi: Initializing interface
avahi: Client changed to state 101
avahi: Client is CONNECTING
state_file: Loading state file /var/lib/mpd/mpdstate
exception: OutputThread could not get realtime scheduling, continuing anyway: sched_setscheduler failed: Operation not permitted
playlist: queue song 1: "..."
decoder_thread: probing plugin mad
mad: detected LAME version 3.97 ("LAME3.97b")
mad: LAME peak found: 0.000000
mad: encoder delay is 576, encoder padding is 2052
decoder: audio_format=44100:24:2, seekable=true
client: [0] opened from 192.168.0.5:49080
client: [1] opened from 192.168.0.5:49082
client: [1] process command "channels"
client: [1] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
exception: Failed to read mixer for 'alsa pulse': no such mixer control: PCM
client: [0] command returned 0
client: [0] process command "stats"
client: [0] command returned 0
client: [0] process command "urlhandlers"
client: [0] command returned 0
client: [0] process command "tagtypes"
client: [0] command returned 0
client: [0] process command "commands"
client: [0] command returned 0
client: [0] process command "lsinfo"
client: [0] command returned 0
client: [0] process command "currentsong"
client: [0] command returned 0
client: [0] process command "listplaylists"
client: [0] command returned 0
client: [0] process command "listplaylistinfo "[Radio Streams]""
exception: Failed to open /var/lib/mpd/playlists/[Radio Streams].m3u: No such file or directory
exception: No such playlist
client: [0] command returned 2
client: [0] process command "playlistinfo"
client: [0] command returned 0
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0

## Here I was connected via cantata and alsa output was the only selected output. I tried klicking play, and surprisingly it worked as it should. Even though a later test showed, that it is still not working when started with systemctl start mpd.

client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0
client: [0] process command "pause "0""
alsa_output: opened pulse type=IOPLUG
alsa_output: buffer: size=96..1048576 time=2176..23777234
alsa_output: period: size=32..349526 time=725..7925760
alsa_output: default period_time = buffer_time/4 = 500000/4 = 125000
alsa_output: format=S16_LE (Signed 16 bit Little Endian)
alsa_output: buffer_size=22050 period_size=5512
output: opened plugin=alsa name="alsa pulse" audio_format=44100:16:2
output: converting in=44100:24:2 -> f=44100:24:2 -> out=44100:16:2
exception: Failed to open mixer for 'alsa pulse': no such mixer control: PCM
client: [0] command returned 0
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "pause "1""
client: [0] command returned 0
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
output: closed plugin=alsa name="alsa pulse"
state_file: Saving state file /var/lib/mpd/mpdstate

## Here the alsa playback has been stopped. In the following, I select the configured pulseaudio device within the settings menu of Cantata. (Alsa output has been unselected, of course). Klicking play produces the same action as described earlier.

client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0
client: [0] process command "disableoutput "0""
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0
client: [0] process command "enableoutput "1""
exception: OutputThread could not get realtime scheduling, continuing anyway: sched_setscheduler failed: Operation not permitted
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [0] process command "outputs"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "pause "0""
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
exception: "direct pulse" [pulse] failed to play: suspended
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
exception: "direct pulse" [pulse] failed to play: suspended
client: [0] process command "status"
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
exception: "direct pulse" [pulse] failed to play: suspended
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
exception: "direct pulse" [pulse] failed to play: suspended
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
exception: "direct pulse" [pulse] failed to play: suspended
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
exception: "direct pulse" [pulse] failed to play: suspended
client: [0] process command "status"
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
exception: "direct pulse" [pulse] failed to play: suspended
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
output: closed plugin=pulse name="direct pulse"
output: opened plugin=pulse name="direct pulse" audio_format=44100:24:2
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
exception: "direct pulse" [pulse] failed to play: suspended
output: closed plugin=pulse name="direct pulse"
exception: Failed to open audio output
client: [0] process command "status"
client: [0] command returned 0
client: [0] process command "replay_gain_status"
client: [0] command returned 0
client: [1] process command "idle"
client: [1] command returned 1
state_file: Saving state file /var/lib/mpd/mpdstate

## For your information: in pulseaudio mode, I clicked the play button only once, thats the output that is produced by this one action.

I double checked that the processes run by the command and by systemd are both listed with the same user, which is my user account "patrick" (checked with ps aux). So I have no idea what is causing the different behaviour.
I don't care if mpd is finally only running under direct pulseaudio or via alsa as a bridge, but I would appreciate mpd showing up in the pulseaudio mixer.

Thank you for your help.

Offline

#9 2017-07-21 03:06:18

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: mpd and ALSA - connection refused

have you tried it without the server line? this is the pulse section from my mpd.conf:

audio_output {
	type		"pulse"
	name		"PulseAudio"
#	server		"remote_server"		# optional
#	sink		"remote_server_sink"	# optional
}

Offline

#10 2017-07-21 10:01:10

paddybu
Member
Registered: 2012-03-30
Posts: 13

Re: mpd and ALSA - connection refused

This drops the following error message when started with systemctl:

ERROR: Failed to enable output "direct pulse" [pulse]; pa_context_connect() has failed: Connection refused

If I start mpd manually like Rasi suggested, it works perfectly. Again, I checked that the mpd process run by systemd is also run as my user account. I have no idea where the difference is. Maybe it works if I change something in the mpd service file?

Offline

#11 2017-08-03 15:21:29

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,425

Re: mpd and ALSA - connection refused

Set up your mpd as an user service read that paragraph closely and follow the link that explains what user services are and how they can be started and manipulated (this is not the same thing as having an User= directive in a system unit service, the magic keyword is

systemctl --user ...

)

Last edited by V1del (2017-08-03 15:26:26)

Offline

Board footer

Powered by FluxBB