Listening To Music On Linux With MPD - Part 4


As a follow up to my earlier pieces about using MPD 1 2 3, I present to you a rundown of my current setup for listening to music with MPD. Things are mostly the same as before, but I now do things somewhat differently so I thought this could be a nice opportunity to tie things together. There's no need to read my prior posts unless you want to; this one will cover everything end-to-end as they do. With that out of the way, let's crank the volume!

Why MPD?

It's worth noting why I prefer to use MPD. There are plenty of really great graphical music players such as Strawberry and QuodLibet, so why go to the trouble of using MPD?

There are probably many ways to answer that question, but for me it boils down to a few things:

In a nutshell, the main initial selling points for me were the low resource usage and good performance points. After dealing with other players bringing my system to a slow crawl, I needed a change. 10

What Do You Need?

To use MPD, you need to run a server and connect to it with a client. There are a variety of clients, my primary being ncmpcpp, mentioned above. I highly encourage you to look around for the right client, but if you like TUI applications then ncmpcpp is a great place to start. In any case, this entry will limit discussion largely to only this client.

The Server: The Service

I run the server as a runit user service, but most if not all distros ship MPD with a system-level service file. 11 It's up to you how to run it, I go the "user service" route because this doesn't need any extra privileges; running as my normal login user is totally fine, for this setup.

This is what my service file ($HOME/.local/sv/mpd/run) looks like:


exec mpd --no-daemon /home/hristos/music/mpd/mpd.conf

I have a fish function that I use as a shortcut for interacting with it:

$ functions usv
# Defined in /home/hristos/.config/fish/ @ line 224
function usv
    env SVDIR=$HOME/.local/sv sv $argv

This makes managing the service much nicer:

$ usv stop mpd
ok: down: mpd: 0s, normally up
$ usv start mpd
ok: run: mpd: (pid 25536) 0s

Of course there are many ways to run a service like MPD. Do what works best for you or what your OS requires you to do.

The Server: The Config

As for the server configuration, there's nothing special going on:

music_directory		"~/music"
bind_to_address		""
bind_to_address		"~/music/mpd/socket"
playlist_directory	"~/music/mpd/playlists"
db_file			"~/music/mpd/mpd.db"
pid_file		"~/music/mpd/"
state_file		"~/music/mpd/mpdstate"
log_file		"~/music/mpd/mpd.log"
user			"hristos"
group			"hristos"
restore_paused		"yes"
replaygain		"off"

audio_output {
    type	"pulse"
    name	"pulse"
    server	"localhost"

audio_output {
    type	"fifo"
    name	"Visualizer"
    path	"~/music/mpd/mpd.fifo"
    format	"44100:16:2"

audio_output {
    type	"httpd"
    name	"http"
    port	"8340"
    encoder	"vorbis"
    format	"44100:16:1"

At the top I set various server parameters such as where the music lives, where to write the socket, where to read playlists, and so on. I've got two values for bind_to_address; you can omit the first one that defines the port if you aren't going to need remote connections (for instance, to use the Android client).

The following three audio_output blocks each define how MPD emits music for me to enjoy:

This is more or less the same setup I've used since the beginning, which as I write this makes me think that another feature of MPD is that it stays the same.

The Client: The Choices

Although ncmpcpp is my primary MPD client, I do actually employ two other clients that are worth mentioning:

The Client: The Config

My ncmpcpp config ($HOME/.ncmpcpp/config) is pretty short, but there are some key things inside:

execute_on_song_change = notify-send "♫ Now Playing: $(mpc current)"
mpd_host = "~/music/mpd/socket"
visualizer_fifo_path = "~/music/mpd/mpd.fifo"
visualizer_output_name = "Visualizer"
visualizer_sync_interval = "120"
visualizer_in_stereo = "yes"
visualizer_type = "spectrum"
visualizer_look = "◆▋"

The first line sends a notification message when a new song begins playback, and the second line points us to the MPD server socket.

The rest of the config is setup for the visualizer and can be omitted if you don't use that. In any case, pretty simple stuff that's easy to reason about.


My previous blog entries about MPD discussed using it with a bluetooth speaker. Since then, I've actually dropped bluetooth from my stack and now connect the speaker to my laptop with an eighth inch audio cable.

No matter what I did, I always seemed to end up with playback skipping when using bluetooth. I tried to work with it and around it for years, but this past summer I decided I had enough and got a cheap cable.

Of course now, with a cable, playback skipping is nonexistent and I don't have to mess with pairing. Still, if you want to go the bluetooth route: do be aware that it mostly works but has some annoying pitfalls.

In any case, I'm no longer including bluetooth coverage as part of my MPD setup. If you're interested in that, please refer to my older post but do note that it isn't fully comprehensive in describing all the things you may need to do for an optimal experience.

Extras: Keyboard Controls

Technically optional but potentially useful: I'll discuss my setup for using the media keys on my keyboard to control MPD. This is essentially unchanged from before, I'm just re-covering it here for posterity.

I'm using xbindkeys to handle these keybinds, and here's a snippet of the MPD parts of my $HOME/.xbindkeysrc file:

# Increase volume
"/home/hristos/.local/bin/volume-tweak --raise"

# Decrease volume
"/home/hristos/.local/bin/volume-tweak --lower"

# Play key
"mpc toggle"
    m:0x0 + c:172

# Stop key
"mpc stop"
    m:0x0 + c:174

# Prev key
"mpc prev"
    m:0x0 + c:173

# Next key
"mpc next"
    m:0x0 + c:171

# Muting


The volume-tweak and mute-or-not scripts seen above are wrappers I've written to handle the various commands I need to use. They both interact with PulseAudio to properly set the volume up or down, or mute/unmute as needed.

Other keybinds simply use mpc directly. I get system notifications for those events "for free" due to the usage of execute_on_song_change in my ncmpcpp config file.

Extras: HTTPD Server

The vast majority of folks won't really have a use for this, but it's a neat thing so I always like to discuss the httpd output feature of MPD.

As the name implies, the feature streams your playback over HTTP. And, as I mentioned above, it's actually this feature which drives the playback of this website's radio page.

I'm sure there are other possible creative usages for this, but for the normal "I need a music player" use-case I assume it isn't a feature folks usually look for.


MPD remains a key piece of software in my personal stack. It may sound silly to consider a music player like this, but it really is a major part of my productivity - I listen to music to relax, to work, and so on. It's fair to say I depend on it.

It's also worth noting that MPD isn't for eveyone. If the idea of running a service for your music player, and/or a TUI client isn't something you love, then MPD might not be right for you.

Additionally: the setup described here is meant for a local collection that you actually own. If you're a user of music "services" then MPD may or may not work for you at all.

In any case, thank you for reading this far! I hope you found it a useful reference, or an interesting read. And whether or not MPD is your ideal music player it is definitely worth a look if you've never tried it before.

Footnotes And References

1 MPD: My Setup 2018

2 MPD through a bluetooth speaker

3 MPD for local listening

4 Clementine, which by the way is (was?) a fantastic piece of software.

5 I rarely use my laptop as a jukebox, but it does happen from time to time.

6 GUI stands for Graphical user interface.

7 In general, resource usage on my server+client setup is very low. I don't have any hard data to demonstrate this, just the anecdote of my years of experience using and observing this setup.

8 Even on older hardware, like my Thinkpad T61.

9 TUI stands for Text-based user interface.

10 That was in 2015 and I've since never looked back! I have looked at how other players have advanced, which is how I found out about Strawberry, but MPD remains as what does the job best for me.

11 Including the one I use, Void Linux.

12 In my full setup, I use a Pulse-to-Jackd bridge, but that's for another blog entry.

13 Unless, of course, you aren't into visualizers. Then for sure just omit this.

This page was last modified on: 2021-12-22