Philip P. Ide

Author, programmer, science enthusiast, half-wit.
Life is sweet. Have you tasted it lately?

User Tools

Site Tools


blog:articles:raspberry:mpd_network

MPD and NAS

I have Volumio on a Raspberry Pi 4, which I think is fantastic software, but there are two gripes I have with it:

  1. Despite setting “Allow UI Statics Collection” to off, stats collection is still enabled
  2. In order to play music on the device I'm controlling it from (e.g. my phone), I have to pay

I can do without paying, I've paid enough and I'm on a tight budget but the stats collection gets up my nose. Whilst they may no longer collect UI stats data and send it to themselves, there are cookies from google analytics, google tag manager, facebook and paddle.com. Making me think my data is not being collected when it still is, is a bad thing, and the fact that these cookies can track a lot more than 'how I use the player' is horrendous.

Time for something new.

MPD

I grabbed a spare micro SD card and installed a copy of DietPi on it (my favourite OS for headless Raspberry Pi's). Once the Pi was up and running, I did some basic configuration stuff (such as change default passwords and give the Pi a hostname), then created a music folder in

/mnt/samba

…where I could mount the share on my NAS that holds all my music.

Next up, I installed

O!MPD

…which installs MPD, MySQL, PHP, and the O!MPD web management system. You can choose another web manager, DietPi has several you can choose from in its software catalogue. You can also choose which webserver engine you want: I chose nginx.

My music folder is:

/mnt/samba/music

…so then I used the DietPi-Drive_Manager to mount my share into that folder. O!MPD barfed a few times trying to access that folder, and the best fix I found was to add mpd to the dietpi group. I'm sure someone will tell me that's not the best way, but I had to get it working, and this did the trick.

    sudo usermod -a -G dietpi mpd

At this stage you can use mpc (the command-line client for mpd) to tell mpd to update its database, but it's just as easy to do it using the web interface, so that's what I did. It was necessary to tell O!MPD where the music lives (/mnt/samba/music), but setting it in the web manager also sets it in mpd too. Once the 'update' button was clicked, it was time to sit back and have a snooze - I have a lot of music.

Once that's done, it's necessary to stream the music (as well as play it on the attached studio speakers), so you can listen on your phone/tablet/laptop blah-di-blah. To do this, edit /etc/mpd.conf and scroll down looking for the section audio output where the type is httpd. Mine looked like this after editing:

audio_out {
  type "httpd"
  name "Juliet Music Stream"
  port "8000"
  bind_to_address "xxx.xxx.xxx.xxx" # there's an actual local ip address here
  bitrate "128"
  format "44100:16:2" # 44.1khz, 16-bit bit-depth, 2-channels (same as CD)

Note the bitrate is half CD quality - I don't want to burn up my data allowance too quickly, and besides, bluetooth bandwidth is limited anyway. An mp3 is between 1/4 and 1/3 of CD quality, and bluetooth has less bandwith than an mp3. After saving this file, restart mpd:

sudo systemctl restart mpd

O!MPD and MAFA

Using the web interface, I can select an album by various categories (genre, artist, album, recents, most-played etc.), by my music is orgnised such that it's easiest to navigate to an album using the file system structure. When I selected an album it started playing, and my music cheerfully blared out of the speakers. That works. Next, onto the reason I wanted this setup in the first place - streaming to my phone when I'm out of the house.

I'd heard a lot of good things about MAFA, an app available for android phones so I installed that. Here's the nice bit - all I had to do was point it at my Raspberry Pi I'd just been setting up, using the local IP address (it has a fixed address). To test, I simply turned WiFi off on my phone, and mobile data on. I have a VPN which tunnels me into my home network, so I enabled that on my phone too.

Hmmm, not working. MAFA is failing to connect. I checked Network settings on MAFA: 'mobile' is enabled (you can also enable it for wifi and vpn, but I just wanted to test mobile data usage). It isn't necessary to select VPN, when the VPN is active, everything goes through it anyway (I use Wireguard). It took me a while to figure out that I also had to enable 'metered' in Network settings. MAFA instantly connected and I was able to select a track and hear it come out of the studio speakers attached to the Raspberry Pi.

To the right of the play controls (in MAFA) is an icon that looks like it woud take you to a graphic equaliser. Instead, it takes you to a screen where you have three very important controls. One allows you to enable/disable ALSA output on the Raspberry Pi, and another sends (or not) the inbound httpd stream to the phone's out system (the speakers or headset, whichever is currently enabled). So, I disabled the output at home and enabled output on my phone, and we're all done.

Adding Music

If I get another CD I'll rip it to FLAC and upload it to my NAS. Then I jump on O!MPD (the web manager) and in the settings I select Update. This gives two options, which are not appropriately named.

To give more distinction, the upper option will allow you to rescan any folder in your music heirarchy (including the root causing a full rescan), and the lower option does a full rescan. I just set the upper option to scan the parent directory of the one I just added and wait for it to finish.

If you have lots of music - I have in excess of 44k tracks (although there is some duplication in earlier stuff) - scanning and rescanning can take a long time, so being able to update a single folder and its sub-folders is very welcome.

Conclusion

It turned out to be a lot less hassle than I expected to setup this system. I have to agree that Volumio generally has a better web interface, but I only use O!MPD to update the database anyway, so I don't care about that. If you wanted a whole-house system, it is very easy to add Shoutcast or Icecast to the system, to ensure each speaker in your house plays in synch with the others. You can even set each 'node' (room) to a zone, and select which zones are active when you play.

One more note about MPD - you can 'partition' the stream. By default, there is only one partition - anyone connecting to the stream hears what you hear. If they change the track/playlist, you hear what they selected. Annoying. By adding a new partition, someone else can listen to their own playlist without disturbing yours - you can listen to different music from them at the same time.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
blog/articles/raspberry/mpd_network.txt · Last modified: 2024/05/08 16:25 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: Copyright © Phil Ide
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki