This is i fundamental thing for how I want my piradio so I’m glad I finally made it work and I’ve seen questions about making something like this work.
The idea of my radio is that it plays from a list of streamed radio stations (di.fm, rockradio, philosomatika et.c) and that it should start playing right away without the need of any buttons clicked or a second interface like a phone. Mopidy only adds a secondary layer with that I can play stuff from Google Music and Soundcloud.
What I did was to install mpc:
sudo apt-get install mpc
With that I can check if anything is already playing, it wont be at startup but I added this anyway. If nothing is playing the que will be cleared and the playlist of choice will be added and played instead. I added “sleep” to wait for Mopidy to start and maybe I could have done with less time but 45 seconds is what it takes for my adafruit lcd to display stuff.
The script:
#!/bin/sh
sleep 45 # Waits 45 seconds.
if mpc status | awk 'NR==2' | grep playing; then
echo "Already playing, do nothing"
else
# Nothing is playing
echo "--Play playlist--"
echo "-----------------"
mpc clear
mpc load streams
mpc play
fi
“streams” is the name of the playlist.
I would like to invert the grep so I don’t need the “do nothing” part, if so I will change my script.
And then I added this at the end of my crontab:
@reboot sh /home/pi/autoplay.sh &