DIY jukebox with MPD

I still have local music files and a large music library and most of the time I do not want to choose a long time what I want to play. I like to pick one album and based on that I want my playlist or play queue to be filled automatically with new albums. I prefer albums but it could also be songs.
Think of it as your personalized radio station, something you get nowadays on Spotify or even Youtube with their own algorithm they use.
In my case we will use Lastfm. I am sure many know this social music network. No worries, you do not need an account, of course you can if you want.

I will use mpd and mpd-sima.
You can set it up on your local machine or as a server-client model on another machine and even use it on your Raspberry. I have one Raspberry where I use this combination.

First install mpd and mpc. Mpc will allow you to control mpd via keyboard shortcuts and control it with commands to start, pause and play music. Then you need a client if you want some features. There are a lot out there. You can google them and try them all out. I prefer it very minimal and use only the console, especially for the Pi therefor I install ncmpc.

I will configure mpd in both cases as a user and not as system service. On Debian/Ubuntu:

apt install mpd mpc ncmpc mpd-sima

On other distros it will be similar. I use systemd as in Debian and Ubuntu and first of all you want to stop mpd running by default as a system service.

sudo service mpd stop

Then you have to remove it from autostart, another default setting, we want it running as a user service and then it will add itself to the autostart applications of your DE:

sudo systemctl disable mpd

Before you start mpd again, first we should configure it. It has to know where your music library is.
We need some configuration directories where mpd will store its playlists and database:

mkdir ~/.mpd
mkdir ~/.mpd/playlists

We need also the specific config file for all the mpd options. It will be called .mpdconf
It is easier to just copy that file from the directory where it is installed to your home folder and then edit it:

gunzip -c /usr/share/doc/mpd/mpdconf.example.gz > ~/.mpdconf

This again is specific to Debian. On Arch that file could be somewhere else.

Now you can open that file in your preferred text editor, mine is vim, and change the configuration to suit your needs. The most important step is to change the music directory!

music_directory “~/music” (replace it with your directory)

Most of the other stuff can stay as is and you should only change it if really needed. OK apart from the sound output. Most distros use Pulse, so I will configure that:

audio_output {
type “pulse”
name “My Pulse Output”
}

Of course you can use Alsa (e.g. bit perfect output without resampling) or even something else like OSS. I stick to the default sound output on Debian/Ubuntu.

Then you can start mpd and it will populate your music directory and start automatically on boot as a user service on the next reboot of the system:

mpd

If you see some error messages you need to change the config. It will tell you what went wrong. Usually it should be OK.

To make it a personal jukebox you will finally configure mpd-sima. It already runs in the background but you can change it to your needs. I want it to add albums to my playlist. So I will change some parameters using my text editor as root:

vi /etc/mpd-sima.cfg

I changed the queue mode to album and changed from adding tracks to adding albums. Close it and save it. Then you need to restart mpd-sima.

sudo service mpd-sima restart

That is all. When you open your play queue with your mpd client it will already add a random album and based on it find similar artists and add new albums to the list based on Lastfm’s algorithm. It is pretty cool. Your playlist will never be empty but you will not listen to random genres and see something like Britney Spears (if you have that :smile:) playing after Black Sabbath’s Paranoid.

You can see I only used the terminal but that is because mpd itself is a command line program and ncmpc is written in ncurses and I just prefer it that way.

I use the same setup on one laptop and another on the Raspberry where I connect through ssh.
To control the Pi remotely I also use M.A.L.P. on Android.

Why do I like using mpd?

It is small, lightweight, I do not need a GUI, I can use it remotely, it supports really big music libraries and it has essentials like gapless playback, crossfading and replay gain. You can find that all in the mpd config file.

References:

https://manpages.debian.org/buster/mpd-sima/mpd-sima.1.en.html
https://wiki.archlinux.org/index.php/Music_Player_Daemon
https://help.ubuntu.com/community/MPD
mpc manpage (installed on computer)

Notes:

You can of course make another project using mpd. There is also Volumio for something like the Raspeberry.
There are more ncurses clients like the popular ncmpcpp or with a GUI like Cantata.

To add keyboard shortcuts to control mpd with e.g. your media keys on your laptop you need these commands:

mpc play
mpc pause
mpc stop
mpc next
mpc prev
mpc toggle

Ncmpc can also display lyrics and I installed the package ncmpc-lyrics but it does not work here. I did not try to fix it. Other clients like Cantata or ncmpcpp can do that better but then on my Raspberry jukebox I do not need that stuff.