{{Note|It is assumed that you already have systemd user-session manager running. See the [[systemd/User]] page for details.}}

{{Note|It is assumed that you already have systemd user-session manager running. See the [[systemd/User]] page for details.}}

−

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 configuration file.

+

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.

{{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:

{{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:

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

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:

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 :

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.

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.

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

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:

Since MPD is started as root by systemd, it first reads the /etc/mpd.conf file.

MPD reads the user variable in the /etc/mpd.conf file, and changes from root to this user.

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:

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.