Debian-based Linux system, but it should be relatively easy to adapt to other distributions as well.
It should also be noted that most, if not all, configuration is done on the command line. If you prefer a graphical interface, something like AzuraCast may suit you more.
First and foremost, we need some audio files to play. I’ve set up a music directory on my server that is synchronized with my local library via Syncthing, but as long as you have a folder with some audio files in it, you’re good to go. You can place and structure it wherever and however you want – we’ll get back to this later.
Music Player Daemon (or MPD for short) is just what the name suggests. It is extremely versatile and configurable, and can be used to output audio via ALSA, JACK, PulseAudio, PipeWire, HTTP and more. To get a first impression of just how much it is capable of doing, I highly recommend skimming through its plugin reference.
In any case, this is what we’ll be using for the core of our station – the audio playback. So, let’s install it.
As is often the case, the version in the respective package repositories is somewhat outdated. At the time of writing, this command will get you version 0.22.4, while the latest is 0.23.5. However, I didn’t notice any major differences between them, so for the sake of simplicity, let’s stick to the provided package:
sudo apt install mpd
While not that up-to-date, it does come with configuration and service files. Let’s open up the former:
sudo editor /etc/mpd.conf
The file itself does a great job of explaining the many available options, so I’ll stick to the bare minimum here.
music_directory
option to the respective path. Mine, for example, is in "/mnt/sda1/Music"
.auto_update
to "yes"
.password
option to "<password>@read,add,control,admin"
(or "<password>@add,control,admin"
to allow read-only access), replacing “<password>”. If not, set bind_to_address
to "localhost"
.always_on
and set it to "yes"
– this will prevent the stream from being shut down when MPD finishes playing, instead outputting silence. The block should now look something like this:audio_output {
type "httpd"
name "My HTTP Stream"
port "8000"
bind_to_address "0.0.0.0"
bitrate "128"
format "44100:16:1"
always_on "yes"
}
Save and close the file, then restart MPD and set it to start automatically on boot:
sudo systemctl restart mpd
sudo systemctl enable mpd
MPD will recognize the changed library path and start scanning it automatically. Depending on the amount of files in it, this may take a while.
MPD is now up and running, but we’ll still need to give it some music to play. It is highly focused on modularity, so we’ll need a separate program for this. mpc comes in handy here – a “minimalist command line interface to MPD”, made by the same authors:
sudo apt install mpc
To see if everything works correctly, run the following command to get the current status of the MPD server. Remember that, if you set up password protection earlier, you’ll need to supply that as well:
mpc [-P <password>]
If everything went well, you should see something like this:
volume: n/a repeat: off random: off single: off consume: off
We are now ready to start adding songs! To do so, we can enter mpc add
, followed by the path to the audio file without the path to the music directory. For example, if I wanted to add “/mnt/sda1/Music/world’s end girlfriend/MEGURI (2018)/02. MEGURI.mp3”, I would run:
mpc -P <password> add "world’s end girlfriend/MEGURI (2018)/02. MEGURI.mp3"
To see if it was added correctly, run:
mpc [-P <password>] playlist
This now gives me:
world’s end girlfriend - MEGURI
Finally, start the playback:
mpc [-P <password>] play
Now open http://localhost:8000 and see MPD in action! The stream includes the song’s metadata, the queue is persisted across restarts, and if not configured otherwise, MPD will resume playback automatically after booting.
mpc also provides a bunch of other useful commands – see its documentation for details.
In theory, we could stop here, but having to add music all the time gets tiring. However, there is a great programm called MPD_sima that automatically adds new songs to the end of the queue. It works by looking for similar artists on Last.fm, so the music doesn’t just jump from, say, Ambient to Harsh Noise. Of course, the larger your library, the better this works.
sudo apt install mpd-sima
Open its configuration file to verify everything is to your liking:
sudo editor /etc/mpd-sima.cfg
Again, the program itself provides detailed documentation regarding the available options. The defaults work well enough for me, but perhaps most importantly, if you set up password protection earlier, you’ll need to uncomment the password
option and adjust it accordingly.
Save and close it, then, as with MPD itself, restart it and enable automatic startup on boot:
sudo systemctl restart mpd-sima
sudo systemctl enable mpd-sima
My queue now looks like this, and more songs will get added while the playback progresses:
world’s end girlfriend - MEGURI
Sigur Rós - Í gær
Hammock - Dark Beyond The Blue
If you find that, after a while, MPD_sima goes into a loop where it queues the same songs over and over again, you might want to try toying with the configuration options a bit.
Most people will want to stop here, but if you’re familiar with Icecast and want to use that instead of a plain HTTP stream, you can do that as well. Start by installing it:
sudo apt install icecast2
You will be prompted to set passwords during the installation process – make sure to choose different ones than the default, “hackme”. Make special note of the source password – this is what MPD will need later on.
This should be all the configuration you need, but if you want to change more advanced settings, you can open the configuration file via:
sudo editor /etc/icecast2/icecast.xml
Once more, the file contains useful documentation regarding all options.
Now, open up MPD’s configuration file again, comment out the “httpd” output, enable the “shout” output instead and change the values as needed. As with the HTTP stream, make sure to add an always_on
value. My block now looks like this:
audio_output {
type "shout"
name "My Shout Stream"
host "localhost"
port "8000"
mount "/mpd.ogg"
password "(redacted)"
bitrate "128"
format "44100:16:1"
always_on "yes"
}
Make sure to replace “(redacted)” with the source password, then save and close the file.
Now, stop MPD to release port 8000, restart Icecast, then restart MPD. Remember, we used this port earlier for the HTTP stream, but now want to give it to Icecast:
sudo systemctl stop mpd
sudo systemctl restart icecast2
sudo systemctl start mpd
Going to http://localhost:8000 now will give you the default Icecast interface, while the stream will be available at http://localhost:8000/mpd.ogg. Of course, the URLs may vary depending on your settings.
Our station is now fully functional! You could now go ahead and publish it to internet radio station directories such as RadioBrowser or the Icecast Directory. Instructions on how to do so can be found on their respective sites. I skipped this step, since my station is mostly for myself and toying around with MPD, but you do you!
One last thing we could do is to set up scrobbling, allowing anyone to see a history of previously played songs. Most stations use their own websites for this, but one station I know of that uses Last.fm is BBC Radio 1. Given the modularity of MPD, there are, once more, multiple clients for doing so, but I usually use mpdscribble, since it’s written by the same authors as MPD itself. It also supports Libre.fm and Jamendo, if you prefer to use that, but I’ll stick to Last.fm.
sudo apt install mpdscribble
mpdscribble’s configuration file is located within “/etc”. To edit it, run:
sudo editor /etc/mpdscribble.conf
As with the previously mentioned programs, mpdscribble, too, provides all the documentation you’d want.
host
property and set it to <password>@localhost
.username
and password
properties.As always, save and close, then restart mpdscribble:
sudo systemctl restart mpdscribble
sudo systemctl enable mpdscribble
Done! The history of your station will now be available at https://last.fm/user/username – just replace the username with your own.