Difference between revisions of "Music Player Daemon"

From ArchWiki
Jump to: navigation, search
m (Start MPD per user with systemd)
m (Autostart with systemd: correction: user and group variables are related to MPD config, not to the service file - added clarification)
(47 intermediate revisions by 29 users not shown)
Line 1: Line 1:
 
[[Category:Player]]
 
[[Category:Player]]
[[Category:Daemons and system services]]
 
 
[[de:Music Player Daemon]]
 
[[de:Music Player Daemon]]
 
[[es:Music Player Daemon]]
 
[[es:Music Player Daemon]]
Line 13: Line 12:
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|Installation, configuration and basic troubleshooting of MPD.}}
 
{{Article summary text|Installation, configuration and basic troubleshooting of MPD.}}
{{Article summary heading|Required software}}
 
{{Article summary link|Music Player Daemon|http://mpd.wikia.com}}
 
 
{{Article summary heading|Related Articles}}
 
{{Article summary heading|Related Articles}}
 
{{Article summary wiki|MPD/Tips and Tricks}}
 
{{Article summary wiki|MPD/Tips and Tricks}}
 
{{Article summary wiki|MPD/Troubleshooting}}
 
{{Article summary wiki|MPD/Troubleshooting}}
 
{{Article summary heading|Other sources}}
 
{{Article summary heading|Other sources}}
{{Article summary text|[[Wikipedia:MPD|Wikipedia article]]}}
+
{{Article summary text|[[Wikipedia:Music Player Daemon|Wikipedia article]]}}
 
{{Article summary end}}
 
{{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]''' ('''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.
  
 
== Installation ==
 
== Installation ==
=== Stable version ===
+
 
 
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].
 
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].
 
 
=== Git version ===
 
 
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.
 
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.
  
 
== Setup ==
 
== 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 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:
+
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.
* mpd.db - The music database
+
 
* mpd.pid -  The file where mpd stores its process ID
+
For a proper MPD operation these are the necessary files and directories:
* mpd.log - mpd logs here
+
 
* mpdstate - mpd's current state is noted here
+
* database - The music database
* playlists - the folder where playlists are saved into
+
* pid -  The file where mpd stores its process ID
 +
* log - MPD logs here
 +
* state - MPD's current state is noted here
 +
* playlists - The folder where playlists are saved into
 +
* sticker.sql - The sticker database
  
 
In order for MPD to be able to play back audio, [[ALSA]], [[PulseAudio]] or [[OSS]] needs to be setup and working.
 
In order for MPD to be able to play back audio, [[ALSA]], [[PulseAudio]] or [[OSS]] needs to be setup and working.
  
=== Global Configuration ===
+
=== Local configuration (per user) ===
{{Note|For user-specific permissions, change the "user" line above to reflect one of the system users.}}
+
{{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!}}
+
  
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.
+
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:
  
Normally,{{ic|/etc/mpd.conf}} is created when installing mpd. If not, copy the included example file to {{ic|/etc/mpd.conf}}.
+
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/$USER/}}) that will contain all the MPD configuration files.
# cp /usr/share/doc/mpd/mpdconf.example /etc/mpd.conf
+
* Easier to avoid unforeseen read/write permission errors.
  
==== Editing mpd.conf ====
+
To setup: create a directory for the required files and the playlists; copy the example configuration locally; create all of the requisite files:
The default Arch install keeps the setup in {{ic|/var/lib/mpd}} and uses "mpd" as default user.
+
  
Edit {{ic|/etc/mpd.conf}} to reflect as such:
+
$ mkdir -p ~/.mpd/playlists
{{hc|/etc/mpd.conf|
+
$ cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf
music_directory      "/home/user/music"
+
$ touch ~/.mpd/{database,log,state,pid,sticker.sql}
playlist_directory    "/var/lib/mpd/playlists"
+
db_file              "/var/lib/mpd/mpd.db"
+
log_file              "/var/log/mpd/mpd.log"
+
pid_file              "/run/mpd/mpd.pid"
+
state_file            "/var/lib/mpd/mpdstate"
+
user                  "mpd"
+
# bind_to_address      "127.0.0.1"
+
# port                  "6600"
+
}}
+
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|
+
Edit {{ic|~/.mpdconf}} and specify the requisite files:
mixer_type "software"
+
}}
+
  
Users of [[PulseAudio]] will need to make the following modification:
+
{{hc|~/.mpdconf|
{{hc|/etc/mpd.conf|2=
+
music_directory    "~/music"          # Can keep commented if XDG music dir.
audio_output {
+
playlist_directory "~/.mpd/playlists"
        type                    "pulse"
+
db_file            "~/.mpd/database"
         name                    "pulse audio"
+
log_file          "~/.mpd/log"
}
+
pid_file          "~/.mpd/pid"
 +
state_file         "~/.mpd/state"
 +
sticker_file      "~/.mpd/sticker.sql"
 
}}
 
}}
  
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.
+
MPD can now be started by typing {{ic|mpd}} on the command line (mpd first searches for {{ic|~/.mpdconf}}, then {{ic|~/etc/mpd.conf}} [there is no support for XDG-config directory {{ic|~/.config/mpd/mpd.conf}}]).  To specify the location of the configuration file :
{{hc|/etc/mpd.conf|2=
+
audio_output {
+
        type            "alsa"
+
        name            "My Sound Card"
+
        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""
+
mpd /path/to/mpd.conf
  
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}}.
+
To start MPD on login add to {{ic|~/.profile}} (or another [[Autostarting#Shells|Autostart file]]):
# gpasswd -a mpd audio
+
  
===== Music directory =====
+
# MPD daemon start (if no other user instance exists)
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.
+
[ ! -s ~/.mpd/pid ] && mpd
  
  # mkdir /var/lib/mpd/music
+
To start with the X.org server add to either [[xprofile]] or [[xinitrc]]. Some DEs ignore these files (GNOME does) and a desktop file must be placed in {{ic|~/.config/autostart/mpd.desktop}}:
# 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}}.
+
{{bc|<nowiki>
# mkdir /var/lib/mpd/music
+
[Desktop Entry]
# ln -s MUSIC_FOLDER /var/lib/mpd/music/
+
Encoding=UTF-8
# rc.d restart mpd  
+
Type=Application
(systemd users should perform # systemctl restart mpd.service)
+
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 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.
+
==== Autostart with systemd ====
  
==== Creating the required files ====
+
{{Note|It is assumed that you already have systemd user-session manager running. See the [[systemd/User]] page for details.}}
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}}:
+
The package {{Pkg|mpd}} provides user service file in {{ic|/usr/lib/systemd/user/mpd.service}}. Though it is a symlink to {{ic|/usr/lib/systemd/system/mpd.service}}, the difference is that the process is not started as root. The configuration file {{ic|~/.mpdconf}} is expected to exist (otherwise the global {{ic|/etc/mpd.conf}} is used). 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.
# 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}}:
+
{{Tip|If you don't like the configuration file being in {{ic|~/.mpdconf}}, copy {{ic|/usr/lib/systemd/system/mpd.service}} to {{ic|~/.config/systemd/user/mpd.service}} and edit it to contain the path of your configuration file:
Change:
+
{{hc|~/.config/systemd/user/mpd.service|2=
d /run/mpd 0755 mpd mpd
+
...
to:
+
ExecStart=/usr/bin/mpd --no-daemon /path/to/your/mpd.conf
d /run/mpd 0755 ''username'' ''groupname''
+
...
 +
}}}}
  
Change the file's permissions so that the daemon can modify them.
+
All you have to do is enable and start the user service:
# chown -R mpd /var/lib/mpd
+
  
==== Create database ====
+
$ systemctl --user enable mpd
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
+
$ systemctl --user start mpd
{{Box RED | Note: | Creating the MPD database as root using {{ic|# mpd --create-db}} is deprecated.}}
+
  
==== Timeline of MPD startup ====
+
{{Note|Also make sure to disable every other method of starting mpd you used before.}}
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).
+
==== Scripted 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.
+
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://53280.de/dl/mpdsetup.sh here].
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) ===
+
=== Global configuration ===
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:
+
{{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!}}
  
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/username}}) that will contain all the MPD configuration files.
+
The default Arch install keeps the setup in {{ic|/var/lib/mpd}} and uses ''mpd'' as default user.
* 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.}}
+
Edit {{ic|/etc/mpd.conf}} to reflect as such:
 +
{{hc|/etc/mpd.conf|
 +
music_directory      "/path/to/music/dir"
 +
playlist_directory    "/var/lib/mpd/playlists"
 +
db_file              "/var/lib/mpd/mpd.db"
 +
log_file              "syslog"
 +
pid_file              "/run/mpd/mpd.pid"
 +
state_file            "/var/lib/mpd/mpdstate"
 +
user                  "mpd"
 +
}}
  
Begin the setup by creating a directory for the required files and the playlists:
+
We just configured MPD to run as the ''mpd'' user, but {{ic|/var/lib/mpd}} is owned by ''root'' by default, we need to change this so ''mpd'' can write here:
 +
# chown -R mpd /var/lib/mpd
  
{{bc|mkdir -p ~/.mpd/playlists}}
+
==== Music directory ====
  
Copy the contents of the default MPD configuration file in {{ic|/usr/share/mpd/mpd.conf.example}} to the target user's home directory:
+
MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection (ie. if it's located outside of {{ic|/var/lib/mpd}}). 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.
  
{{bc|cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf}}
+
# mkdir /var/lib/mpd/music
 +
# echo "/path/to/music/dir /var/lib/mpd/music none bind" >> /etc/fstab
 +
# mount -a
 +
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this forum thread].
  
Create all of the requisite files:
+
An additional solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.
 +
# mkdir /var/lib/mpd/music
 +
# ln -s /path/to/music/dir /var/lib/mpd/music/
  
{{bc|<nowiki>touch ~/.mpd/{mpd.db,mpd.log,mpd.pid,mpdstate}</nowiki>}}
+
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.
  
Edit {{ic|~/.mpdconf}} to specify these files:
+
==== Start MPD ====
  
{{hc|~/.mpdconf|
+
MPD can be controlled with the ''mpd'' [[daemon]]. The first startup can take some time as MPD will scan your music directory.
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"
+
}}
+
  
MPD can now be started by typing {{ic|mpd}} on the command line.
+
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!
  
To have MPD start with the X server add it to [[xprofile]].
+
==== Configure audio ====
  
==== Start MPD per user with systemd ====
+
To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:
 +
{{hc|/etc/mpd.conf|
 +
mixer_type "software"
 +
}}
  
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.
+
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.
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.
+
{{hc|/etc/mpd.conf|2=
If you already enabled it, just disable it first:
+
audio_output {
{{bc| # systemctl disable mpd.service}}
+
        type            "alsa"
 +
        name            "My Sound Card"
 +
        mixer_type      "software"      # optional
 +
}
 +
}}
  
If you used to start mpd inside your {{ic|~/.xinitrc}}, comment or delete the line
+
Users of [[PulseAudio]] will need to make the following modification:
{{bc|mpd ~/.mpdconf}}
+
{{hc|/etc/mpd.conf|2=
 +
audio_output {
 +
        type            "pulse"
 +
        name            "pulse audio"
 +
}
 +
}}
  
Then, edit a new file /etc/systemd/user/mpd.service
+
==== Changing user ====
{{hc|/etc/systemd/user/mpd.service|
+
[Unit]
+
Description &#61; Music Player Daemon
+
  
[Service]
+
{{Note|This is only required if you change the user!}}
ExecStart &#61; /usr/bin/mpd --no-daemon
+
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""
Restart &#61; always
+
  
[Install]
+
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}}:
WantedBy &#61; default.target
+
# gpasswd -a mpd audio
}}
+
  
Then, add this line to [[xinitrc|.xinitrc]]
+
==== Timeline of MPD startup ====
{{hc|~/.xinitrc|
+
#run systemd as user intsance
+
systemd --user &
+
}}
+
  
Log out, log in your xsession.
+
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:
Let's first check mpd is not running. If yes, just kill it
+
{{bc|$ ps -ef &#124; grep mpd}}
+
  
Now, start mpd.service as per user
+
# Since MPD is started as root by systemd, it first reads the {{ic|/etc/mpd.conf}} file.
$ systemctl --user enable mpd
+
# MPD reads the user variable in the {{ic|/etc/mpd.conf}} file, and changes from root to this user.
$ systemctl --user start mpd
+
# MPD then reads the contents of the {{ic|/etc/mpd.conf}} file and configures itself accordingly.
  
Check the mpd status and see if mpd.service is correctly enabled and started
+
Notice that MPD changes the running user from root to the one named in the {{ic|/etc/mpd.conf}} file.
{{bc|$ systemctl --user status mpd}}
+
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.
==== 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 ===
 
=== Multi-mpd setup ===
 +
 
'''Useful if running an icecast server.'''
 
'''Useful if running an icecast server.'''
  
Line 239: Line 207:
  
 
== Clients ==
 
== Clients ==
A separate client is needed to control mpd. Popular options are:
+
 
 +
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:
  
 
=== Console ===
 
=== Console ===
 +
 
*{{App|mpc|Simple KISS client. All basic functionality available|http://mpd.wikia.com/wiki/Client:Mpc|{{Pkg|mpc}}}}
 
*{{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|ncmpc|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|[[ncmpcpp]]|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}}}}
 
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}
 +
*{{App|vimpc|Ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}
 +
 
=== 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|Ario|Very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}
*{{App|Sonata|An elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}
+
*{{App|QmpdClient|GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}
*{{App|gmpc|GNOME Client|http://gmpc.wikia.com/wiki/Gnome_Music_Player_Client|{{Pkg|gmpc}}}}
+
*{{App|Sonata|Elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}
 +
*{{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|Dmpc|Dmenu-based MPC client with a playlist manager and state-saving on playlist changes|http://wintervenom.mine.nu/|{{AUR|dmpc}}}}
 
*{{App|Dmpc|Dmenu-based MPC client with a playlist manager and state-saving on playlist changes|http://wintervenom.mine.nu/|{{AUR|dmpc}}}}
 +
*{{App|Cantata|High-feature, Qt4/KDE4 client for MPD with very configurable interface|https://code.google.com/p/cantata/|{{AUR|cantata-qt}}}}
  
 
=== Web ===
 
=== Web ===
*{{App|Patchfork|web client for MPD written in PHP and Ajax|http://mpd.wikia.com/wiki/Client:Pitchfork|{{AUR|patchfork-git}}}}.
 
  
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].
+
*{{App|Patchfork|Web client for MPD written in PHP and Ajax|http://mpd.wikia.com/wiki/Client:Pitchfork|{{AUR|patchfork-git}}}}.
 +
 
 +
== 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]
+

Revision as of 13:09, 1 November 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary heading Template:Article summary text Template:Article summary end

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

The latest stable version of mpd is available in the official repositories.

Should users wish to run an experimental version, the AUR offers several from which to choose. For example, mpd-gitAUR.

Setup

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.

For a proper MPD operation these are the necessary files and directories:

  • database - The music database
  • pid - The file where mpd stores its process ID
  • log - MPD logs here
  • state - MPD's current state is noted here
  • playlists - The folder where playlists are saved into
  • sticker.sql - The sticker database

In order for MPD to be able to play back audio, ALSA, PulseAudio or OSS needs to be setup and working.

Local configuration (per user)

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:

  • A single directory ~/.mpd (or any other directory under /home/$USER/) that will contain all the MPD configuration files.
  • Easier to avoid unforeseen read/write permission errors.

To setup: create a directory for the required files and the playlists; copy the example configuration locally; create all of the requisite files:

$ mkdir -p ~/.mpd/playlists
$ cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf
$ touch ~/.mpd/{database,log,state,pid,sticker.sql}

Edit ~/.mpdconf and specify the requisite files:

~/.mpdconf
music_directory    "~/music"          # Can keep commented if XDG music dir.
playlist_directory "~/.mpd/playlists"
db_file            "~/.mpd/database"
log_file           "~/.mpd/log"
pid_file           "~/.mpd/pid"
state_file         "~/.mpd/state"
sticker_file       "~/.mpd/sticker.sql"

MPD can now be started by typing mpd on the command line (mpd first searches for ~/.mpdconf, then ~/etc/mpd.conf [there is no support for XDG-config directory ~/.config/mpd/mpd.conf]). To specify the location of the configuration file :

mpd /path/to/mpd.conf

To start MPD on login add to ~/.profile (or another Autostart file):

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

To start with the X.org server add to either xprofile or xinitrc. Some DEs ignore these files (GNOME does) and a desktop file must be placed in ~/.config/autostart/mpd.desktop:

[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

Autostart with systemd

Note: It is assumed that you already have systemd user-session manager running. See the systemd/User page for details.

The package mpd provides user service file in /usr/lib/systemd/user/mpd.service. Though it is a symlink to /usr/lib/systemd/system/mpd.service, the difference is that the process is not started as root. The configuration file ~/.mpdconf is expected to exist (otherwise the global /etc/mpd.conf is used). You should not use the user and group variables in the MPD configuration file, the process already has user permissions and therefore it is not necessary to change them further.

Tip: If you don't like the configuration file being in ~/.mpdconf, copy /usr/lib/systemd/system/mpd.service to ~/.config/systemd/user/mpd.service and edit it to contain the path of your configuration file:
~/.config/systemd/user/mpd.service
...
ExecStart=/usr/bin/mpd --no-daemon /path/to/your/mpd.conf
...

All you have to do is enable and start the user service:

$ systemctl --user enable mpd
$ systemctl --user start mpd
Note: Also 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 here.

Global configuration

Warning: Users of PulseAudio with a local mpd have to implement a workaround in order to run mpd as its own user!

The default Arch install keeps the setup in /var/lib/mpd and uses mpd as default user.

Edit /etc/mpd.conf to reflect as such:

/etc/mpd.conf
music_directory       "/path/to/music/dir"
playlist_directory    "/var/lib/mpd/playlists"
db_file               "/var/lib/mpd/mpd.db"
log_file              "syslog"
pid_file              "/run/mpd/mpd.pid"
state_file            "/var/lib/mpd/mpdstate"
user                  "mpd"

We just configured MPD to run as the mpd user, but /var/lib/mpd is owned by root by default, we need to change this so mpd can write here:

# chown -R mpd /var/lib/mpd

Music directory

MPD needs to have +x permissions on all parent directories to the music collection (ie. if it's located outside of /var/lib/mpd). 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
# echo "/path/to/music/dir /var/lib/mpd/music none bind" >> /etc/fstab
# mount -a

Also see this forum thread.

An additional solution would be to just create a symbolic link into /var/lib/mpd/music.

# mkdir /var/lib/mpd/music
# 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 /var/lib/mpd. Remember to set permissions accordingly on the directories being linked.

Start MPD

MPD can be controlled with the mpd daemon. 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!

Configure audio

To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:

/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.

/etc/mpd.conf
audio_output {
        type            "alsa"
        name            "My Sound Card"
        mixer_type      "software"      # optional
}

Users of PulseAudio will need to make the following modification:

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

Changing user

Note: This is only required if you change the user!

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""

This is because by default MPD runs as member of audio group and the sound devices under /dev/snd/ are owned by this group, so add user mpd to group audio:

# gpasswd -a mpd audio

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 listed here:

  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 /etc/mpd.conf file, and changes from root to this user.
  3. MPD then reads the contents of the /etc/mpd.conf file and configures itself accordingly.

Notice that MPD changes the running user from root to the one named in the /etc/mpd.conf file. This way, uses of ~ 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 ~ to /home/username to avoid any confusion over this aspect of MPD's behavior.

Multi-mpd setup

Useful if 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).

Clients

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

Console

  • mpc — Simple KISS client. All basic functionality available
http://mpd.wikia.com/wiki/Client:Mpc || mpc
  • ncmpc — Ncurses client for mpd
http://mpd.wikia.com/wiki/Client:Ncmpc || ncmpc
  • ncmpcpp — Almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)
http://unkart.ovh.org/ncmpcpp/ || ncmpcpp
  • pms — Highly configurable and accessible ncurses client
http://pms.sourceforge.net/ || pmusAUR
  • vimpc — Ncurses based MPD client with vi-like key bindings
http://sourceforge.net/projects/vimpc/ || vimpcAUR

Graphical

  • Ario — Very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox
http://ario-player.sourceforge.net/ || ario
  • QmpdClient — GUI client written with Qt 4.x
http://bitcheese.net/wiki/QMPDClient || qmpdclient
  • Sonata — Elegant Python GTK+ client
http://sonata.berlios.de/ || sonata
  • 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 || gmpc
  • Dmpc — Dmenu-based MPC client with a playlist manager and state-saving on playlist changes
http://wintervenom.mine.nu/ || dmpcAUR
  • Cantata — High-feature, Qt4/KDE4 client for MPD with very configurable interface
https://code.google.com/p/cantata/ || cantata-qtAUR

Web

  • Patchfork — Web client for MPD written in PHP and Ajax
http://mpd.wikia.com/wiki/Client:Pitchfork || patchfork-gitAUR.

See also