Ubuntu – mpd conflicting with other applications — taking control of pulse

mpdpulseaudiosound

Simple explanation

If mpd is playing and sound attempts to play through another application, x, sound from x will not be output.

If sound from another application, x, is playing and mpd then attempts to play, no sound will be output from mpd whilst sound from x continues to play.

Details

I first noticed this problem with Flash, and this continues to be the most common scenario. I posted a question about this before realising it was not strictly Flash-related, but instead is something to do with mpd.

My biggest frustration comes from trying to get mpd working again, as I can't seem to pin down any method. Sometimes pulseaudio -k seems to help, other times sudo /etc/init.d/mpd restart, others killing Chromium (due to Flash) with SIGTERM. Most of the time it's a combination of the above.

I think this might be because I run mpd as another user and use pulseaudio. It is not run as root or current user. Also, mpd is compiled with pulse support.

I have tried numerous things, however I honestly couldn't recite what, as it has been some time since. I'd rather not go poking around without some direction, but I'd be really happy to fix this problem once and for all.

mpd.conf

Simplified by removing comments/blank lines.

music_directory     "/var/lib/mpd/music"
playlist_directory      "/var/lib/mpd/playlists"
db_file         "/var/lib/mpd/tag_cache"
log_file            "/var/log/mpd/mpd.log"
pid_file            "/var/run/mpd/pid"
state_file          "/var/lib/mpd/state"

user                "mpd"
bind_to_address     "wilson"

input {
        plugin "curl"
}

audio_output {
    type        "pulse"
    name        "My Pulse Output"

}

filesystem_charset      "UTF-8"
id3v1_encoding          "UTF-8"

Question

For the sake of keeping this a question: does anyone know what is causing this, or how to fix it without running mpd as the current user?

Best Answer

I had this problem when I first started using mpd, but it was quite some time ago, so I can't exactly remember what I did to fix it!

Do you have PulseAudio preferences installed? I found this tip on a forum: sudo apt-get install paprefs

Then open PulseAudio prefrences from the menu: System->Preferences->PulseAudio Preferences Click the Network Server tab, then check the "Enable network access to local sound devices" box, and finally check the "Don't require authentication" box. After that, restart mpd: sudo /etc/init.d/mpd restart

However... I just realized that mpd works fine for me and I don't have "network access to local sound devices" enabled.

I think you might be right about needing to run mpd as the current user, which is what I'm doing. (I have no clue as to why this is though!)

A simple guide to setting up mpd to be run as a user can be found here: http://gmpc.wikia.com/wiki/MPD_INSTALL_USER_SERVICE_UBUNTU

To sum things up, since you already have mpd installed:

1.) Stop it: sudo update-rc.d mpd disable

2.) Copy your mpdconf to your home directiory (as .mpdconf), and change the following entries to places where your user can access and write to:

music_directory
playlist_directory
db_file
log_file
error_file
pid_file
state_file 

The page I'm taking this from suggests just creating a .mpd folder in your home directory for this stuff, save for your actual music directory.

3.) Comment out the user line in .mpdconf: #user "mpd"

4.) Now you can run mpd and update the database.

5.) To make mpd start up automatically as a user when logging in, go to Startup Applications and add an entry for mpd, then create an autostart file in ~/.config/autostart/.

[Desktop Entry]
Type=Application
Exec=mpd
Hidden=false
NoDisplay=false
Terminal=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Music Player Daemon
Name=Music Player Daemon
Comment[en_US]=plays the music
Comment=plays the music

There are probably downsides to running as a user, so maybe this won't suit your needs.

Related Question