Weekend Project: Whole House and Streaming Audio for Free with MPD

I often see posts on /r/selfhosted asking about self-hosting a streaming music service. Over the years, I’ve put together a pretty comprehensive solution that both provides whole-house audio and streaming on the go with a variety of ways to control the whole system – and for the wonderful price of free (except for the hardware, of course).

The key to the whole thing is MPD, the music player daemon. You can install MPD on a single-board computer (like the Raspberry Pi) or on any home server. You want a computer that sits in one place instead of a laptop, since you want to be able to stream your music anywhere. The key is making sure that it’s attached to enough storage to hold your whole music collection.

I’m going to go through the whole installation setup – partially for my own reference, but also to help anyone else out who is interested. While I’ve included guides and instructions for Windows, I have not personally tried them, so any feedback would be highly appreciated.

Setting up MPD

Download and install MPD for the operating system of your choice. (Windows instructions are here, if you have trouble with the 32 bit binaries, try the suggestions here). I would also highly recommend downloading and setting up MPC as well.

You’ll then need to edit MPD’s configuration file. The example (see it on GitHub) has lots of comments to help you understand what these things are. You specify the location of the configuration file on Windows when you run the program; on *nix the global configuration is at /etc/mpd.conf and per-user configuration is at ~/.mpd/mpd.conf .

Windows folks, my examples use *nix file paths – /home/steven/mpd instead of C:\mpd\data – so keep that in mind. We are going to keep working with mpd.conf for the next little bit.

music_directory		"/path/to/music"
# Windows:  "C:\Music" or wherever. 
# Remember to change the home directory name to match your username
# For Windows, replace /home/steven/.mpd with C:\mpd\data\
# as per https://www.chriswarrick.com/blog/2013/09/01/mpd-on-windows/
playlist_directory	"/home/steven/.mpd/playlists"
db_file			"/home/steven/.mpd/tag_cache"
pid_file		"/home/steven/.mpd/pid"
state_file		"/home/steven/.mpd/state"
sticker_file            "/home/steven/.mpd/sticker.sql"
bind_to_address         "any"
bind_to_address		"/home/steven/.mpd/socket"

Then find this bit, changing the password to one of your choosing.

# We are enabling this for Snapclient
zeroconf_enabled		"yes"
# You can use whatever name you like here.
zeroconf_name			"MPD"
password                        "YOURPASSWORD@read,add,control,admin"

Now it’s time for audio outputs. My server does not actually have speakers itself, as I’m using Snapcast to pipe the audio around my house. But if you’re not interested in that part, configure your audio like so for Windows:

audio_output {
    type "winmm"
    name "Speakers"
    device "Speakers (Realtek High Definition Audio)"

or for *nix (I’m using PulseAudio here; if you’re interested in ALSA or OSS, you probably already know how to configure those.)

audio_output {
	type		"pulse"
	name		"My Pulse Output"

If you do not add/uncomment those sections, there will be no audio output from the server. Start MPD (using the Windows instructions, sudo systemctl restart mpd.service, or just mpd

Finally, you’ll need a client. There are a bunch, but in various states of being updated and maintained – and aesthetically they’re all different. For example, there’s

There are also web clients, which tend to be better maintained and up to date in my experience. This annoys me, but hey. I’ll talk about those at the end.

Note: Since you set a password, you’ll need to let MPC know. You can specify with each time you call the program: mpc --host YOURPASSWORD@localhost) or export the environment variable. On *nix add this line to your .bashrc: export MPD_HOST=YOURPASSWORD@localhost, on Windows it’s a tish more complicated; but there are instructions at this link for you. You can also run MPC from another system by putting the server name there instead of @localhost.

Setting up Streaming

I’m referring to streaming outside your home here, so there are a few things to set up to make that work. You’ll need a dynamic DNS name (explainer, list of providers) and know how to open and redirect ports on your router. You will open port 8000 on your router so you can hear the music, and 6600 as well if you’re going to control it with an Android or iOS client from out in the world.

While there are other ways to configure streaming, MPD has a built in streaming server that we are going to use instead. So let’s add this block to mpd.conf :

audio_output {
	type		"httpd"
	name		"MyRadio"
#using mp3 format for compatibility
	encoder		"lame"
#I use 8000 here, but you can use whatever port you like                 
	port		"8000"                 
	always_on	"yes"
	replay_gain_handler	"software"
	tags		"yes"
# do not define bitrate if quality is defined
	bitrate		"64"			
	format		"22050:16:1"

# I specified a lower bitrate because I didn't 
# want to take up a bunch of data. 
# An example of higher bitrate is below.
# do not define bitrate if quality is defined
#	bitrate		"128"			
#	format		"44100:16:1"

There are a lot more options, as I mentioned. I prefer volume normalization and replaygain, for example, so I have this block as well:

replaygain			"track"
replaygain_preamp		"0"
volume_normalization		"yes"
mpc outputsmpc disable my_fifompc enable 2

MPC will allow you to list the audio outputs and toggle them on and off. You can use the output name or it’s number like in the image to the right. This is especially useful if you’ve set up whole-house audio and streaming and don’t want both going at the same time. 🙂

At this point, you can just point most web browsers at your server like this: http://server_name_or_ip_address:8000/ and listen to what’s playing!

This works but isn’t ideal… but we’ll get to that after whole-house audio.

Whole House Audio With Snapcast

If you have *nix or Macs, you’re in luck. Snapcastwhich I wrote about back in 2018 – has only gotten better and smoother. After installing Snapcast, to have our MPD server use it, we’re going to add an audio output to mpd.conf and then restart MPD:

audio_output {
    type            "fifo"
    name            "my_pipe"
    path            "/tmp/snapfifo"
    format          "48000:16:2"
    mixer_type      "software"

Right now I have music playing from my server to my phone, two single board computers hooked up to speakers in the dining room and kitchen, and to my media PC that I watch movies on.

Web Interfaces And Streaming URLs

Whether you’re streaming or not, you may want to check out the web interfaces as well, as they’re pretty darn cool. The two I prefer are O!MPD and RompЯ. They each have their strengths and very different user interfaces:

O!MPD handily requires a username and password, which RompЯ does not. That said, RompЯ has a lot of themes as well, but more importantly, you can control both the audio outputs and Snapcast easily from the main interface:

For either of these, you’ll need to set up a web server – the two most common are nginx and apache. Setting the webserver up is beyond the scope of this document (let alone setting up LetsEncrypt for SSL), but here are guides for:

Remember to open and forward port 80 and/or 443 on your router to the server!

Note: While O!MPD’s installation instructions assume the webserver is already set up, RompЯ has detailed installation instructions for pretty much every system in the sidebar of the main page.

But what about making our streaming URL prettier (and without a port number)? That’s a simple tweak in the configuration in the webserver’s conf file after making sure the proxy submodule is enabled. In both examples, substitute for the LAN IP address of your MPD machine. For nginx:

    location /mpd.mp3 {
        proxy_pass ;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;

and for apache:

    ProxyPass /mpd.mp3  !
    ProxyPassReverse /  !

Now you can stream from your home by just pointing at , using any streaming music player – including a browser or even Windows Media Player. Additionally, this gets around if ports are blocked, and lets you close port 8000 on your home server, which is good for security reasons.

Tweak Away!

Because of the way MPD and MPC are designed, it’s possible to do interesting things with them, like create “smart playlists” with a simple script, control it all via a terminal (with ascii album art!), or use Conky to display covers nicely on your desktop.

If you’ve got feedback or additional tweaks, please let me know!

Featured Photo by Wesley Tingey on Unsplash

Popular posts:

  • Weekend Project: Whole House and Streaming Audio for Free with MPD
  • Minecraft Bug: Despawning Named Zombie Villagers
  • The difference between boundaries and rules
  • If there's one Nazi (or a racist) at the table...
  • Upgrading Voxelmap and Keeping Your Waypoints in #Minecraft
  • Organizing and Tiling Your Windows on #Openbox Using Only... Openbox
  • The Context of Abusive Statements

Recent Posts

Be First to Comment

Leave a Reply