Skip to main content

Music Player Daemon

Guangzhou, China

Installing the Music Player Daemon

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.

sudo pacman -S mpd mpc ncmpcpp

MPD is configured in the file mpd.conf. 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
mkdir -p ~/.mpd/playlists
touch ~/.mpd/{mpd.conf,mpd.db,mpd.log,mpd.pid}
cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf
lvim ~/.mpd/mpd.conf

Make sure to point the daemon to a music directory the daemon will have access rights to - e.g. ~/Music if you start the daemon with your local user. I needed to use pulse as my audio output - yours might be different:

music_directory		"~/Music"
#
# This setting sets the MPD internal playlist directory. The purpose of this
# directory is storage for playlists created by MPD. The server will use
# playlist files not created by the server but only if they are in the MPD
# format. This setting defaults to playlist saving being disabled.
#
playlist_directory "~/.mpd/playlists"
#
# This setting sets the location of the MPD database. This file is used to
# load the database at server start up and store the database while the
# server is not up. This setting defaults to disabled which will allow
# MPD to accept files over ipc socket (using file:// protocol) or streaming
# files over an accepted protocol.
#
db_file "~/.mpd/database"

# These settings are the locations for the daemon log files for the daemon.
#
# The special value "syslog" makes MPD use the local syslog daemon. This
# setting defaults to logging to syslog.
#
# If you use systemd, do not configure a log_file. With systemd, MPD
# defaults to the systemd journal, which is fine.
#
log_file "~/.mpd/mpd.log"

# This setting sets the location of the file which stores the process ID
# for use of mpd --kill and some init scripts. This setting is disabled by
# default and the pid file will not be stored.
#
# If you use systemd, do not configure a pid_file.
#
pid_file "~/.mpd/mpd.pid"

# This setting sets the location of the file which contains information about
# most variables to get MPD back into the same general shape it was in before
# it was brought down. This setting is disabled by default and the server
# state will be reset on server start up.
#
state_file "~/.mpd/state"
#
# The location of the sticker database. This is a database which
# manages dynamic information attached to songs.
#
sticker_file "~/.mpd/sticker.sql"

user "mylinuxuser"
group "mylinuxusergroup"
bind_to_address "127.0.0.1"
port "6600"
input {
plugin "curl"
# proxy "proxy.isp.com:8080"
# proxy_user "user"
# proxy_password "password"
}

audio_output {
type "fifo"
name "my_fifo"
path "/tmp/mpd.fifo"
format "44100:16:1"
}
audio_output {
type "pulse"
name "ALSA/PulseAudio"
mixer_type "software"
}

Configure the ncmpcpp console UI tool for mpd:

mkdir ~/.ncmpcpp
cp /usr/share/doc/ncmpcpp/config ~/.ncmpcpp/
lvim ~/.ncmpcpp/config
ncmpcpp_directory = ~/.config/ncmpcpp
mpd_host = localhost
mpd_port = 6600
mpd_music_dir = ~/Music
mpd_crossfade_time = 5
visualizer_data_source = /tmp/mpd.fifo
visualizer_output_name = Visualizer feed
visualizer_in_stereo = yes
visualizer_type = wave_filled

Error messages

server_socket: bind to '0.0.0.0:6600' failed (continuing anyway, because binding to '[::]:6600'>
sudo systemctl disable mpd.service
sudo systemctl status mpd.service

Run mpd as your user:

systemctl --user enable mpd
systemctl --user start mpd
systemctl --user status mpd
# after making changes to your config if needed
systemctl --user restart mpd

Once you got rid of all the error messages start the console UI:

ncmpcpp

Installing the Music Player Daemon on Arch Linux