My ultimate guide to the Raspberry pi audio server I wanted — MPD

Mathieu Réquillart
4 min readApr 20, 2020

--

Part 3 — MPD

So now to make as the big boys I want to add MPD to manage my music library, but I can’t have the database managed by the Pi for various reasons:

  • Initial scan is very long because of the number of files I have, they are located on an NFS share which makes each file access longer
  • Setting up correct folder permissions from NFS seemed impossible to me, and it prevented MPD database from updating automatically.
  • Manual update of database was also very long and often ended up with a corrupted db file, ending up with me giving up on MPD and the solution which used it.

Thankfully, MPD has a satellite mode, where we’ll be able to run MPD database directly on the NAS, and have the Pi get its database as a proxy.
We’ll need to install mpd on both device

$ sudo apt install mpd

NAS /etc/mpd.conf :

music_directory “/srv/dev-disk-by-id-md-name-nas-localraid/Musique/music”
playlist_directory “/srv/dev-disk-by-id-md-name-nas-localraid/Musique/playlists”
db_file “/srv/dev-disk-by-id-md-name-nas-localraid/Musique/mpd/tag_cache”

log_file “/var/log/mpd/mpd.log”
pid_file “/run/mpd/pid”
state_file “/var/lib/mpd/state”
sticker_file “/var/lib/mpd/sticker.sql”

user “mpd”
bind_to_address “localhost”
bind_to_address “192.168.0.11”
port “6600”

auto_update “yes”

input {
plugin “curl”
}
filesystem_charset “UTF-8”
id3v1_encoding “UTF-8”

NAS isn’t connected to any speaker so I commented all audio ouputs.
MPD must listen on the same interface to which Pi is connected through network, and music_directory points to the folder you share by NFS. For the auto_update to work properly, MPD needs to be able to write to the music folders, So I ran

$ sudo chgrp -R audio $MUSIC_FOLDER
$ sudo chmod -R 775 $MUSIC_FOLDER

I store the MPD db on the NFS share in case another MPD client without satellite function needs access to it, but it’s not been necessary for now.

On the Pi side, the configuration file gets a bit more complicated.

music_directory “nfs://192.168.0.11/export/Musique/music”
playlist_directory “nfs://192.168.0.11/export/Musique/playlists”

log_file “/var/log/mpd/mpd.log”
pid_file “/run/mpd/pid”
state_file “/var/lib/mpd/state”
sticker_file “/var/lib/mpd/sticker.sql”

user “mpd”
bind_to_address “localhost”
bind_to_address “192.168.0.15”
port “6600”

auto_update “yes”
zeroconf_enabled “yes”
zeroconf_name “Onkyo MPD”

database {
plugin “proxy”
host “192.168.0.11”
port “6600”
}

input {
plugin “curl”
}

audio_output {
type “pulse”
name “pulse audio”
server “127.0.0.1”
}

filesystem_charset “UTF-8”

music_directory now points to a special nfs uri
db_file has disappeared in favor of:

database {
plugin “proxy”
host “192.168.0.11”
port “6600”
}

This way, enabling zeroconf_* configuration on the Pi only, we can make the NAS act as the actual MPD database, while being hidden, and have the Pi make NAS’ database available on the whole network.

For the database we’re done. We still need to make a final tweak to MPD since it use ALSA by default, and we know it’s bad.
Even if we’d forgotten about it, the unabilty to change volume through mpd clients reminds us that we need to use Pulseaudio and not ALSA.

audio_output {
type “pulse”
name “pulse audio”
server “127.0.0.1”
}

localhost instead of 127.0.0.1 would translate to IPV6 ::1 so be careful.

We need to restart mpd

$ sudo systemctl restart mpd

I installed M.A.L.P. as an Android client on my phone.

M.A.L.P. queue

but I also wanted a light web interface to install directly on the pi and chose ympd. It’s written in C++ and doesn’t need to set up PhP (which I really hate) or a web server.

First lets retrieve it and create a systemd unit to start it up at boot

$ cd /tmp
$ wget https://ympd.org/downloads/ympd-1.2.3-armhf.tar.bz2
$ tar xf ympd-1.2.3-armhf.tar.bz2
$ sudo mv ympd /usr/local/bin

/etc/systemd/system/ympd.service

[Unit]
Description=ympd server daemon Requires=network.target
local-fs.target

[Service]
Type=simple
Environment=MPD_HOST=localhost
Environment=MPD_PORT=6600
Environment=WEB_PORT=8080
Environment=YMPD_USER=nobody
ExecStart=/usr/local/bin/ympd — webport $WEB_PORT -u $YMPD_USER

[Install]
WantedBy=multi-user.target

To start ympd:

$ sudo systemctl daemon-reload 
$ sudo systemctl enable ympd
Created symlink /etc/systemd/system/multi-user.target.wants/ympd.service → /etc/systemd/system/ympd.service.
$ sudo systemctl start ympd
$ sudo systemctl status ympd
● ympd.service — ympd server daemon
Loaded: loaded (/etc/systemd/system/ympd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020–04–18 18:02:32 CEST; 4s ago
Main PID: 4598 (ympd)
Memory: 552.0K
CGroup: /system.slice/ympd.service
└─4598 /usr/local/bin/ympd — webport 8080

Apr 18 18:02:32 Ampli-BT systemd[1]: Started ympd server daemon.
Apr 18 18:02:33 Ampli-BT ympd[4598]: MPD connected.

Ympd is now available at your pi’s IP port 8080.

ympd queue

Do not try to run ympd on 80 port, you’d need to give it root privileges, which is really bad.

# Edit: I just realized ympd wasn’t maintained anymore, but there’s now Mympd I hadn’t spotted yet. Builds for Rapsbian are available here however not for Raspberry 2b armv6 architecture. So I’d would either have to compile it on pi, on setup cross compiling on a more powerful computer. It might be a new part someday.

Part4: DLNA

--

--