MPD autoplay feature

At a workshop that I go to we have a music station that’s been playing rock and metal music for a very long time.

The player used was a generic MP3 player hacked to get power from a 5V charger and since it’s very old it has just(!) 2GB of storage, so not many songs fit on it and you can imagine the playlist repeats itself quite often.

Some time ago we talked about something and an idea popped up to make an upgrade to the music station. We had an RPi 1, wifi adapter and 16GB flash drive laying around, so I put those together to make a music station. And with that you also need a some kinda system to actually play music.

I experimented with various different OS’e just for that – Volumio, RuneAudio (and the other version RuneAudio+R E2), Pi MusicBox and Moode Audio.

I stuck with Moode because, in my particular use-case, it’s very simple to use and had a setting to auto-play last playlist when the RPi boots up, because we turn off the electricity when we close the workshop.

But RuneAudio was very fast to boot on RPi1 – in about 20 secs. it would be ready to play, whereas Moode takes about 1.5 minutes, but that isn’t an issue at all. Also Moode has the ability to play radio stations very easily and even has a huge list already built-in.

But after a while I noticed that in rare cases Moode doesn’t play on boot. Also since the workshop is public and Moode is available to control through the web browser to anyone, it’s possible that someone might do something and leave it not playing.

I figured that all these music distros have MPD as their backend and add a nice wrapper to control it. Therefore you can connect to MPD locally and control it. That means you can add automated features with scripts that aren’t included in the distro of your choice, like adding an auto-play feature. Given that the distro has SSH, cron and can run scripts.

So anyway, I made a script that simply resets a playlist if not playing already to ensure it always plays music. For that I used Python and python-mpd2 lib which essentially does this: checks if music is playing, if not – clears current playlist, loads a playlist by a hard-coded name, sets random play on and starts playing. The script for that can be found here.

To use it in Moode, I connected to it with SSH, as root enabled cron to autostart on boot with systemctl enable cron, installed the lib dependency with pip install python-mpd2, added a cronjob to start the script every minute and done.


Notify of

Inline Feedbacks
View all comments