I’m using my Raspberry PI as a MusicPlayer en most of the times I’m playing a radio stream from the Internet. However, when the Internet connection is lost the stream stops. (duh…) so I made a script that runs at startup and checks every 20 seconds if the Internet is still up. If not, mpc kicks in and loads a local playlist to play songs from the local storage. When Internet is back on, mpc kicks in again and starts my favourite radio stream.
This is the script:
#!/bin/bash while true do if ping -c2 www.google.nl | grep -q 100% then if [ -f '/home/pi/playingstream' ]; then rm /home/pi/playingstream echo "Network unreacheable" > /home/pi/playinglocal mpc stop mpc clear mpc load local mpc play fi else if [ -f '/home/pi/playinglocal' ]; then rm /home/pi/playinglocal echo "No network issues" > /home/pi/playingstream mpc stop mpc clear mpc load Radio10Live mpc play fi fi sleep 20 done