Continue playing after Internet connection is lost

Discuss about Hardware diy and tweaks

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.

Continue playing after Internet connection is lost

Postby Nico » Wed Mar 04 2015 01:39

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:

Code: Select all
#!/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


.Nico
Random avatar
Nico
Serious Listener
Serious Listener
 
Posts: 59
Joined: Mon Aug 11 2014 07:13

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.


Continue playing after Internet connection is lost

Postby djdexy » Sat Feb 20 2016 13:51

hi there,

after many attempts I was unable to start the script....

have you any ideas?

br
d
Random avatar
djdexy
Fresh off the boat
Fresh off the boat
 
Posts: 1
Joined: Sat Feb 20 2016 00:58


Continue playing after Internet connection is lost

Postby Nico » Fri Mar 11 2016 08:43

djdexy wrote:hi there,

after many attempts I was unable to start the script....

have you any ideas?

br
d


start it with sudo ?
or even better, call your script /home/pi/checkInternet.sh and add this line in /etc/rc.local just before exit:

/home/pi/checkInternet.sh & > /dev/null 2>&1

and of course you'll need the playlists 'local' and 'Radio10Live'
Random avatar
Nico
Serious Listener
Serious Listener
 
Posts: 59
Joined: Mon Aug 11 2014 07:13


Continue playing after Internet connection is lost

Postby bitinfo » Wed Mar 18 2020 21:30

This script isnt work for me. Any plugin instead?
Random avatar
bitinfo
Fresh off the boat
Fresh off the boat
 
Posts: 5
Joined: Wed Feb 26 2020 14:27


Continue playing after Internet connection is lost

Postby Nico » Sat Mar 21 2020 09:39

bitinfo wrote:This script isnt work for me. Any plugin instead?

Did you create the two playlists in mpc first?
Random avatar
Nico
Serious Listener
Serious Listener
 
Posts: 59
Joined: Mon Aug 11 2014 07:13


Continue playing after Internet connection is lost

Postby bitinfo » Sat Mar 21 2020 17:21

Nico wrote:
bitinfo wrote:This script isnt work for me. Any plugin instead?

Did you create the two playlists in mpc first?


What is "MPC"?
Random avatar
bitinfo
Fresh off the boat
Fresh off the boat
 
Posts: 5
Joined: Wed Feb 26 2020 14:27


Continue playing after Internet connection is lost

Postby Nico » Mon Mar 23 2020 19:29

mpc is the Music Player Client to be used for the Music Player Daemon (MPD)

The mentioned method of playing playlists with mpc is very old and based on Volumio version 1.5x
Since version 2.x of volumio, playing playlists is handled different.

It might still work with mpc but playing with this method does not show anything on the GUI.
It will be better to use the volumio API when using version 2.x of volumio.
It will the be something like this:

Code: Select all
#!/bin/bash

while true
    do
        if ping -c2 8.8.8.8 | grep -q 100%
        then
                if [ -f '/home/volumio/playingstream' ];
                then
                        rm /home/volumio/playingstream
                        echo "Network unreacheable" > /home/volumio/playinglocal
                        curl localhost:3000/api/v1/commands/?cmd=stop
                        curl localhost:3000/api/v1/commands/?cmd=clearQueue
                        curl localhost:3000/api/v1/commands/?cmd=playplaylist&name=usb
                        ##curl localhost:3000/api/v1/commands/?cmd=play
                fi
        else
                if [ -f '/home/volumio/playinglocal' ];
                then
                        rm /home/volumio/playinglocal
                        echo "No network issues" > /home/volumio/playingstream
                        curl localhost:3000/api/v1/commands/?cmd=stop
                        curl localhost:3000/api/v1/commands/?cmd=clearQueue
                        curl localhost:3000/api/v1/commands/?cmd=playplaylist&name=radio10-80
                        ##curl localhost:3000/api/v1/commands/?cmd=play
                fi
        fi
        sleep 20
done


Make sure you've created the playlists named 'usb' and 'radio10-80' before running this script.
playlist 'usb' is a playlists that plays all songs from the USB stick
playlist 'radio10-80' is a webradio station saved in a playlist.

Playlists should be created in the queue.

Also, create an empty file with 'touch /home/volumio/playinglocal'
This will then be replaced by 'playingstream' when you have Internet and running the script the first time.

.Nico
Random avatar
Nico
Serious Listener
Serious Listener
 
Posts: 59
Joined: Mon Aug 11 2014 07:13


Continue playing after Internet connection is lost

Postby Nico » Mon Mar 23 2020 21:39

it is also possible to add the playlist command to /volumio/app/plugins/system_controller/volumio_command_line_client/volumio.sh

in the section
case "$1" in

and then add the following underneath clear)
Code: Select all
playlist)
       /usr/bin/curl "http://127.0.0.1:3000/api/v1/commands/?cmd=playplaylist&name=$2"
       ;;


you can then use the CLI command 'volumio playlist <name of playlist>'

.Nico
Random avatar
Nico
Serious Listener
Serious Listener
 
Posts: 59
Joined: Mon Aug 11 2014 07:13


Return to Diy and Tweaks

Who is online

Users browsing this forum: No registered users and 0 guests