Music Player Daemon (MPD)

Music Player Daemon (MPD) is a flexible, powerful, server-side application for playing music. Through plug-ins and libraries it can play a variety of sound files while being controlled by its network protocol.

Installing with the GUI

Start Synaptic Package Manager ( System > Administration > Synaptic Package Manager ) and in the search box enter mpd. Mark the package mpd for installation and client if required. In this guide Sonata is used as an example.

The following packages should be marked for installation:

  • mpd
  • sonata

Click Apply.

Installing with the command line (advanced users)

$ sudo apt-get update

$ sudo apt-get install mpd sonata

Configuring MPD to run as a system service

By default MPD is configured to run as a daemon to is available to all users.

  • In the configuration, many of the default options will be what is required; however, there is still some customization needed to be done.

Editing the configuration

Almost all of the default settings in <tt>/etc/mpd.conf</tt> can be left untouched, but there are some things that you may want to change.

$ sudo nano /etc/mpd.conf

You will need to specify the music directory:

music_directory    "/home/user/Music"   # or whatever your music is located

The audio controller will need to be defined. First, comment the ALSA section:

#audio_output {
#  type    "alsa"
#  name    "Sound Card"
#  device    "hw:0,0"  # optional
#  format    "44100:16:2"  # optional
#  mixer_device  "default" # optional
#  mixer_control "PCM"   # optional
#  mixer_index "0"   # optional

Then add Pulse Audio below it (comment out, and define name [optional]):

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

Sometimes there can be a problem with sound getting processed correctly and uncommenting this line might help:

#mixer_type "software"

Bugfix: Giving MPD proper permissions

Unfortunately, by default MPD does not have the proper permissions to access PulseAudio, the default audio setup on most new Ubuntu systems. If MPD plays for you without these steps, then that's great, but if you can play your songs but no sound is emitted, try the following steps.

What we need to do is add the user mpd to the groups pulse and pulse-access so that it can access the audio system.

$ sudo usermod -aG pulse,pulse-access mpd

MPD starts new pulseserver

Unfortunatly MPD tries to start its own pulseaudio server. So if you still unlucky you could try:

audio_output {
  type    "pulse"
  name    "MPD"
  server  "localhost"   # optional
# sink    "remote_server_sink"  # optional

Then you need to allow access. You should install paprefs

sudo apt-get install paprefs 

Then run it (e.g. alt+f2 and enter paperfs). 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. At this point make sure to restart the pulseaudio daemon.

sudo service pulseaudio restart

Now you should see MPD in Sound settings Application tab and hear music.

Configuring MPD to run as a user service

MPD doesn't need to run as a daemon and can be run as a regular program by any user. By doing this, MPD will use the users configurations and has no need for a system-wide configuration (useful if you keep your /home on a separate partition.

First stop the daemon and disable from starting on boot:

sudo service mpd stop
sudo update-rc.d mpd disable

* Note: This will probably change as of Ubuntu 11.04 (Natty) the MPD daemon is not yet an upstart service yet.

Create a directory for the mpd files and the playlists:

mkdir -p ~/.mpd/playlists

Copy the MPD configuration file to the home folder:

gunzip -c /usr/share/doc/mpd/examples/mpd.conf.gz > ~/.mpd/mpd.conf

Create all of the requisite files:

touch ~/.mpd/{mpd.db,mpd.log,,mpdstate}

Edit the configuration file to direct to the local MPD files:

gedit ~/.mpd/mpd.conf

playlist_directory "/home/user/.mpd/playlists"   # Cannot use ~/
db_file            "/home/user/.mpd/mpd.db"
log_file           "/home/user/.mpd/mpd.log"
pid_file           "/home/user/.mpd/"
state_file         "/home/user/.mpd/mpdstate"

The music_directory isn't required to be specified unless the music directory is in another place besides /home/user/Music.

Comment the user line (unnecessary/unwanted if using as a non-daemon):

#user       "mpd"

Comment out alsa audio_output section, select Pulse section:

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

Create a desktop file for MPD to have MPD load on log in:

gedit ~/.config/autostart/mpd.desktop

and add:

[Desktop Entry]
Name=Music Player Daemon
Comment=Server for playing audio files

Now the MPD daemon will run in the background and a MPD music client can connect to it; until then mpd can be started by running mpd from the command line.

Bugfix: Pausing loses connection with Pulse server

This is a bug the occurs with Pulse when pausing a track and trying to play it again that the MPD client will show that the track is playing but no sound is heard (skipping to will resume contact with the Pulse sound server, or stopping and playing will as well). This bug effects pulseaudio-1:09.22 and possibly later.

To fix this modify the MPD configuration to use ALSA directly.

In the mpd.confdirect MPD to use ALSA and comment the pulse section if previously specified:

audio_output {
  type    "alsa"
  name    "Sound Card"
# device    "hw:0,0"  # optional
# format    "44100:16:2"  # optional
# mixer_device  "default" # optional
# mixer_control "PCM"   # optional
# mixer_index "0"   # optional

Configuring MPD to stream to an IceCast server


MPD (last edited 2017-02-08 06:24:48 by 5)