From 4bf755add9b735aa97030f288cfaae81c60c8a7c Mon Sep 17 00:00:00 2001 From: "Hristos N. Triantafillou" Date: Mon, 4 Jan 2021 14:06:17 -0600 Subject: [PATCH] Publish: Listening To Music On Linux With MPD - Part 4 Update prior posts about MPD to link back to this one. --- ...ing-to-music-on-linux-with-mpd-part-4.html | 275 ++++++++++++++++++ site/mpd-local-listening.html | 4 +- site/mpd-my-setup-2018.html | 6 +- site/mpd-through-a-bluetooth-speaker.html | 4 +- 4 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 site/blog/listening-to-music-on-linux-with-mpd-part-4.html diff --git a/site/blog/listening-to-music-on-linux-with-mpd-part-4.html b/site/blog/listening-to-music-on-linux-with-mpd-part-4.html new file mode 100644 index 0000000..6cafa14 --- /dev/null +++ b/site/blog/listening-to-music-on-linux-with-mpd-part-4.html @@ -0,0 +1,275 @@ +

Listening To Music On Linux With MPD - Part 4

+ +
+ Posted: +
+ +

+ As a follow up to my earlier pieces about using MPD MPD: My Setup 2018 MPD through a bluetooth speaker MPD for local listening, 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. 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. +

+ +

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. Including the one I use, Void Linux. 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: +

+ +
#!/bin/sh
+
+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/config.fish @ line 224
+function usv
+    env SVDIR=$HOME/.local/sv sv $argv
+end
+ +

+ 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		"0.0.0.0:6600"
+bind_to_address		"~/music/mpd/socket"
+playlist_directory	"~/music/mpd/playlists"
+db_file			"~/music/mpd/mpd.db"
+pid_file		"~/music/mpd/mpd.pid"
+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. +

+ +

Bluetooth?

+ +

+ 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"
+   XF86AudioRaiseVolume
+
+# Decrease volume
+"/home/hristos/.local/bin/volume-tweak --lower"
+   XF86AudioLowerVolume
+
+# Play key
+"mpc toggle"
+    m:0x0 + c:172
+    XF86AudioPlay
+
+# Stop key
+"mpc stop"
+    m:0x0 + c:174
+    XF86AudioStop
+
+# Prev key
+"mpc prev"
+    m:0x0 + c:173
+    XF86AudioPrev
+
+# Next key
+"mpc next"
+    m:0x0 + c:171
+    XF86AudioNext
+
+# Muting
+"/home/hristos/.local/bin/mute-or-not"
+    XF86AudioMute
+
+...
+ +

+ 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 its 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. +

+ +

Conclusion

+ +

+ 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

+ +
diff --git a/site/mpd-local-listening.html b/site/mpd-local-listening.html index 2471252..97b63cf 100644 --- a/site/mpd-local-listening.html +++ b/site/mpd-local-listening.html @@ -1,11 +1,11 @@

MPD for local listening

- Posted: | Updated: + Posted: | Updated: ,

- UPDATE! Check out my other post on MPD to see how some of the flaws of the setup described here are resolved! + UPDATE! Check out my latest post on MPD to see an updated writeup on my MPD setup and usage.

diff --git a/site/mpd-my-setup-2018.html b/site/mpd-my-setup-2018.html index c469735..0568399 100644 --- a/site/mpd-my-setup-2018.html +++ b/site/mpd-my-setup-2018.html @@ -1,13 +1,11 @@

MPD: My Setup 2018

- Posted: | Updated: + Posted: | Updated: ,
-

UPDATE: Of course not even a week after I posted this, I've made yet another tweak -- see the Bonus section at the end of the entry for more details.

-

- It's also worth mentioning that since I published this and the updated entry, I've stopped using a Bluetooth speaker with MPD. There were just too many issues with reliability and "lag" that I now connect my bluetooth speaker with an audio cable. A fair warning for those that want to go down this path. + UPDATE! Check out my latest post on MPD to see an updated writeup on my MPD setup and usage.

diff --git a/site/mpd-through-a-bluetooth-speaker.html b/site/mpd-through-a-bluetooth-speaker.html index 11f7bb3..7e0deeb 100644 --- a/site/mpd-through-a-bluetooth-speaker.html +++ b/site/mpd-through-a-bluetooth-speaker.html @@ -1,11 +1,11 @@

MPD through a bluetooth speaker

- Posted: | Updated: + Posted: | Updated: ,

- UPDATE: be sure to check out my updated entry on MPD! + UPDATE! Check out my latest post on MPD to see an updated writeup on my MPD setup and usage.

-- 2.30.2