Music Player Daemon: Difference between revisions

From ArchWiki
No edit summary
(→‎Configure the location of files and directories: Adding -p to mkdir, saving some (unwritten) steps)
 
(285 intermediate revisions by 73 users not shown)
Line 1: Line 1:
[[Category:Player]]
[[Category:Music]]
[[de:Music Player Daemon]]
[[de:Music Player Daemon]]
[[es:Music Player Daemon]]
[[fr:Music Player Daemon]]
[[fr:MPD]]
[[it:Music Player Daemon]]
[[ja:Music Player Daemon]]
[[ja:Music Player Daemon]]
[[nl:Music Player Daemon]]
[[zh-hans:Music Player Daemon]]
[[pl:Music Player Daemon]]
[[ru:Music Player Daemon]]
[[sr:Music Player Daemon]]
[[tr:Music_Player_Daemon]]
[[zh-CN:Music Player Daemon]]
{{Related articles start}}
{{Related articles start}}
{{Related|MPD/Tips and Tricks}}
{{Related|MPD/Tips and Tricks}}
{{Related|MPD/Troubleshooting}}
{{Related|MPD/Troubleshooting}}
{{Related articles end}}
{{Related articles end}}
'''[http://www.musicpd.org/ 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.
 
'''[https://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 ==


The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].
[[Install]] the {{Pkg|mpd}} package, or {{AUR|mpd-git}} for the development version.


Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.
== Configuration ==
{{Note|An alternative plug-in based implementation called [http://www.mopidy.com Mopidy] exists. It is available in the AUR as {{AUR|mopidy}} and {{AUR|mopidy-git}}. Be warned that is not a complete MPD [http://docs.mopidy.com/en/latest/ext/mpd/#limitations drop-in relacement].}}


== 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]].
The way of setting up MPD depends on the way it is intended to be used: a local per-user configuration is easier to set up and may prove more adapted on a desktop system. The system-wide setup might be better suited for a always-on audio server with multiple users but a shared MPD instance.


MPD is able to run locally (per user settings), globally (settings apply to all users), and in multiple instances. 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, for example.
In order for MPD to be able to playback audio, [[ALSA]], optionally with [[PulseAudio]] or [[PipeWire]], must be set up and working. The [[#Audio configuration]] section thereafter describes the parameters needed for ''ALSA'', ''PulseAudio'' or ''PipeWire''.


In order for MPD to be able to play back audio, [[ALSA]] or [[OSS]] (optionally with [[PulseAudio]]) 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.


MPD is configured in {{ic|mpd.conf}}. The location of this file depends on how you want to run MPD (see the sections below). These are commonly used configuration options:
These are some of the most commonly used configuration options:
* {{ic|pid_file}} -  The file where mpd stores its process ID
* {{ic|pid_file}} -  The file where MPD stores its process ID
* {{ic|db_file}} - The music database
* {{ic|db_file}} - The music database
* {{ic|state_file}} - MPD's current state is noted here
* {{ic|state_file}} - MPD's current state is noted here
* {{ic|playlist_directory}} - The folder where playlists are saved into
* {{ic|playlist_directory}} - The directory where playlists are saved into
* {{ic|music_directory}} - The folder that MPD scans for music
* {{ic|music_directory}} - The directory that MPD scans for music
* {{ic|sticker_file}} - The sticker database
* {{ic|sticker_file}} - The sticker database


{{Note|The files must already exist (the path is specified in the configuration file) with proper permissions, otherwise MPD will fail to start.}}
=== Per-user configuration ===
 
MPD can be configured per-user. Running it as a normal user has the benefits of:
 
* Regrouping into one single directory {{ic|~/.config/mpd/}} (or any other directory under {{ic|$HOME}}) all the MPD configuration files.
* Avoiding unforeseen directory and file permission errors.


=== Global configuration ===
==== Configure the location of files and directories ====


{{Warning|Users of PulseAudio with a global 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!}}
In user mode, the configuration is read from {{ic|$XDG_CONFIG_HOME/mpd/mpd.conf}}.
We will assume here {{ic|$XDG_CONFIG_HOME}} equals the [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html default] of {{ic|~/.config}}.


The default {{ic|/etc/mpd.conf}} keeps the setup in {{ic|/var/lib/mpd}} and uses ''mpd'' as default user. However, {{ic|/var/lib/mpd}} is owned by ''root'' by default, we need to change this so ''mpd'' can write here:
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:
# chown -R mpd /var/lib/mpd


Edit {{ic|/etc/mpd.conf}} and add a {{ic|music_directory}} line with the path to your music directory:
$ mkdir -p ~/.config/mpd
  music_directory /path/to/music
  $ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf


==== Music directory ====
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.


MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection.
Then edit the configuration file in order to specify the required and optional files and directories:


If the music directory is located outside of {{ic|/var/lib/mpd}}, you will most likely need to remount the music directory under a directory that the MPD user (''mpd'' by default) has access to:
{{hc|~/.config/mpd/mpd.conf|
# mkdir /var/lib/mpd/music
# Recommended location for database
# echo "/path/to/music/dir /var/lib/mpd/music none bind" >> /etc/fstab
db_file            "~/.config/mpd/database"
# mount -a
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this forum thread].


An additional solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.
# If running mpd using systemd, delete this line to log directly to systemd.
# mkdir /var/lib/mpd/music
log_file          "syslog"
# ln -s /path/to/music/dir /var/lib/mpd/music/


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.
# The music directory is by default the XDG directory, uncomment to amend and choose a different directory
#music_directory    "~/music"


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


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.
# Uncomment to enable the functionalities
#playlist_directory "~/.config/mpd/playlists"
#pid_file          "~/.config/mpd/pid"
#state_file        "~/.local/state/mpd/state"
#sticker_file      "~/.config/mpd/sticker.sql"
}}


Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!
If playlists are enabled in the configuration, the specified playlist directory must be created:


===== Socket activation =====
$ mkdir ~/.config/mpd/playlists


If the following {{ic|mpd.socket}} file is enabled while {{ic|mpd.service}} (provided by {{Pkg|mpd}}) is disabled, systemd will not start mpd immediately, but it will listen on the appropriate sockets. When an mpd client attempts to connect on one of those sockets, systemd will start {{ic|mpd.service}} and transparently hand over control of those ports to the mpd process.
If {{ic|state_file}} is set, the specified directory must be created:


If you prefer to listen on different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen on network ports at all, you should add/edit/remove the appropriate {{ic|1="ListenStream="}} lines in the {{ic|[Socket]}} section of {{ic|mpd.socket}} '''and''' modify the appropriate lines {{ic|/etc/mpd.conf}} (see {{ic|man 5 mpd.conf}} for details).
$ mkdir -p ~/.local/state/mpd


If you use different (even multiple) network or local sockets, or prefer not to use network sockets at all, simply add, change, or remove lines beginning with {{ic|1="ListenStream="}} in the {{ic|[Socket]}} section.
MPD can now be started (an optional custom location for the configuration file can be specified):


{{hc|/etc/systemd/system/mpd.socket|<nowiki>
$ mpd ''[config_file]''
[Unit]
Description=Music Player Daemon Sockets


[Socket]
In order to build the database file, MPD must scan into the {{ic|music_directory}} defined above. To request this task, one of the MPD [[#Clients|clients]] must be used. For example with ''mpc'' the command is:
ListenStream=/var/run/mpd/socket
ListenStream=6600


[Install]
$ mpc update
WantedBy=sockets.target
</nowiki>}}


==== Configure audio ====
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}}.


To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:
==== Audio configuration ====
{{hc|/etc/mpd.conf|
mixer_type "software"
}}


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.
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           "alsa"
         type         "alsa"
         name           "My Sound Card"
         name         "''ALSA sound card''"
         mixer_type      "software"     # optional
         # Optional
        #device        "''iec958:CARD=Intel,DEV=0''"
        #mixer_control "PCM"
}
}
}}
}}


Users of [[PulseAudio]] will need to make the following modification:
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            "pulse"
         type            "pulse"
         name            "pulse audio"
         name            "''pulse audio''"
}
}
}}
}}


PulseAudio supports multiple advanced operations, e.g. transferring the audio to a different machine. For advanced configuration with MPD see [http://mpd.wikia.com/wiki/PulseAudio Music Player Daemon Community Wiki].
Output with [[PipeWire]] can also be configured:
{{hc|~/.config/mpd/mpd.conf|2=
audio_output {
        type            "pipewire"
        name            "''PipeWire Sound Server''"
}
}}


==== Changing user ====
==== Autostart with systemd ====


Changing the group that MPD runs as may result in errors like {{ic|output: Failed to open "My ALSA Device"}}, {{ic|[alsa]: Failed to open ALSA device "default": No such file or directory}} or {{ic|player_thread: problems opening audio device while playing "Song Name.mp3"}}.
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.


This is because the MPD users need to be part of the ''audio'' group to access sound devices under {{Ic|/dev/snd/}}. To fix it add user make the MPD user part of the ''audio'' group:
[[Start/enable]] the user unit {{ic|mpd.service}} (i.e. with the {{ic|--user}} flag).
# gpasswd -a '''mpd''' audio


==== Timeline of MPD startup ====
{{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.}}


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:
==== Autostart on tty login ====


# Since MPD is started as root by systemd, it first reads the {{ic|/etc/mpd.conf}} file.
To start MPD on login add the following to {{ic|~/.profile}} or another [[Autostarting|autostart 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.
# MPD daemon start (if no other user instance exists)
This way, uses of {{ic|~}} in the configuration file point correctly to the home user's directory, and not root's directory.  
[ ! -s ~/.config/mpd/pid ] && mpd
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) ===
==== Scripted configuration ====


MPD can be configured per user (rather than the typical method of configuring MPD globally). Running MPD as a normal user has the benefits of:
The [https://gitlab.com/sonida/mpd-configure mpd-configure] tool creates 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).


* A single directory {{ic|~/.config/mpd/}} (or any other directory under {{ic|$HOME}}) that will contain all the MPD configuration files.
=== System-wide configuration ===
* Easier to avoid unforeseen read/write permission errors.


Good practice is to create a single directory for the required files and playlists. It can be any directory for which you have read and write access, e.g. {{ic|~/.config/mpd/}} or {{ic|~/.mpd/}}. This section assumes it is {{ic|~/.config/mpd/}}, which corresponds to the default value of {{ic|$XDG_CONFIG_HOME}} (part of [http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG Base Directory Specification]).
{{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!}}


MPD searches for a config file in {{ic|$XDG_CONFIG_HOME/mpd/mpd.conf}} and then {{ic|~/.mpdconf}}. It is also possible to pass other path as command line argument.
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.


Copy the example configuration file to desired location, for example:
==== Music directory ====
 
$ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf


Edit {{ic|~/.config/mpd/mpd.conf}} and specify the required files:
The music directory is defined by the option {{ic|music_directory}} in the configuration file {{ic|/etc/mpd.conf}}.


{{hc|~/.config/mpd/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 {{ic|~/Music}}, where the music is stored.
# Required files
db_file            "~/.config/mpd/database"
log_file          "~/.config/mpd/log"


# Optional
While there are several solutions to this issue, one of these should be most practical:
music_directory    "~/Music"
* Switch to the [[#Per-user configuration]] mode instead
playlist_directory "~/.config/mpd/playlists"
* 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:
pid_file          "~/.config/mpd/pid"
# gpasswd -a ''user_group'' mpd
state_file        "~/.config/mpd/state"
$ chmod 710 /home/''user_directory''
sticker_file      "~/.config/mpd/sticker.sql"
* 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}} ).


Create all the files and directories as configured above:
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.


$ mkdir ~/.config/mpd/playlists
To exclude a file - or files - from the update, create a file called {{ic|.mpdignore}} in its parent directory. Each line of that file may contain a list of shell wildcards. Matching files in the current directory and all subdirectories are then excluded from subsequent updates.
$ touch ~/.config/mpd/{database,log,pid,state,sticker.sql}


When the paths of required files are configured, MPD can be started. To specify custom location of the configuration file:
{{Note|MPD is capable of reading music files within some archive file formats, and will add those during an update if they are in the music directory; tar is known to be an exception.}}


$ mpd ''config_file''
==== Start with systemd ====


==== Autostart on tty login ====
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.


To start MPD on login add the following to {{ic|~/.profile}} (or another [[Autostarting#Shells|autostart file]]):
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!


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


==== Autostart in X ====
{{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.


If you use a [[Desktop environment|desktop environment]], place the following file in {{ic|~/.config/autostart/}}:
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).
{{hc|~/.config/autostart/mpd.desktop|<nowiki>
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=Music Player Daemon
Comment=Server for playing audio files
Exec=mpd
StartupNotify=false
Terminal=false
Hidden=false
X-GNOME-Autostart-enabled=false
</nowiki>}}


If you do not use a DE, place the line from [[#Autostart on tty login]] in your [[Autostarting#Graphical|autostart file]].
==== User id startup workflow ====


==== Autostart with systemd ====
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.
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:


{{Note|It is assumed that you already have systemd user-session manager running. See the [[systemd/User]] page for details.}}
# 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.


The package {{Pkg|mpd}} provides user service file in {{ic|/usr/lib/systemd/user/mpd.service}}. The configuration file is expected to exist either in {{ic|~/.mpdconf}} or {{ic|~/.config/mpd/mpd.conf}}, see [[systemd#Editing provided unit files]] if you would like to use different path. The process is not started as root, so you should not use the {{ic|user}} and {{ic|group}} variables in the MPD configuration file, the process already has user permissions and therefore it is not necessary to change them further.
=== Multi-MPD setup ===


All you have to do is enable and start the {{ic|mpd}} [[systemd/User#User Services|user service]].
==== Running an Icecast server ====


{{Note|
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 {{ic|log_file}}, {{ic|error_file}}, {{ic|pid_file}}, and {{ic|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 uses 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 - but be sure to have a different port number, avoiding a conflict with the first MPD daemon.
* {{Pkg|mpd}} provides also system service file in {{ic|/usr/lib/systemd/system/mpd.service}}, but as the process is started as root, it does not read the user configuration file and falls back to {{ic|/etc/mpd.conf}}. [[#Global configuration|Global configuration]] is described in other section.
* Make sure to disable every other method of starting mpd you used before.
}}
 
==== 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://dl.53280.de/mpdsetup.sh here].
 
=== 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., {{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).


==== Satellite setup ====
==== 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 [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.
The method described in [[#Running an Icecast server]] 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 concurrently. MPD has a [https://www.musicpd.org/doc/user/advanced_config.html#satellite 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.
In your {{ic|config-icecast}} add this, where host and port reflect your primary MPD server:


{{bc|
{{bc|
Line 240: Line 213:
== Clients ==
== Clients ==


A separate client is needed to control mpd. See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki]. Popular options are:
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:
 
=== Command-line ===
 
* {{App|mpc|Command line user interface for MPD server written in C.|https://www.musicpd.org/clients/mpc/|{{Pkg|mpc}}}}


=== Console ===
=== Console ===


*{{App|mpc|Command line user interface for MPD server|http://www.musicpd.org/clients/mpc/|{{Pkg|mpc}}}}
* {{App|clerk|MPD client using [[Rofi]].|https://github.com/carnager/clerk|{{AUR|clerk-git}}}}
*{{App|ncmpc|Ncurses client for mpd|http://www.musicpd.org/clients/ncmpc/|{{Pkg|ncmpc}}}}
* {{App|FMUI|Unmaintained console user interface created with [[fzf]] and mpc.|https://github.com/seebye/fmui|{{AUR|fmui-git}}}}
*{{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|ncmpc|Ncurses client for MPD written in C++.|https://www.musicpd.org/clients/ncmpc/|{{Pkg|ncmpc}}}}
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}
* {{App|[[ncmpcpp]]|Almost exact clone of ''ncmpc'', written in C++ with some additional features (tag editor, search engine).|https://rybczak.net/ncmpcpp/|{{Pkg|ncmpcpp}}}}
*{{App|vimpc|Ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}
* {{App|ncmpy|Curses-based MPD client written in Python.|https://repo.cykerway.com/ncmpy|{{AUR|ncmpy}}}}
* {{App|nncmpp|Yet another MPD client. It is in effect a simplified TUI version of Sonata.|https://git.janouch.name/p/nncmpp/|{{AUR|nncmpp-git}}}}
* {{App|pms|Highly configurable and accessible ncurses client written in Go.|https://ambientsound.github.io/pms/{{Dead link|2023|10|29|status=404}}|{{AUR|pmus-git}}}}
* {{App|vimpc|Ncurses based MPD client with vi-like key bindings.|https://github.com/boysetsfrog/vimpc|{{AUR|vimpc-git}}}}
* {{App|gomp|MPD client inspired by ncmpcpp with builtin cover-art view and LastFM integration.|https://github.com/aditya-K2/gomp|{{AUR|gomp-git}}}}
* {{App|mmtc|Minimal mpd terminal client that aims to be simple yet highly configurable.|https://github.com/figsoda/mmtc|{{AUR|mmtc}}}}


=== Graphical ===
=== Graphical ===


*{{App|Ario|Very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}
* {{App|Ario|Very feature-rich GTK3 GUI client for MPD, inspired by [[Rhythmbox]].|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}
*{{App|QmpdClient|GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}
* {{App|Cantata|Unmaintained high-feature, Qt5 client for MPD with very configurable interface.|https://github.com/CDrummond/cantata|{{AUR|cantata}}}}
*{{App|Sonata|Elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}
* {{App|CoverGrid|GTK3 GUI client focusing on albums instead of single tracks.|https://www.suruatoel.xyz/codes/mcg|{{AUR|mcg}}}}
*{{App|gmpc|GTK2 frontend for Music Player Daemon. 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://gmpc.wikia.com/wiki/Gnome_Music_Player_Client|{{Pkg|gmpc}}}}
* {{App|Plattenalbum|A modern and small GTK4 MPD client written in python.|https://github.com/SoongNoonien/plattenalbum|{{AUR|plattenalbum}}}}
*{{App|Cantata|High-feature, Qt4, Qt5 or KDE4 client for MPD with very configurable interface|https://code.google.com/p/cantata/|{{Pkg|cantata}}}}
* {{App|QMPDClient|Qt5 GUI client.|https://bitcheese.net/QMPDClient/|{{AUR|qmpdclient}}}}
 
* {{App|Quimup|Simple Qt5 frontend for MPD written in C++.|https://sourceforge.net/projects/quimup/|{{AUR|quimup}}}}
=== Web ===
* {{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|Patchfork|Web client for MPD written in PHP and Ajax|http://mpd.wikia.com/wiki/Client:Pitchfork|{{AUR|patchfork-git}}}}.
* {{App|Sonata|Elegant Python GTK client.|https://www.nongnu.org/sonata/|{{AUR|sonata-git}}}}
* {{App|Xfce MPD Panel Plugin|MPD plugin for [[Xfce]]4 panel.|https://goodies.xfce.org/projects/panel-plugins/xfce4-mpc-plugin|{{Pkg|xfce4-mpc-plugin}}}}
* {{App|Xfmpc|Graphical GTK MPD client focusing on low footprint.|https://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}}}}
* {{App|Ymuse|Easy, functional and snappy GTK front-end (client) for Music Player Daemon written in Go.|https://yktoo.com/en/software/ymuse/|{{AUR|ymuse}}}}


== See also ==
== See also ==


* [http://forum.musicpd.org/ MPD Forum]
* [https://forum.musicpd.org/ MPD Forum]
* [http://www.musicpd.org/doc/user/ MPD User Manual]
* [https://www.musicpd.org/doc/user/ MPD User Manual]
* [[Wikipedia:Music Player Daemon|Wikipedia article]]
* [[Wikipedia:Music Player Daemon|MPD Wikipedia article]]
* [https://github.com/MusicPlayerDaemon/MPD 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.

Latest revision as of 02:41, 12 March 2024

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 set up and may prove more adapted on a desktop system. The system-wide setup might be better suited for a always-on audio server with multiple users but a shared MPD instance.

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

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.

These are some of the most commonly used configuration options:

  • 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 directory where playlists are saved into
  • music_directory - The directory 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 the default of ~/.config.

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 -p ~/.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"

# If running mpd using systemd, delete this line to log directly to systemd.
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         "~/.local/state/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

If state_file is set, the specified directory must be created:

$ mkdir -p ~/.local/state/mpd

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. To request this task, one of the MPD clients must be used. 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"
}

Output with PipeWire can also be configured:

~/.config/mpd/mpd.conf
audio_output {
        type            "pipewire"
        name            "PipeWire Sound Server"
}

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 mpd-configure tool creates a MPD configuration optimized for bit perfect audio playback, without any resampling or conversion, using the ALSA interface hardware address (hw:x,y).

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 user_group mpd
$ 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.

To exclude a file - or files - from the update, create a file called .mpdignore in its parent directory. Each line of that file may contain a list of shell wildcards. Matching files in the current directory and all subdirectories are then excluded from subsequent updates.

Note: MPD is capable of reading music files within some archive file formats, and will add those during an update if they are in the music directory; tar is known to be an exception.

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 uses 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 - but be sure to have a different port number, avoiding a conflict with the first MPD daemon.

Satellite setup

The method described in #Running an Icecast server 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 concurrently. 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:

Command-line

  • mpc — Command line user interface for MPD server written in C.
https://www.musicpd.org/clients/mpc/ || mpc

Console

  • clerk — MPD client using Rofi.
https://github.com/carnager/clerk || clerk-gitAUR
  • FMUI — Unmaintained console user interface created with fzf and mpc.
https://github.com/seebye/fmui || fmui-gitAUR
  • ncmpc — Ncurses client for MPD written in C++.
https://www.musicpd.org/clients/ncmpc/ || ncmpc
  • ncmpcpp — Almost exact clone of ncmpc, written in C++ with some additional features (tag editor, search engine).
https://rybczak.net/ncmpcpp/ || ncmpcpp
  • ncmpy — Curses-based MPD client written in Python.
https://repo.cykerway.com/ncmpy || ncmpyAUR
  • nncmpp — Yet another MPD client. It is in effect a simplified TUI version of Sonata.
https://git.janouch.name/p/nncmpp/ || nncmpp-gitAUR
  • pms — Highly configurable and accessible ncurses client written in Go.
https://ambientsound.github.io/pms/[dead link 2023-10-29 ⓘ] || pmus-gitAUR
  • vimpc — Ncurses based MPD client with vi-like key bindings.
https://github.com/boysetsfrog/vimpc || vimpc-gitAUR
  • gomp — MPD client inspired by ncmpcpp with builtin cover-art view and LastFM integration.
https://github.com/aditya-K2/gomp || gomp-gitAUR
  • mmtc — Minimal mpd terminal client that aims to be simple yet highly configurable.
https://github.com/figsoda/mmtc || mmtcAUR

Graphical

  • Ario — Very feature-rich GTK3 GUI client for MPD, inspired by Rhythmbox.
http://ario-player.sourceforge.net/ || ario
  • Cantata — Unmaintained high-feature, Qt5 client for MPD with very configurable interface.
https://github.com/CDrummond/cantata || cantataAUR
  • CoverGrid — GTK3 GUI client focusing on albums instead of single tracks.
https://www.suruatoel.xyz/codes/mcg || mcgAUR
  • Plattenalbum — A modern and small GTK4 MPD client written in python.
https://github.com/SoongNoonien/plattenalbum || plattenalbumAUR
  • QMPDClient — Qt5 GUI client.
https://bitcheese.net/QMPDClient/ || qmpdclientAUR
  • 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.
https://www.nongnu.org/sonata/ || sonata-gitAUR
  • Xfce MPD Panel Plugin — MPD plugin for Xfce4 panel.
https://goodies.xfce.org/projects/panel-plugins/xfce4-mpc-plugin || xfce4-mpc-plugin
  • Xfmpc — Graphical GTK MPD client focusing on low footprint.
https://goodies.xfce.org/projects/applications/xfmpc || xfmpc
  • ympd — Standalone MPD Web GUI written in C, utilizing Websockets and Bootstrap/JS.
https://ympd.org/ || ympdAUR
  • Ymuse — Easy, functional and snappy GTK front-end (client) for Music Player Daemon written in Go.
https://yktoo.com/en/software/ymuse/ || ymuseAUR

See also