Difference between revisions of "Music Player Daemon"

From ArchWiki
Jump to navigation Jump to search
(Method 1: Simpler, working method)
m (Local Configuration (per user): typo)
Line 129: Line 129:
* Edit {{Filename|~/.mpd/mpd.conf}} to specify these files:
* Edit {{Filename|~/.mpd/mpd.conf}} to specify these files:
music_directory    "/home/USER/Music"            # Keep commented if your XDG directory already points to it
music_directory    "/home/USER/Music"            # Keep commented if your XDG directory already points to it
playlist_directory "/home/USER/.mpd/playlists"
playlist_directory "/home/USER/.mpd/playlists"

Revision as of 07:20, 18 November 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

MPD (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their website.

Please have a look at the official page for setup and troubleshooting instructions, the main developer called this wiki page in its current state "full of symptom killers", hence the official pages should contain better instructions.



Install with pacman: Template:Cli


MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances.

Global Configuration (daemon)

The way of setting up mpd depends on the way it is supposed to be used. It can be configured to run on a per-user basis or at system startup with a system-wide configuration. MPD's configuration is saved in Template:Filename.

For a comfortable use, it is sensible to provide MPD access to the following files and directories:

mpd.db    # The music database
mpd.pid   # The file where mpd stores its process ID
mpd.log   # mpd logs here
mpdstate  # mpd's current state is noted here
playlists # the folder where playlists are saved into

In order for MPD to be able to play back audio, ALSA or PulseAudio needs to be setup and working. Do not forget to unmute the required channels.

Starting MPD on system boot

  • As root, check if Template:Filename exists and delete the file if it does. This is safe.


MPD comes with an example configuration file, available at Template:Filename. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.


Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a Template:Filename file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section Starting mpd as a user). This is important to prevent conflicts.

Editing Template:Filename

The default Arch install keeps the setup in /var and uses "mpd" as default user. Edit Template:Filename to reflect as such:


  • If your music collection is contained under multiple directories, you can make symbolic links under Template:Filename then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.
  • To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:


  • Users of PulseAudio will make the following modification:


Creating the required files

Now, having finished configuring MPD, the files and directories for MPD to write in need to be created:

# mkdir -p /var/lib/mpd/playlists /var/run/mpd
# touch /var/lib/mpd/{mpd.db,mpdstate} /var/run/mpd/mpd.pid
  • You then need to change the file's permissions so that the daemon can modify them.
# chown -R mpd /var/lib/mpd /var/run/mpd

Create database

Creating the database is now accomplished via the update feature of the client, for example Template:Codeline.

Note: Creating the MPD database as root using Template:Codeline is deprecated.

Timeline of MPD startup

To depict when MPD drops its superuser privileges and assumes those of the user set in the configuration, the timeline of a normal MPD startup is depicted here:

  1. MPD is started on boot by Template:Filename, by including it in the Template:Codeline array. (Or, this can be done manually each session by running Template:Codeline with root privileges).
  2. Since MPD is now started as root, it first reads the Template:Filename file.
  3. MPD reads the user variable in the Template:Filename file, and changes from root to this user.
  4. MPD then reads the contents of the Template:Filename file and configures itself accordingly.

Notice that MPD changes the running user from root to the one named in the Template:Filename file. This way, uses of Template:Codeline in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of Template:Codeline to Template:Codeline to avoid any confusion over this aspect of MPD's behavior.

Local Configuration (per user)

MPD does not need to be run globally as a daemon and can rather work per user. The usual method to configure MPD globally is because the listed files and folders in the default configuration file point to directories owned by root (the Template:Filename directory). Though a less used method (but perhaps more sensible) is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:

  • A single directory Template:Filename (or any other directory under Template:Filename) will contain all the MPD configuration files.
  • Easier to avoid unforeseen read/write permission errors.

To run MPD as a normal user:

Note: This approach will not work if you want multiple users to have access to MPD at the same time.
  • Create a directory for the required files and the playlists:


  • Copy the contents of the default MPD configuration file in Template:Filename to your home directory:


  • Create all of the requisite files:




Scripted Configuration

Rasi has written a script that will create the proper directory structure, configuration files and prompt for the location of the user's Music directory; it can be downloaded here.

Multi-mpd setup

Useful if you want to run for example an icecast server. If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., Template:Filename), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., Template:Filename, Template:Filename, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you do not have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your Template:Filename above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).


To control mpd, you need a client program. Popular options are:


  • mpc – CLI client, the most basic functionality available.


  • ncmpc – NCurses Client (this one is very useful for running in a console)


  • ncmpcpp – Clone of ncmpc with some new features written in C++ (tag editor, search engine)


  • pms – Highly configurable and accessible ncurses client. Install pmus from the AUR.


  • ario – GTK+ Client with a library browser similar to that of Rhythmbox.


  • gmpc – GNOME Client




  • dmpc – Dmenu-based MPC client with a playlist manager and state-saving on playlist changes. Install dmpc from the AUR.

See a long list of clients at the mpd wiki.

Tips and Tricks

Last.fm scrobbling

To scrobble your songs to Last.fm when using MPD, there are several alternatives.


mpdscribble is a daemon, available in the "community" repository (if you prefer, the "git" version is available in the AUR). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you do not need root access to configure it, because it doesn't need any changes to Template:Codeline at all. Visit the official website for more information.

After you have installed mpdscribble, do the following (not as root):


Template:File Please note that passwords can also be written down as MD5:

echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "
pidof mpdscribble >& /dev/null
if [ $? -ne 0 ]; then
 mpdscribble &

Sonata & Ario

Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata doesn't cache the songs if they cannot be forwarded to Last.fm at the time of playing, meaning they will not be added to the statistics.


The daemon lastfmsubmitd is a daemon which may be installed from the "community" repository as well. To install it, first edit Template:Filename to reflect your requirements and add both Template:Codeline and Template:Codeline to the Template:Codeline array in Template:Filename.

Last.fm playback

Native Last.fm playback

Since version 0.16 mpd has a very well working method to play back last.fm streams. Template:File Then use e.g. mpc to load streams Template:Cli

Last.fm playback with lastfmproxy

lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install lastfmproxy from the AUR and then edit Template:Filename. If you plan to only stream to MPD on the same host, just edit the login info.

Note: Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it is useful to copy Template:Filename to your home directory.

Start lastfmproxy with Template:Codeline and visit Template:Codeline in your web browser. To add a last.fm station navigate to Template:Codeline followed by the lastfm:// (e.g. Template:Codeline). Navigate back to Template:Codeline and download the m3u file by selecting the Start Listening link. Simply add it to your music library path.

Never play on start

This feature has recently been added to mpd git by Martin Kellerman, see commits Template:Codeline and Template:Codeline. As of September 2011, this feature has not yet arrived in a mpd version in the official repositories. If support for this feature is still required, have a look at the following proposals.

Installing mpd from the AUR

This is the best method currently available, but is only currently (as of April 2011) enabled in the git version. Install mpd-git from the AUR and add Template:Codeline to your Template:Filename file.

If you have issues with connecting your client to mpd-git, see Music Player Daemon#Other issues when attempting to connect to mpd with a client.

Method 1

If you do not want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your Template:Filename file:

Method 1.1

Simpler, working method (disables playing on startup of mpd daemon):



     mpc -q pause #add this line only
     add_daemon mpd
Method 1.2

This method was described here before Method 1.1 and is much more complicated:

   stat_busy "Starting Music Player Daemon"
   # always start in paused state
   awk '/^state_file[ \t]+"[^"]+"$/ {
       match($0, "\".+\"")
       sfile = substr($0, RSTART + 1, RLENGTH - 2)
   } /^user[ \t]+"[^"]+"$/ {
       match($0, "\".+\"")
       user = substr($0, RSTART + 1, RLENGTH - 2)
   } END {
       if (sfile == "")
       if (user != "")
               sub(/^~/, "/home/" user, sfile)
       system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")
   }' /etc/mpd.conf
   /usr/bin/mpd /etc/mpd.conf &> /dev/null

This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your Template:Filename:

NoUpgrade = etc/rc.d/mpd

Method 2

Another simpler method, would be to add mpd to your Template:Filename daemons array and add Template:Codeline or Template:Codeline to Template:Filename and to Template:Filename. (Remember you must have mpc installed to use this method).

Adding only the order in Template:Filename cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. On the other hand, if you only add the order to Template:Filename, that will assure that mpd won't play at all, as long as you properly shutdown your system. Even though they are redundant, adding it to Template:Filename would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.

Method 3

The general idea is to ask mdp to pause music when the user logs out, so that mdp will stick to the "pause" state after a reboot. Sending such command can be achieved using mpc, the command line interface to MPD.

GDM users can then add Template:Codeline to Template:Filename (be sure to add it before Template:Codeline):

Non-GDM users can use their own login manager's method to launch the line at logout.


Sometimes, when using other audio outputs, e.g: some web pages containing Flash applets, MPD is rendered unable to play (until it is restarted). The error comes up in mpd's log:

Error opening alsa device "hw:0,0": Device or resource busy

Reasons for this may be:

  • The sound card does not support hardware mixing (uses dmix plugin)
  • An application does not work with ALSA's default settings

For a detailed description, it is recommended to take a look at this link.

This problem may be solved by adding the following lines to Template:Filename: Template:File

To make the changes have effect, restart mpd (e.g. Template:Codeline, if it is a global configuration).

High CPU usage with ALSA

When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.

For most users the problem should be solved by telling MPD not to use resampling by adding Template:Codeline into audio_output-part of Template:Filename. This will degrade quality slightly, however.


Although it may not give as drastic a speedup, enabling mmap may still speed things up: Template:File

Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found on the MPD wiki

Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once

Why these formats? Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least Template:Filename is not changed this way.

What's the downside? These settings cause everything (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.

The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential Template:Filename — which MPD as its own user ignores, therefore the following should go to Template:Filename:



Note: MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the format line only comes after that.)

If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the dmix.format line and change the one for mpd with format to "44100:*:2".

Note: Crossfading between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.

Control MPD with lirc

There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.

It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.

First of all, please setup your remotes as referred to the Lirc article.

Edit your favored lirc startup configuration file, default location is Template:Filename.

Fill the file with the following pattern:

     prog = irexec
     button = <button_name>
     config = <command_to_run>
     repeat = <0 or 1>

An useful example:

## irexec
     prog = irexec
     button = play_pause
     config = mpc toggle
     repeat = 0

     prog = irexec
     button = stop
     config = mpc stop
     repeat = 0
     prog = irexec
     button = previous
     config = mpc prev
     repeat = 0
     prog = irexec
     button = next
     config = mpc next
     repeat = 0
     prog = irexec
     button = volup
     config = mpc volume +2
     repeat = 1
     prog = irexec
     button = voldown
     config = mpc volume -2
     repeat = 1
     prog = irexec
     button = pbc
     config = mpc random
     repeat = 0
     prog = irexec
     button = pdvd
     config = mpc update
     repeat = 0
     prog = irexec
     button = right
     config = mpc seek +00:00:05
     repeat = 0
     prog = irexec
     button = left
     config = mpc seek -00:00:05
     repeat = 0
     prog = irexec
     button = up
     config = mpc seek +1%
     repeat = 0
     prog = irexec
     button = down
     config = mpc seek -1%
     repeat = 0

There are more functions for mpc, run Template:Codeline for more info.

Control MPD with bluetooth phone

You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:

  • install remuco -- a wireless remote control for several Linux media players (aur)
  • transfer remuco client -- jar/jad files from Template:Filename to your phone and install it
  • run Template:Codeline (as current user)
  • run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities

More information about remuco including troubleshooting to be found at its homepage

MPD & PulseAudio

Edit Template:Filename, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.

Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.

# gpasswd -a mpd pulse-access
# gpasswd -a mpd pulse-rt

Lastly, you may or may not need to copy Template:Filename from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be Template:Filename if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.

Cue Files

To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:

  • remove libcdio temporary (pacman -Rdd libcdio)
  • install libcue (pacman -S libcue)
  • install mpd with abs or from aur.
  • reinstall libcdio (pacman -S libcdio)

At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230) Once this patch is merged into mpd, i will remove this line :)

HTTP Streaming

Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD. To activate this server simply set it as output device in mpd.conf:

audio_output {    
	type		"httpd"    
	name		"My HTTP Stream"    
	encoder		"vorbis"		# optional, vorbis or lame    
	port		"8000"    
#	quality		"5.0"			# do not define if bitrate is defined    
	bitrate		"128"			# do not define if quality is defined    
	format		"44100:16:1"    

Then to listen to this stream simply open the URL of your mpd server (along with the specified port) in your favorite music player. Note: You may have to specify the file format of the stream using an appropriate file extension in the URL. For example, using Winamp 5.5, You would use rather than

To use mpd to connect to the stream from another computer.

mpc add


Autodetection failed

During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied Template:Filename over from Template:Filename as mentioned above, you can simply uncomment:

Example for alsa output type and alsa mixer:

audio_output {
	type			"alsa"
	name			"My ALSA Device"
	device			"hw:0,0"	# optional
	format			"44100:16:2"	# optional
	mixer_type		"hardware"
	mixer_device		"default"
	mixer_control		"PCM"

Note: in case of permission problems when using ESD with MPD run this as root:

# chsh -s /bin/true mpd

Executable permissions

Warning: This is not good security practice and may be unnecessary.

MPD needs to have +x permissions on ALL parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music.

# chmod a+x /home/$USER
# chmod -R a+X /home/$USER/music

Alternative solution

An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.

# chmod -R g-rwx /home/$USER
# chmod g+rx /home/$USER
# chmod -R g+rX /home/$USER/music

Another alternative solution

Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.

# mkdir /var/lib/mpd/music
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab
# mount -a
# /etc/rc.d/mpd restart

And that should fix the problem. See also the forum thread.

Avoiding timeouts

To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase Template:Codeline option in Template:Filename.

If files and/or titles are shown in wrong encoding, uncomment and change Template:Codeline and Template:Codeline options. Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use external tag readers.

If you want to use another computer to control MPD over a network, the Template:Codeline option in Template:Filename will need to be set to either your IP address, or Template:Codeline if your IP address changes frequently.

With the latest version of MPD (0.15), built-in httpd streaming is now available.

To activate this feature, you'll just need to add a new output of type httpd in Template:Filename:

audio_output {
          type   "httpd"
          name   "What you want"
          encoder "lame"     # vorbis or lame supported
          port    "8000"
          bitrate  "128"
          format   "44100:16:2"  # change 2 to 1 for mono

Restart the mpd daemon and, from another computer, simply load the stream as any other url.

$ mplayer http://<server's IP>:8000
Note: You must open the port on your router / firewall for the stream to be connectible to from another computer.

Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.

This is a nice clean way to replace your current icecast setup with something natively supported within MPD.

mpd hangs on first startup

This is a common error that's caused by corrupt mp3 tags. Here is an experimental way to solve this issue. Requirements:

  • kid3
  • easytag

This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.

Easy Tag

The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar. Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.


Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.

Repeat this procedure until your music library is done.

Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution

Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is disable IPv6 or add line to /etc/hosts

::1 localhost.localdomain localhost

Other issues when attempting to connect to mpd with a client

Some have reported being unable to access mpd with various clients, for example seeing errors like these:

$ ncmpcpp
Cannot connect to mpd: Connection closed by the server
$ sonata
2011-02-13 18:33:05  Connection lost while reading MPD hello
2011-02-13 18:33:05  Not connected
2011-02-13 18:33:05  Not connected

Please see posts on ncmpcpp on the Arch Forums HERE and HERE. Also see the Arch bug report on this issue HERE.

First fix

Check Template:Filename for a line like Template:Codeline and remove it. The mpd error file is deprecated and has been removed.

Second fix

Note: I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.

If that doesn't help, add the following to Template:Filename:

 bind_to_address ""
 port "6600"

Afterwards, instruct your client to connect via For example, add the following to the ncmpcpp config file:

 mpd_host ""
 mpd_port "6600"

Port 6600 already in use

MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.

If port 6600 is tied up for some other reason, one can use the following command to find the offending process:

# netstat -tulpan | grep 6600

This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).

If you need to restart mpd for whatever reason, use:
 $ mpd --kill
 $ mpd 

A more brute-force approach:

 $ killall mpd
 $ mpd 
Note: If you typically run MPD as root, you will need to run the above commands as root.

In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to Template:File to enable it.

Binding to IPV6 before IPV4

If on startup, you see this message:

listen: bind to '' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)

MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:

bind_to_address ""

Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:

bind_to_address ""
bind_to_address ""

Crackling sound with some audio files

This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:


This is usually a sane value for most mp3 files.

daemon: cannot setgid for user "mpd": Operation not permitted

The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.

To solve the issue, simply start mpd as root. Template:Cli or Template:Cli

External links