Difference between revisions of "Music Player Daemon"

From ArchWiki
Jump to: navigation, search
m (quick sed line to help convert default /etc/mpd.conf to work with local user)
m (Console: sorting)
 
(261 intermediate revisions by 75 users not shown)
Line 1: Line 1:
[[Category:Player]]
+
[[Category:Music]]
[[Category:Daemons and system services]]
 
 
[[de:Music Player Daemon]]
 
[[de:Music Player Daemon]]
 
[[es:Music Player Daemon]]
 
[[es:Music Player Daemon]]
 
[[fr:MPD]]
 
[[fr:MPD]]
 
[[it:Music Player Daemon]]
 
[[it:Music Player Daemon]]
 +
[[ja:Music Player Daemon]]
 
[[nl:Music Player Daemon]]
 
[[nl:Music Player Daemon]]
 
[[pl:Music Player Daemon]]
 
[[pl:Music Player Daemon]]
 
[[ru:Music Player Daemon]]
 
[[ru:Music Player Daemon]]
 
[[sr:Music Player Daemon]]
 
[[sr:Music Player Daemon]]
[[tr:Music_Player_Daemon]]
+
[[zh-hans:Music Player Daemon]]
[[zh-CN:Music Player Daemon]]
+
{{Related articles start}}
{{Article summary start}}
+
{{Related|MPD/Tips and Tricks}}
{{Article summary text|Installation, configuration and basic troubleshooting of MPD.}}
+
{{Related|MPD/Troubleshooting}}
{{Article summary heading|Required software}}
+
{{Related articles end}}
{{Article summary link|Music Player Daemon|http://mpd.wikia.com}}
 
{{Article summary heading|Related Articles}}
 
{{Article summary wiki|MPD/Tips and Tricks}}
 
{{Article summary wiki|MPD/Troubleshooting}}
 
{{Article summary heading|Other sources}}
 
{{Article summary text|[[Wikipedia:MPD|Wikipedia article]]}}
 
{{Article summary end}}
 
  
'''MPD''' ('''m'''usic '''p'''layer '''d'''aemon) is an audio player that has a server-client architecture.  It plays audio files, organizes playlists and maintains a music database all while using  very few resources. In order to interface with it, a separate [[#Clients|client]] is needed.
+
'''[http://www.musicpd.org/ MPD]''' (music player daemon) is an audio player that has a server-client architecture.  It plays audio files, organizes playlists and maintains a music database, all while using  very few resources. In order to interface with it, a separate [[#Clients|client]] is needed.
  
 
== Installation ==
 
== Installation ==
=== Stable version ===
 
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].
 
  
You may also want to install [https://github.com/GutenYe/systemd-units/tree/master/mpd mpd-systemd].
+
[[Install]] the {{Pkg|mpd}} package, or {{AUR|mpd-git}} for the development version.
  
=== Git version ===
+
== Configuration ==
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.
 
  
== Setup ==
+
MPD is able to run in [[#Per-user configuration]] or [[#System-wide configuration]] mode (settings apply to all users). Also it is possible to run multiple instances of MPD in a [[#Multi-MPD setup]].
MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances.
+
The way of setting up MPD depends on the way it is intended to be used: a local per-user configuration is easier to setup and may prove more adapted on a desktop system.
The way of setting up mpd depends on the way it is intended to be used.
 
A local configuration may prove more useful on a desktop system than on a system that is used by several people simultaneously.
 
  
For a comfortable use, it is sensible to provide MPD access to the following files and directories:
+
In order for MPD to be able to playback audio, [[ALSA]], optionally with [[PulseAudio]], must be setup and working. The [[#Audio configuration]] section thereafter describes the parameters needed for ''ALSA'' or ''PulseAudio''.
* 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]], [[PulseAudio]] or [[OSS]] needs to be setup and working.
+
MPD is configured in the file {{man|5|mpd.conf}} which can be located in various paths depending on the setup chosen (system-wide or per-user). In short, the two common locations used are:
 +
# {{ic|~/.config/mpd/mpd.conf}} in per-user configuration mode, this is the first location searched,
 +
# {{ic|/etc/mpd.conf}} in system-wide configuration.
  
=== Global Configuration ===
+
For indication, some of the most commonly used configuration options are listed thereafter:
{{Note|For user-specific permissions, change the "user" line above to reflect one of the system users.}}
+
* {{ic|pid_file}} -  The file where MPD stores its process ID
{{Warning|Users of PulseAudio with a local mpd have to implement a [[Music Player Daemon/Tips and Tricks#Local (with separate mpd user)|workaround]] in order to run mpd as its own user!}}
+
* {{ic|db_file}} - The music database
 +
* {{ic|state_file}} - MPD's current state is noted here
 +
* {{ic|playlist_directory}} - The folder where playlists are saved into
 +
* {{ic|music_directory}} - The folder that MPD scans for music
 +
* {{ic|sticker_file}} - The sticker database
  
MPD comes with an example configuration file, available at {{ic|/usr/share/doc/mpd/mpdconf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values.
+
=== Per-user configuration ===
  
Normally,{{ic|/etc/mpd.conf}} is created when installing mpd. If not, copy the included example file to {{ic|/etc/mpd.conf}}.
+
MPD can be configured per-user. Running it as a normal user has the benefits of:
# cp /usr/share/doc/mpd/mpdconf.example /etc/mpd.conf
 
  
==== Editing mpd.conf ====
+
* Regrouping into one single directory {{ic|~/.config/mpd/}} (or any other directory under {{ic|$HOME}}) all the MPD configuration files.
The default Arch install keeps the setup in {{ic|/var/lib/mpd}} and uses "mpd" as default user.
+
* Avoiding unforeseen directory and file permission errors.
  
Edit {{ic|/etc/mpd.conf}} to reflect as such:
+
==== Configure the location of files and directories ====
{{hc|/etc/mpd.conf|
+
In user mode, the configuration is read from {{ic|$XDG_CONFIG_HOME/mpd/mpd.conf}}.
music_directory      "/home/user/music"
+
We will assume here {{ic|$XDG_CONFIG_HOME}} equals {{ic|~/.config}} which is the recommended [http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG base directory specification].
playlist_directory    "/var/lib/mpd/playlists"
+
 
db_file               "/var/lib/mpd/mpd.db"
+
To build the user configuration, the [https://raw.githubusercontent.com/MusicPlayerDaemon/MPD/master/doc/mpdconf.example MPD configuration example] included in the package is a good starting point, copy it using the following lines:
log_file             "/var/log/mpd/mpd.log"
+
 
pid_file             "/run/mpd/mpd.pid"
+
$ mkdir ~/.config/mpd
state_file           "/var/lib/mpd/mpdstate"
+
$ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf
user                  "mpd"
+
 
# bind_to_address       "127.0.0.1"
+
A good practice is to use this newly created {{ic|~/.config/mpd/}} directory to store, together with the configuration file, other MPD related files like the database or the playlists. The user must have read write access to this directory.
# port                  "6600"
+
 
 +
Then edit the configuration file in order to specify the required and optional files and directories:
 +
 
 +
{{hc|~/.config/mpd/mpd.conf|
 +
# Recommended location for database
 +
db_file           "~/.config/mpd/database"
 +
 
 +
# Logs to systemd journal
 +
log_file           "syslog"
 +
 
 +
# The music directory is by default the XDG directory, uncomment to amend and choose a different directory
 +
#music_directory    "~/music"
 +
 
 +
# Uncomment to refresh the database whenever files in the music_directory are changed
 +
#auto_update "yes"
 +
 
 +
# Uncomment to enable the functionalities
 +
#playlist_directory "~/.config/mpd/playlists"
 +
#pid_file           "~/.config/mpd/pid"
 +
#state_file         "~/.config/mpd/state"
 +
#sticker_file       "~/.config/mpd/sticker.sql"
 
}}
 
}}
Now change permissions for mpd to write to {{ic|/var/log/mpd/mpd.log}}, otherwise mpd will return an error when it is started. The best way is to make the {{ic|/var/log/mpd/mpd.log}} belong to the mpd [[Users and Groups#Group management|user]].
 
  # chown -R mpd /var/log/mpd 
 
also, run this to create the /run/mpd dir:
 
  # systemd-tmpfiles --create mpd.conf
 
To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:
 
  
{{hc|/etc/mpd.conf|
+
If playlists are enabled in the configuration, the specified playlist directory must be created:
mixer_type "software"
+
 
}}
+
$ mkdir ~/.config/mpd/playlists
 +
 
 +
MPD can now be started (an optional custom location for the configuration file can be specified):
 +
 
 +
$ mpd ''[config_file]''
 +
 
 +
In order to build the database file, ''MPD'' must scan into the {{ic|music_directory}} defined above. A MPD client is required to request this task, for example with {{pkg|mpc}} the command is:
 +
 
 +
$ mpc update
 +
 
 +
or alternatively one can set the option {{ic|auto_update}} to {{ic|"yes"}} in the configuration to refresh the database whenever files are changed in {{ic|music_directory}}.
 +
 
 +
==== Audio configuration ====
  
Users of [[PulseAudio]] will need to make the following modification:
+
If [[ALSA]] is used, '''autodetection''' of the default device should work out of the box without any particular setting. If not, the syntax for ALSA audio output definition is provided thereafter; the required {{ic|name}} parameter specifies a unique name for the audio output.
{{hc|/etc/mpd.conf|2=
+
The exact device as displayed using {{ic|aplay --list-pcm}} from the package {{pkg|alsa-utils}} can optionally be indicated with the {{ic|device}} option.
 +
{{hc|~/.config/mpd/mpd.conf|2=
 
audio_output {
 
audio_output {
         type                   "pulse"
+
         type         "alsa"
         name                   "pulse audio"
+
         name         "''ALSA sound card''"
 +
        # Optional
 +
        #device        "''iec958:CARD=Intel,DEV=0''"
 +
        #mixer_control "PCM"
 
}
 
}
 
}}
 
}}
  
Users of [[ALSA]] will want to have the following device definition, which allows software volume control in the MPD client to control the volume separately from other applications.
+
Users of [[PulseAudio]] will need to make the following modification:
{{hc|/etc/mpd.conf|2=
+
{{hc|~/.config/mpd/mpd.conf|2=
 
audio_output {
 
audio_output {
         type            "alsa"
+
         type            "pulse"
         name            "My Sound Card"
+
         name            "''pulse audio''"
        mixer_type      "software"      # optional
 
 
}
 
}
 
}}
 
}}
  
Changing the group that MPD runs as may result in errors like "output: Failed to open "My ALSA Device"" "[alsa]: Failed to open ALSA device "default": No such file or directory" "player_thread: problems opening audio device while playing "Song Name.mp3""
+
User will also have to edit {{ic|/etc/pulse/client.conf}} and change the {{ic|autospawn}} option to {{ic|yes}} in order to allow the MPD user to use ''pulseaudio''. It will be necessary to restart ''pulseaudio'' after making this modification.
 
 
This is because by default MPD runs as member of '''audio''' group and the sound devices under {{Ic|/dev/snd/}} are owned by this group, so add user {{Ic|mpd}} to group {{Ic|audio}}.
 
# gpasswd -a mpd audio
 
  
===== Music directory =====
+
==== Autostart with systemd ====
MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection (ie. if it's located outside of "mpd" home directory {{ic|/var/lib/mpd}}). By default useradd sets permissions on home directories to {{ic|1700 drwx------}}. Thus users will most likely need to remount the music directory under a directory that mpd has access to -- this only applies if running as the 'mpd' user.
 
  
# mkdir /var/lib/mpd/music
+
The {{Pkg|mpd}} package provides a [[systemd/User|user service]] file. The service starts the process as user, there is no need to change permission nor use the {{ic|user}} and {{ic|group}} variables in the MPD configuration file.
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab
 
# mount -a
 
# rc.d restart mpd
 
(systemd users should perform # systemctl restart mpd.service)
 
See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]
 
  
An additional solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.
+
[[start/enable]] the user unit {{ic|mpd.service}} (i.e. with the {{ic|--user}} flag).
# mkdir /var/lib/mpd/music
 
# ln -s MUSIC_FOLDER /var/lib/mpd/music/
 
# rc.d restart mpd
 
(systemd users should perform # systemctl restart mpd.service)
 
  
If the music collection is contained under multiple directories, create symbolic links under the main music directory in {{ic|/var/lib/mpd}}. Remember to set permissions accordingly on the directories being linked.
+
{{Note|The configuration file is read from {{ic|~/.config/mpd/mpd.conf}}, see [[systemd#Editing provided units]] if you would like to indicate a custom configuration file path.}}
  
==== Creating the required files ====
+
==== Autostart on tty login ====
Now, having finished configuring MPD, the files and directories for MPD to write in need to be created:
 
  
Create the directories and files specified in {{ic|/etc/mpd.conf}}:
+
To start MPD on login add the following to {{ic|~/.profile}} or another [[Autostarting|autostart file]]:
# mkdir -p /var/lib/mpd/playlists
 
# touch /var/lib/mpd/{mpd.db,mpdstate}
 
  
Usually the init-script should properly create {{ic|/run/mpd/}} when starting. The deamon will use this directory to create {{ic|mpd.pid}} in it. However, when running mpd as a different user, requires an update to the tmpfiles.d: In {{ic|/usr/lib/tmpfiles.d/mpd.conf}}:
+
# MPD daemon start (if no other user instance exists)
Change:
+
  [ ! -s ~/.config/mpd/pid ] && mpd
d /run/mpd 0755 mpd mpd
 
to:
 
d /run/mpd 0755 ''username'' ''groupname''
 
  
Change the file's permissions so that the daemon can modify them.
+
==== Scripted configuration ====
# chown -R mpd /var/lib/mpd
 
  
==== Create database ====
+
The following tool provides assistance for MPD configuration:
Creating the database is now accomplished via the update feature of the client, for example {{ic|mpc update}}. You'll need to install the mpc package for this. It is in the official repositories
 
{{Box RED | Note: | Creating the MPD database as root using {{ic|# mpd --create-db}} is deprecated.}}
 
  
==== Timeline of MPD startup ====
+
* {{App|[http://lacocina.nl/audiophile-mpd mpd-configure]|Create a MPD configuration optimized for [https://www.musicpd.org/doc/user/advanced_usage.html#bit_perfect bit perfect] audio playback, without any resampling or conversion, using the ALSA interface hardware address (hw:x,y)|https://github.com/ronalde/mpd-configure|no package}}
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 listed here:
 
  
# MPD is started on boot by {{ic|/etc/rc.conf}}, by including it in the {{ic|DAEMONS}} array. (Or, this can be done manually each session by running {{ic|rc.d start mpd}} with root privileges).
+
=== System-wide configuration ===
# Since MPD is now started as root, it first reads the {{ic|/etc/mpd.conf}} file.
 
# MPD reads the user variable in the {{ic|/etc/mpd.conf}} file, and changes from root to this user.
 
# MPD then reads the contents of the {{ic|/etc/mpd.conf}} file and configures itself accordingly.
 
  
Notice that MPD changes the running user from root to the one named in the {{ic|/etc/mpd.conf}} file.
+
{{Note|Users of PulseAudio with a system-wide MPD configuration have to implement a [[Music Player Daemon/Tips and tricks#Local (with separate mpd user)|workaround]] in order to run MPD as its own user!}}
This way, uses of {{ic|~}} 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 {{ic|~}} to {{ic|/home/username}} to avoid any confusion over this aspect of MPD's behavior.
 
  
=== Local Configuration (per user) ===
+
The default {{ic|/etc/mpd.conf}} keeps the setup in {{ic|/var/lib/mpd}} which is assigned to user as well as primary group MPD.
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 {{ic|/var}} directory).
 
  
A less used (but perhaps more sensible) method is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:
+
==== Music directory ====
  
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/username}}) that will contain all the MPD configuration files.
+
The music directory is defined by the option {{ic|music_directory}} in the configuration file {{ic|/etc/mpd.conf}}.
* Easier to avoid unforeseen read/write permission errors.
 
  
{{Note|This approach will not work with multiple users to having access to MPD at the same time.}}
+
MPD needs to have execute permission on ''all'' parent directories of the music collection and also read access to all directories containing music files. This may conflict with the default configuration of the user directory, like {{ic|~/Music}}, where the music is stored.
  
Begin the setup by creating a directory for the required files and the playlists:
+
While there are several solutions to this issue, one of these should be most practical:
 +
* Switch to the [[#Per-user configuration]] mode instead
 +
* Add the {{ic|mpd}} user to the user's group and grant group execute permission to the user directory. This way the {{ic|mpd}} user has permission to open the user directory:
 +
# gpasswd -a mpd ''user_group''
 +
$ chmod 710 /home/''user_directory''
 +
* Store the music collection in a different path, either:
 +
** by moving it entirely,
 +
** with a bind mount,
 +
** or with [[Btrfs#Subvolumes]] (you should make this change persistent with an entry to {{ic|/etc/fstab}} ).
  
{{bc|mkdir -p ~/.mpd/playlists}}
+
The MPD configuration file must define only one music directory. If the music collection is contained under multiple directories, create symbolic links under the main music directory in {{ic|/var/lib/mpd}}. Remember to set permissions accordingly on the directories being linked.
  
Copy the contents of the default MPD configuration file in {{ic|/usr/share/mpd/mpd.conf.example}} to the target user's home directory:
+
==== Start with systemd ====
  
{{bc|cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf}}
+
MPD can be controlled with {{ic|mpd.service}} [[systemd#Using units|using systemd]]. The first startup can take some time as MPD will scan your music directory.
  
Create all of the requisite files:
+
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!
  
{{bc|<nowiki>touch ~/.mpd/{mpd.db,mpd.log,mpd.pid,mpdstate}</nowiki>}}
+
===== Socket activation =====
  
Edit {{ic|~/.mpdconf}} to specify these files:
+
{{Pkg|mpd}} provides a {{ic|mpd.socket}} unit. If {{ic|mpd.socket}} is enabled (and {{ic|mpd.service}} is disabled), systemd will not start MPD immediately, it will just listen to the appropriate sockets. Then, whenever an MPD client attempts to connect to one of these sockets, systemd will start {{ic|mpd.service}} and transparently hand over control of these ports to the MPD process.
  
{{hc|~/.mpdconf|
+
If you prefer to listen to different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen to network ports at all, [[edit]] the {{ic|mpd.socket}} unit appropriately '''and''' modify {{ic|/etc/mpd.conf}} to match the configuration (see {{man|5|mpd.conf}} for details).
music_directory    "/home/USER/music"            # Keep commented if your XDG directory already points to it
 
playlist_directory "/home/USER/.mpd/playlists"
 
db_file            "/home/USER/.mpd/mpd.db"
 
log_file          "/home/USER/.mpd/mpd.log"
 
pid_file          "/home/USER/.mpd/mpd.pid"
 
state_file        "/home/USER/.mpd/mpdstate"
 
}}
 
  
or you can use
+
==== User id startup workflow ====
{{bc|sed "s/var\/lib\/mpd\/music/home\/$USER\/music/;
+
MPD should never run as ''root'', you may use the {{ic|user}} option in the configuration to make MPD change its user id after initialization. Do not use this option if you start MPD as an unprivileged user.
    s/var\/lib\/mpd/home\/$USER\/.mpd/;
+
To describe how MPD drops its superuser privileges and switch to those of the user set in the configuration, the steps of a normal MPD startup are listed thereafter:
    s/var\/run\/mpd/home\/$USER\/.mpd/;
 
    s/var\/log\/mpd/home\/$USER\/.mpd/" /etc/mpd.conf > ~/.mpd/mpd.conf}}
 
  
MPD can now be started by typing {{ic|mpd}} on the command line.
+
# Since MPD is started as ''root'' by systemd, it first reads the {{ic|/etc/mpd.conf}} file.
 +
# MPD reads the {{ic|user}} variable in the configuration, and changes from ''root'' to this user.
 +
# MPD then reads the rest of the configuration file and configures itself accordingly. Uses of {{ic|~}} in the configuration file points to the home user's directory, and not root's directory.
  
To have MPD start with the X server add it to [[xprofile]].
+
=== Multi-MPD setup ===
  
==== Start MPD per user with systemd ====
+
==== Running an icecast server ====
  
As recommanded above, it is best to use MPD as a service per user. In this case, we will use {{ic|~/.mpd/mpd.conf}} and not start mpd.service as a daemon for the whole system and all users.
+
For a second MPD (e.g., with icecast output to share music over the network) using the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{ic|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{ic|mpd-icecast.log}}, {{ic|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second MPD would use the same music collection as the first one e.g., creating and editing a playlist under the first daemon would affect the second daemon as well.  Users do not have to create the same playlists all over again for the second daemon.  Call this second daemon the same way from {{ic|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with the first MPD daemon).
We will NOT use the {{ic|/usr/lib/systemd/sytsem/mpd.service}} which is intended to start the mpd.service as root and for all users.
 
If you already enabled it, just disable it first:
 
{{bc| # systemctl disable mpd.service}}
 
  
If you used to start mpd inside your {{ic|~/.xinitrc}}, comment or delete the line
+
==== Satellite setup ====
{{bc|mpd ~/.mpdconf}}
 
  
Then, edit a new file /etc/systemd/user/mpd.service
+
The method above works, but at least in theory could lead to issues with the database, when both MPD instances try to write to the same database file. MPD has a [http://www.musicpd.org/doc/user/advanced_config.html#satellite satellite mode] where one instance can receive the database from an already running MPD instance.
{{hc|/etc/systemd/user/mpd.service|
 
[Unit]
 
Description &#61; Music Player Daemon
 
  
[Service]
+
in your config-icecast add this, where host and port reflect your primary MPD server.
ExecStart &#61; /usr/bin/mpd --no-daemon
 
Restart &#61; always
 
  
[Install]
+
{{bc|
WantedBy &#61; default.target
+
database {
 +
    plugin "proxy"
 +
    host "localhost"
 +
    port "6600"
 +
}
 
}}
 
}}
  
Then, add this line to [[xinitrc|.xinitrc]]
+
== Clients ==
{{hc|~/.xinitrc|
 
#run systemd as user intsance
 
systemd --user &
 
}}
 
  
Log out, log in your xsession.
+
A separate client is needed to control MPD. See a long list of clients at the [https://www.musicpd.org/clients/ mpd website]. Popular options are:
Let's first check mpd is not running. If yes, just kill it
 
{{bc|$ ps -ef &#124; grep mpd}}
 
  
Now, enable and start mpd.service as per user
+
=== Console ===
$ systemctl --user enable mpd
 
$ systemctl --user start mpd
 
 
 
Check the mpd status and see if mpd.service is correctly enabled and started
 
{{bc|$ systemctl --user status mpd}}
 
 
 
==== 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 [http://karif.server-speed.net/~carnager/mpdsetup.tar here].
 
  
=== Multi-mpd setup ===
+
* {{App|clerk|MPD client using rofi.|https://github.com/carnager/clerk|{{AUR|clerk}}}}
'''Useful if running an icecast server.'''
+
* {{App|FMUI|Console user interface created with fzf and mpc.|https://github.com/seebye/fmui|{{AUR|fmui-git}}}}
 +
* {{App|mpc|Command line user interface for MPD server.|http://www.musicpd.org/clients/mpc/|{{Pkg|mpc}}}}
 +
* {{App|ncmpc|Ncurses client for MPD.|http://www.musicpd.org/clients/ncmpc/|{{Pkg|ncmpc}}}}
 +
* {{App|[[ncmpcpp]]|Almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine).|http://ncmpcpp.rybczak.net/|{{Pkg|ncmpcpp}}}}
 +
* {{App|ncmpy|Curses-based MPD client written in Python.|http://ncmpcpp.rybczak.net/|{{AUR|ncmpy}}}}
 +
* {{App|nncmpp|Yet another MPD client. It is in effect a simplified TUI version of Sonata.|http://ncmpcpp.rybczak.net/|{{AUR|nncmpp-git}}}}
 +
* {{App|pms|Highly configurable and accessible ncurses client written in Go.|https://ambientsound.github.io/pms/|{{AUR|pmus-git}}}}
 +
* {{App|vimpc|Ncurses based MPD client with vi-like key bindings.|https://github.com/boysetsfrog/vimpc|{{AUR|vimpc-git}}}}
  
For a second MPD (e.g., with icecast output to share music over the network) using the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{ic|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{ic|mpd-icecast.log}}, {{ic|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd would use the same music collection as the first one e.g., creating and editing a playlist under the first daemon would affect the second daemon as well.  Users do not have to create the same playlists all over again for the second daemon.  Call this second daemon the same way from {{ic|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with the first mpd daemon).
 
 
== Clients ==
 
A separate client is needed to control mpd. Popular options are:
 
 
=== Console ===
 
*{{App|mpc|Simple KISS client. All basic functionality available|http://mpd.wikia.com/wiki/Client:Mpc|{{Pkg|mpc}}}}
 
*{{App|ncmpc|A NCurses client for mpd|http://mpd.wikia.com/wiki/Client:Ncmpc|{{Pkg|ncmpc}}}}
 
*{{App|ncmpcpp|An almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)|http://unkart.ovh.org/ncmpcpp/|{{Pkg|ncmpcpp}}}}
 
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}
 
 
=== Graphical ===
 
=== Graphical ===
*{{App|Ario|A very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}
 
*{{App|QmpdClient|A GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}
 
*{{App|Sonata|An elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}
 
*{{App|gmpc|GNOME Client|http://gmpc.wikia.com/wiki/Gnome_Music_Player_Client|{{Pkg|gmpc}}}}
 
*{{App|Dmpc|Dmenu-based MPC client with a playlist manager and state-saving on playlist changes|http://wintervenom.mine.nu/|{{AUR|dmpc}}}}
 
  
=== Web ===
+
* {{App|Ario|Very feature-rich GTK3 GUI client for MPD, inspired by [[Rhythmbox]].|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}
*{{App|Patchfork|web client for MPD written in PHP and Ajax|http://mpd.wikia.com/wiki/Client:Pitchfork|{{AUR|patchfork-git}}}}.
+
* {{App|Cantata|High-feature, Qt4, Qt5 or KDE client for MPD with very configurable interface.|https://github.com/CDrummond/cantata|{{Pkg|cantata}}}}
 +
* {{App|GMPC|Gnome Music Player Client. GTK+ frontend for MPD. It is designed to be lightweight and easy to use, while providing full access to all of MPD's features. Users are presented with several different methods to browse through their music. It can be extended by plugins, of which many are available.|http://gmpclient.org/|{{Pkg|gmpc}}}}
 +
* {{App|pymp'd|A GTK+ front end client for the music playing daemon MPD.|http://pympd.sourceforge.net|{{Pkg|pympd}}}}
 +
* {{App|QMPDClient|Qt4 GUI client.|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}
 +
* {{App|Quimup|Simple Qt5 frontend for MPD written in C++.|https://sourceforge.net/projects/quimup/|{{AUR|quimup}}}}
 +
* {{App|RompЯ|Web client for MPD.|https://fatg3erman.github.io/RompR/|{{AUR|rompr}}}}
 +
* {{App|SkyMPC|Simple MPD client, powered by Qt5.|https://github.com/soramimi/SkyMPC|{{AUR|skympc-git}}}}
 +
* {{App|Sonata|Elegant Python GTK+ client.|http://www.nongnu.org/sonata/|{{Pkg|sonata}}}}
 +
* {{App|Xfce MPD Panel Plugin|MPD plugin for [[Xfce]]4 panel.|http://goodies.xfce.org/projects/panel-plugins/xfce4-mpc-plugin|{{Pkg|xfce4-mpc-plugin}}}}
 +
* {{App|Xfmpc|Graphical GTK+ MPD client focusing on low footprint.|http://goodies.xfce.org/projects/applications/xfmpc|{{Pkg|xfmpc}}}}
 +
* {{App|ympd|Standalone MPD Web GUI written in C, utilizing Websockets and Bootstrap/JS.|https://ympd.org/|{{AUR|ympd}}}}
  
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].
+
== See also ==
  
== External links ==
+
* [http://forum.musicpd.org/ MPD Forum]
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]
+
* [http://www.musicpd.org/doc/user/ MPD User Manual]
* [http://www.musicpd.org/forum/ MPD forum]
+
* [[Wikipedia:Music Player Daemon|Wikipedia article]]
 +
* [https://github.com/MusicPlayerDaemon/MPD GitHub repository]
 +
* {{Pkg|mopidy}} is an alternative to MPD written in Python. Note it is not a complete MPD replacement, its advantage is that it has plug-ins for playing music from cloud services like Spotify, SoundCloud, and Google Play Music. However, the project is not that active and some of its plugins are not maintained.

Latest revision as of 16:59, 19 June 2018

MPD (music player daemon) is an audio player that has a server-client architecture. It plays audio files, organizes playlists and maintains a music database, all while using very few resources. In order to interface with it, a separate client is needed.

Installation

Install the mpd package, or mpd-gitAUR for the development version.

Configuration

MPD is able to run in #Per-user configuration or #System-wide configuration mode (settings apply to all users). Also it is possible to run multiple instances of MPD in a #Multi-MPD setup. The way of setting up MPD depends on the way it is intended to be used: a local per-user configuration is easier to setup and may prove more adapted on a desktop system.

In order for MPD to be able to playback audio, ALSA, optionally with PulseAudio, must be setup and working. The #Audio configuration section thereafter describes the parameters needed for ALSA or PulseAudio.

MPD is configured in the file mpd.conf(5) which can be located in various paths depending on the setup chosen (system-wide or per-user). In short, the two common locations used are:

  1. ~/.config/mpd/mpd.conf in per-user configuration mode, this is the first location searched,
  2. /etc/mpd.conf in system-wide configuration.

For indication, some of the most commonly used configuration options are listed thereafter:

  • pid_file - The file where MPD stores its process ID
  • db_file - The music database
  • state_file - MPD's current state is noted here
  • playlist_directory - The folder where playlists are saved into
  • music_directory - The folder that MPD scans for music
  • sticker_file - The sticker database

Per-user configuration

MPD can be configured per-user. Running it as a normal user has the benefits of:

  • Regrouping into one single directory ~/.config/mpd/ (or any other directory under $HOME) all the MPD configuration files.
  • Avoiding unforeseen directory and file permission errors.

Configure the location of files and directories

In user mode, the configuration is read from $XDG_CONFIG_HOME/mpd/mpd.conf. We will assume here $XDG_CONFIG_HOME equals ~/.config which is the recommended XDG base directory specification.

To build the user configuration, the MPD configuration example included in the package is a good starting point, copy it using the following lines:

$ mkdir ~/.config/mpd
$ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf

A good practice is to use this newly created ~/.config/mpd/ directory to store, together with the configuration file, other MPD related files like the database or the playlists. The user must have read write access to this directory.

Then edit the configuration file in order to specify the required and optional files and directories:

~/.config/mpd/mpd.conf
# Recommended location for database
db_file            "~/.config/mpd/database"

# Logs to systemd journal
log_file           "syslog"

# The music directory is by default the XDG directory, uncomment to amend and choose a different directory
#music_directory    "~/music"

# Uncomment to refresh the database whenever files in the music_directory are changed
#auto_update "yes"

# Uncomment to enable the functionalities
#playlist_directory "~/.config/mpd/playlists"
#pid_file           "~/.config/mpd/pid"
#state_file         "~/.config/mpd/state"
#sticker_file       "~/.config/mpd/sticker.sql"

If playlists are enabled in the configuration, the specified playlist directory must be created:

$ mkdir ~/.config/mpd/playlists

MPD can now be started (an optional custom location for the configuration file can be specified):

$ mpd [config_file]

In order to build the database file, MPD must scan into the music_directory defined above. A MPD client is required to request this task, for example with mpc the command is:

$ mpc update

or alternatively one can set the option auto_update to "yes" in the configuration to refresh the database whenever files are changed in music_directory.

Audio configuration

If ALSA is used, autodetection of the default device should work out of the box without any particular setting. If not, the syntax for ALSA audio output definition is provided thereafter; the required name parameter specifies a unique name for the audio output. The exact device as displayed using aplay --list-pcm from the package alsa-utils can optionally be indicated with the device option.

~/.config/mpd/mpd.conf
audio_output {
        type          "alsa"
        name          "ALSA sound card"
        # Optional
        #device        "iec958:CARD=Intel,DEV=0"
        #mixer_control "PCM"
}

Users of PulseAudio will need to make the following modification:

~/.config/mpd/mpd.conf
audio_output {
        type            "pulse"
        name            "pulse audio"
}

User will also have to edit /etc/pulse/client.conf and change the autospawn option to yes in order to allow the MPD user to use pulseaudio. It will be necessary to restart pulseaudio after making this modification.

Autostart with systemd

The mpd package provides a user service file. The service starts the process as user, there is no need to change permission nor use the user and group variables in the MPD configuration file.

start/enable the user unit mpd.service (i.e. with the --user flag).

Note: The configuration file is read from ~/.config/mpd/mpd.conf, see systemd#Editing provided units if you would like to indicate a custom configuration file path.

Autostart on tty login

To start MPD on login add the following to ~/.profile or another autostart file:

# MPD daemon start (if no other user instance exists)
[ ! -s ~/.config/mpd/pid ] && mpd

Scripted configuration

The following tool provides assistance for MPD configuration:

  • mpd-configure — Create a MPD configuration optimized for bit perfect audio playback, without any resampling or conversion, using the ALSA interface hardware address (hw:x,y)
https://github.com/ronalde/mpd-configure || no package

System-wide configuration

Note: Users of PulseAudio with a system-wide MPD configuration have to implement a workaround in order to run MPD as its own user!

The default /etc/mpd.conf keeps the setup in /var/lib/mpd which is assigned to user as well as primary group MPD.

Music directory

The music directory is defined by the option music_directory in the configuration file /etc/mpd.conf.

MPD needs to have execute permission on all parent directories of the music collection and also read access to all directories containing music files. This may conflict with the default configuration of the user directory, like ~/Music, where the music is stored.

While there are several solutions to this issue, one of these should be most practical:

  • Switch to the #Per-user configuration mode instead
  • Add the mpd user to the user's group and grant group execute permission to the user directory. This way the mpd user has permission to open the user directory:
# gpasswd -a mpd user_group
$ chmod 710 /home/user_directory
  • Store the music collection in a different path, either:
    • by moving it entirely,
    • with a bind mount,
    • or with Btrfs#Subvolumes (you should make this change persistent with an entry to /etc/fstab ).

The MPD configuration file must define only one music directory. If the music collection is contained under multiple directories, create symbolic links under the main music directory in /var/lib/mpd. Remember to set permissions accordingly on the directories being linked.

Start with systemd

MPD can be controlled with mpd.service using systemd. The first startup can take some time as MPD will scan your music directory.

Test everything by starting a client application (ncmpc is a light and easy to use client), and play some music!

Socket activation

mpd provides a mpd.socket unit. If mpd.socket is enabled (and mpd.service is disabled), systemd will not start MPD immediately, it will just listen to the appropriate sockets. Then, whenever an MPD client attempts to connect to one of these sockets, systemd will start mpd.service and transparently hand over control of these ports to the MPD process.

If you prefer to listen to different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen to network ports at all, edit the mpd.socket unit appropriately and modify /etc/mpd.conf to match the configuration (see mpd.conf(5) for details).

User id startup workflow

MPD should never run as root, you may use the user option in the configuration to make MPD change its user id after initialization. Do not use this option if you start MPD as an unprivileged user. To describe how MPD drops its superuser privileges and switch to those of the user set in the configuration, the steps of a normal MPD startup are listed thereafter:

  1. Since MPD is started as root by systemd, it first reads the /etc/mpd.conf file.
  2. MPD reads the user variable in the configuration, and changes from root to this user.
  3. MPD then reads the rest of the configuration file and configures itself accordingly. Uses of ~ in the configuration file points to the home user's directory, and not root's directory.

Multi-MPD setup

Running an icecast server

For a second MPD (e.g., with icecast output to share music over the network) using the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., /home/username/.mpd/config-icecast), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., mpd-icecast.log, mpd-icecast.error, and so on); using the same directory paths for the music and playlist directories would ensure that this second MPD would use the same music collection as the first one e.g., creating and editing a playlist under the first daemon would affect the second daemon as well. Users do not have to create the same playlists all over again for the second daemon. Call this second daemon the same way from ~/.xinitrc above. (Just be sure to have a different port number, so as to not conflict with the first MPD daemon).

Satellite setup

The method above works, but at least in theory could lead to issues with the database, when both MPD instances try to write to the same database file. MPD has a satellite mode where one instance can receive the database from an already running MPD instance.

in your config-icecast add this, where host and port reflect your primary MPD server.

database {
    plugin "proxy"
    host "localhost"
    port "6600"
}

Clients

A separate client is needed to control MPD. See a long list of clients at the mpd website. Popular options are:

Console

  • clerk — MPD client using rofi.
https://github.com/carnager/clerk || clerkAUR
  • FMUI — Console user interface created with fzf and mpc.
https://github.com/seebye/fmui || fmui-gitAUR
  • mpc — Command line user interface for MPD server.
http://www.musicpd.org/clients/mpc/ || mpc
  • ncmpc — Ncurses client for MPD.
http://www.musicpd.org/clients/ncmpc/ || ncmpc
  • ncmpcpp — Almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine).
http://ncmpcpp.rybczak.net/ || ncmpcpp
  • ncmpy — Curses-based MPD client written in Python.
http://ncmpcpp.rybczak.net/ || ncmpyAUR
  • nncmpp — Yet another MPD client. It is in effect a simplified TUI version of Sonata.
http://ncmpcpp.rybczak.net/ || nncmpp-gitAUR
  • pms — Highly configurable and accessible ncurses client written in Go.
https://ambientsound.github.io/pms/ || pmus-gitAUR
  • vimpc — Ncurses based MPD client with vi-like key bindings.
https://github.com/boysetsfrog/vimpc || vimpc-gitAUR

Graphical

  • Ario — Very feature-rich GTK3 GUI client for MPD, inspired by Rhythmbox.
http://ario-player.sourceforge.net/ || ario
  • Cantata — High-feature, Qt4, Qt5 or KDE client for MPD with very configurable interface.
https://github.com/CDrummond/cantata || cantata
  • GMPC — Gnome Music Player Client. GTK+ frontend for MPD. It is designed to be lightweight and easy to use, while providing full access to all of MPD's features. Users are presented with several different methods to browse through their music. It can be extended by plugins, of which many are available.
http://gmpclient.org/ || gmpc
  • pymp'd — A GTK+ front end client for the music playing daemon MPD.
http://pympd.sourceforge.net || pympd
  • QMPDClient — Qt4 GUI client.
http://bitcheese.net/wiki/QMPDClient || qmpdclient
  • Quimup — Simple Qt5 frontend for MPD written in C++.
https://sourceforge.net/projects/quimup/ || quimupAUR
  • RompЯ — Web client for MPD.
https://fatg3erman.github.io/RompR/ || romprAUR
  • SkyMPC — Simple MPD client, powered by Qt5.
https://github.com/soramimi/SkyMPC || skympc-gitAUR
  • Sonata — Elegant Python GTK+ client.
http://www.nongnu.org/sonata/ || sonata
  • Xfce MPD Panel Plugin — MPD plugin for Xfce4 panel.
http://goodies.xfce.org/projects/panel-plugins/xfce4-mpc-plugin || xfce4-mpc-plugin
  • Xfmpc — Graphical GTK+ MPD client focusing on low footprint.
http://goodies.xfce.org/projects/applications/xfmpc || xfmpc
  • ympd — Standalone MPD Web GUI written in C, utilizing Websockets and Bootstrap/JS.
https://ympd.org/ || ympdAUR

See also

  • MPD Forum
  • MPD User Manual
  • Wikipedia article
  • GitHub repository
  • mopidy is an alternative to MPD written in Python. Note it is not a complete MPD replacement, its advantage is that it has plug-ins for playing music from cloud services like Spotify, SoundCloud, and Google Play Music. However, the project is not that active and some of its plugins are not maintained.