From 6dade5c67d76772680b9cc914e7038e3abf5c72f Mon Sep 17 00:00:00 2001 From: ktyl Date: Mon, 19 Dec 2022 21:13:23 +0000 Subject: [PATCH] Pi+MPD --- blogs/2022/12/03/automount-nfs.md | 4 + blogs/2022/12/19/pi-mpd-music-server.md | 126 ++++++++++++++++++++++++ communal-music-server.md | 4 - nfs-mpd-nas-music-server.md | 26 ----- 4 files changed, 130 insertions(+), 30 deletions(-) create mode 100644 blogs/2022/12/19/pi-mpd-music-server.md delete mode 100644 communal-music-server.md delete mode 100644 nfs-mpd-nas-music-server.md diff --git a/blogs/2022/12/03/automount-nfs.md b/blogs/2022/12/03/automount-nfs.md index 2e04aa6..3715064 100644 --- a/blogs/2022/12/03/automount-nfs.md +++ b/blogs/2022/12/03/automount-nfs.md @@ -1,5 +1,9 @@ # Automounting network drives with NFS +This is the first part of a series of posts about setting up a music server using a NAS and Raspberry Pi. The next part is [here](https://ktyl.dev/blog/2022/12/19/pi-mpd-music-server.md). + +--- + I have a NAS which supports NFS, which I use to store all of my photos, music and other media on my local network. This gives me OS-independent to all of these files, and frees up drive space on my laptops and desktop - most of which are dual-booted. On Windows it's fairly straightforward to establish a network drive, but on Linux-based systems - at least on the Debian- and Arch- based distros I find myself using - the process is a little more involved. diff --git a/blogs/2022/12/19/pi-mpd-music-server.md b/blogs/2022/12/19/pi-mpd-music-server.md new file mode 100644 index 0000000..683ffe7 --- /dev/null +++ b/blogs/2022/12/19/pi-mpd-music-server.md @@ -0,0 +1,126 @@ +# NAS-based music with a Raspberry Pi + +This follows on from my [previous post](https://ktyl.dev/blog/2022/12/03/automount-nfs.html) about setting up NFS. + +--- + +I have a large digitised collection of music, and have been experimenting with ways to set up a communal music player in my living room without defaulting to Spotify, or any other such streaming platform. +Thus far I have used an old laptop with as much music as it will fit loaded onto it, running [MPD](https://www.musicpd.org/) and plugged into some speakers. +Then, on the laptop (or usually, another, closer laptop) I can connect to the MPD instance with [ncmpcpp](https://github.com/ncmpcpp/ncmpcpp) to change tunes. +This is an OK solution, but has a few drawbacks: I'm limited to the disk of the laptop, the laptop uses more power than it needs to, and I kind of want that laptop back! + +I had the luck to grab a Raspberry Pi from a pop-up store a few weeks ago, and felt that would make a perfect, low-power, unintrusive box to attach to the speakers. +Ostensibly, the Pi is overkill for just playing music, but it's better than a whole laptop and I'm sure I'll find other jobs for it to do as time goes on. + +As for requirements, I have a desktop machine from which I often work from home, and would like my music collection available there too. +I also often use my laptop in the living room or kitchen, which is also in earshot of the speakers, and I'd like to be able to control the music from my laptop with ease - no cables. + +Ideally, these should be stored in the same place, to save having to manage duplicate files and manually synchronising locations, since I am likely to add to my collection from a variety of locations. +I have spent enough time `rsync`ing albums between machines, life is too short even on a gigabit local network. + +I've recently had the good fortune to acquire a Synology NAS, so I'm going to use that to host my music collection. +However, it's more than possible to jerry-rig a NAS using anything with a hard-drive - maybe even a second Pi. +Nothing I'm doing should be specific to Synology's hardware or software, as we'll be using [NFS](https://wiki.archlinux.org/title/NFS) to mount remote drives - but exposing an NFS shared folder to the network is therefore out of scope for this post. + +## Set up a shared folder + +The first step is to centralise my music storage. +To do this, I created a shared folder from my NAS' web interface, and exposed it to the network. + +In my case, I had to specifically add permission for other devices to access the folder via NFS - such as the Pi, my desktop and my laptop. +It was therefore prudent to assign each of these machines a static IP on my network, so that the NAS can continue to recognise them. +I also had to set it to map all users to admin, but this is almost certainly a misconfiguration on my part - don't follow me for security advice, I am just tinkering! + +My previous blog post goes into detail regarding setting up the NFS configuration. + +## Setting up the Pi + +My Pi is a Pi 4 Model B, with 4GB of RAM. +This is more than enough for my needs, and you should be able to get by with much less. +I went through the initial default setup, noticing that it's much, much slicker than it was on my gen 1 Pi, which ultimately landed me on a graphical desktop. + +First, I set a hostname and enabled SSH access, since this is to be a headless machine. +For the same reason, I disabled the auto-launch of the graphical user interface. +I would have thought that if it's booted headless, it shouldn't think to launch a graphical session in the first place, but better safe than sorry. +The point of the thing is to sip power! + +## MPD + +Next, I installed MPD. +By default, MPD sets itself up with a `systemd` unit, so it connects as soon as I run `ncmpcpp` from the Pi itself. +After a reboot, this still seems to be the case, so I'm happy with the default installation. + +I pointed it to the automounted music directory by editing `/etc/mpd.conf` and added it to the `audio` group: + +``` +music_directory "/sleeper-service/Music" + +group "audio" +``` + +Configured an output for ALSA (I was not able to make it work with Pulse): + +``` +audio_output { + type "alsa" + name "My ALSA Device" + mixer_type "software" +} +``` + +We also have to add the `mpd` user to the `audio` group to allow it to access sound devices: + +``` +sudo usermod -G audio -a mpd +``` + +And enable the driver on boot for the 3.5mm audio jack in `/etc/modules`: + +``` +sudo echo "snd-bcm2835" >> /etc/modules +``` + +I found I had errors with MPD failing to create a pid file, so I gave the `mpd` user ownership of the directory it was trying to create it in: + +``` +sudo chown -R mpd /run/mpd/ +``` + +This was a bit of a weird one, since it didn't have this error to start with. +Nonetheless, after all of that, it works! +I'm able to play music by running `ncmpcpp` on the Pi itself. + +## Remote access + +The last thing to configure is access from remote machines. +I only intend to access it from the local network, so this is pretty straightforward. +First, to expose MPD to the network, I set its address and port in `/etc/mpd.conf`: + +``` +bind_to_address "192.168.1.17" +port "6600" +``` + +Then, I need only specify the location of the Pi on the network in a local machine's `ncmpcpp` config: + +``` +mpd_host = "pifi" +mpd_port = "6600" +``` + +Of course, `pifi` is an entry in my remote machine's `/etc/hosts`. + +It's possible you have multiple MPD installations - one on your remote machine, such as a laptop, as well as an installation like the Pi. +In that case, recall that `ncmpcpp` can be launched with different configs using the `-c` flag: + +``` +alias bops="ncmpcpp -c ~/.config/ncmpcpp/config.alt +``` + +## Wrapping up + +That's all for now. +At some point in the future I'll write another post on making this setup more accessible. +I certainly like `ncmpcpp`, but it often garners a scoff from houseguests. +So, I'd like to pursue the ultimate goal of making it as straightforward to use as something like Spotify. +As always, I hope this was helpful and please don't hesitate to [get in touch](mailto:me@ktyl.dev)! diff --git a/communal-music-server.md b/communal-music-server.md deleted file mode 100644 index 9c97ad4..0000000 --- a/communal-music-server.md +++ /dev/null @@ -1,4 +0,0 @@ -For the communal music player, means of access is also something to consider. -I'm personally quite comfortable with the minimal MPD client, [ncmpcpp](https://github.com/ncmpcpp/ncmpcpp), but the aim of a _communal_ music system is to entice others, potentially houseguests to use it too. -To ask them to use a TUI system whose name doesn't even contain vowels would be an exercise in the obtuse. -Therefore, I also want a means to interact with this music player which is ideally as straightforward as Spotify. diff --git a/nfs-mpd-nas-music-server.md b/nfs-mpd-nas-music-server.md deleted file mode 100644 index b21d9af..0000000 --- a/nfs-mpd-nas-music-server.md +++ /dev/null @@ -1,26 +0,0 @@ -# Setting up a network media drive with an NFS-enabled NAS and a Raspberry Pi - -I have a large digitised collection of music, and have been experimenting with ways to set up a communal music player in my living room without defaulting to Spotify, or any other such streaming platform. -Thus far I have used an old laptop with as much music as it will fit loaded onto it, running [MPD](https://www.musicpd.org/) and plugged into some speakers. -This is an OK solution, but has a few drawbacks: I'm limited to the disk of the laptop, the laptop uses more power than it needs to, and I kind of want that laptop back as a laptop! - -I also have a desktop machine from which I often work from home, and would like my music collection available there too. -Ideally, these should be stored in the same place, to save having to manage duplicate files and manually synchronising locations, since I am likely to add to my collection from a variety of locations. -I have spent enough time `rsync`ing albums between machines, life is too short even on a gigabit local network. - -I've recently had the good fortune to acquire a Synology NAS, so I'm going to use that to host my music collection. -Nothing I'm doing should be specific to Synology's hardware or software, as we'll be using [NFS](https://wiki.archlinux.org/title/NFS) to mount remote drives - but exposing an NFS shared folder to the network is therefore out of scope for this post. -I also had the luck to grab a Raspberry Pi from a pop-up store a few weeks ago, and felt that would make a perfect, low-power, unintrusive box to attach to the speakers. -Ostensibly, the Pi is overkill for just playing music, but it's better than a whole laptop and I'm sure I'll find other jobs for it to do as time goes on. - -## Set up a shared folder - -The first step is to centralise my music storage. -To do this, I created a shared folder from my NAS' web interface, and exposed it to the network. - -In my case, I had to specifically add permission for other devices to access the folder via NFS - such as the Pi, my desktop and my laptop. -It was therefore prudent to assign each of these machines a static IP on my network, so that the NAS can continue to recognise them. -I also had to set it to map all users to admin, but this is almost certainly a misconfiguration on my part - don't follow me for security advice, I am just tinkering! - -## Setting up the Pi -