Raspberry Pi MPD server

Notes about starting fresh on a Raspberry Pi and making a Music Player Daemon (MPD) server out of it.

New image preparation

I did use the Raspberry Pi Imager program and put the base Debian with no desktop environment on the SD card. I did use the customizer to put a user and password on it.

I also have put the MAC in my DHCP server so that the Pi gets a static IP address, and I put an entry in DNS so that IP address maps to the host name I want.

First, an update:

sudo apt-get update

Then I install vim. The default is to use nano, but I like vim.

sudo apt-get install vim -y

Followed by

sudo update-alternatives --config editor

Choice 3 picks vim as my editor.

Followed by turning off Wi-Fi. For music streaming, I only want the Raspberry Pi to be hard-wired into the network.

sudo vim /boot/firmware/config.txt

At the very bottom, I added this to the config.txt file:

dtoverlay=disable-wifi

It goes underneath the [all] section. Then I reboot and log in, and perform

sudo apt update
sudo apt upgrade -y

Now I get to install my favorite aliases and history search keystrokes. These are detailed here.

The next steps are so that I can do ssh from my main machine. I followed this, although I wanted to set a root user password first:

sudo passwd root

Then I mostly followed these steps: New Debian install; ssh and sudo changes

Then I did the ssh-copy-id thing and changed Password Authentication back to no in /etc/ssh/sshd_config

Start with the MPD install

The documentation says that the version of MPD that one can install from the Debian repositories is out of date. I can confirm that.

However, going through those motions sets things up well for later.

apt install mpd -y

Followed by

apt install snapserver -y

The Snapcast server needs to be configured to look to MPD for the sound source.

vim /etc/snapserver.conf

to say:

[stream]  
source = pipe:///tmp/snapfifo?name=MPD

That line was already there, except the name= was default instead of MPD

So later I get to download the latest .tar.xy file, and copy it to the Raspberry Pi. Then:

tar xf mpd-version.tar.xz
cd mpd-version

At this point, I should simply point you at https://mpd.readthedocs.io/en/stable/user.html

There’s a whole bit about apt install meson g++ pkgconf \ and some whole bunches of packages. Then there’s the compile after that. 696 things it compiles.

After all that is done, it is time to update the /etc/mpd.conf file.

This is what mine looks like with the comments stripped out:

music_directory       "/var/lib/mpd/music"
playlist_directory "/var/lib/mpd/playlists"
db_file "/var/lib/mpd/tag_cache"

state_file "/var/lib/mpd/state"
sticker_file "/var/lib/mpd/sticker.sql"

user "mpd"
bind_to_address "0.0.0.0"
port "6600"

auto_update "yes"
auto_update_depth "0"

zeroconf_enabled "yes"
zeroconf_name "Music Player @ %h"

input {
plugin "curl"
}

decoder {
plugin "hybrid_dsd"
enabled "no"
}

decoder {
plugin "wildmidi"
enabled "no"
#config_file "/etc/timidity/timidity.cfg"
}

audio_output {
type "fifo"
encoder "flac"
name "snapserver"
format "48000:16:2"
path "/tmp/snapfifo"
compression "8"
mixer_type "software"
}

filesystem_charset "UTF-8"

Eventually, we get it installed, which includes creating the /var/lib/mpd/music directory. We need that for the next step.

Access to the sound files

This took an edit of /etc/fstab although this is always more difficult than I think it should be.

I did it for Nextcloud, so it is the same thing, kind of. Nextcloud gets read/write access, where this MPD server doesn’t need to be able to write to the sound files or directory.

First, set up a credentials file, with the login name and password:

touch /root/credentials.smb
vim /root/credentials.smb
username=epstein_did_not_kill_himself
password=Apparently-Child-Rape-Is-Okay-If-0.1%-Richest-People-Opt-In-To-Doing-It,Obviously,Because-Otherwise-The-Rapists-Would-Have-Gone-To-Jail

Then we can edit /etc/fstab

//hostname/smbsharename/data /var/lib/mpd/music cifs vers=3.0,credentials=/root/credentials.smb,_netdev,iocharset=utf8 0 0

One thing that kicked my ass for a couple of hours:

vim /usr/local/lib/systemd/system/mpd.service

And on the ExecStart line, I had to explicitly add the configuration file path and file name.

So before, it looked like this:

ExecStart=/usr/local/bin/mpd --systemd

But that would err out with “could not find config file”. I changed it to this:

ExecStart=/usr/local/bin/mpd --systemd /etc/mpd.conf

And now it magically works. Of course, yesterday the first time I set it up, I had no such problems. Sigh.

I still have one more thing to add: Snapweb, where Snapcast server will show you what is currently running. I had that running yesterday, and liked it.