• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
RetroPie forum home
  • Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login

Streaming internet radio when browsing for games and on screensaver?

Scheduled Pinned Locked Moved Ideas and Development
internetradiostreamingmp3
47 Posts 7 Posters 8.4k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P
    pipesfranco @mitu
    last edited by 29 Sept 2017, 21:13

    @mitu Thats great thanks mitu :)

    1 Reply Last reply Reply Quote 0
    • P
      pipesfranco
      last edited by pipesfranco 29 Sept 2017, 21:25

      This is my station of choice, C64 remixes https://www.slayradio.org/home.php#news

      1 Reply Last reply Reply Quote 0
      • M
        mitu Global Moderator
        last edited by mitu 10 May 2017, 17:08 30 Sept 2017, 06:17

        Ok, here it goes.

        All credit goes to @synack for putting together the easiest method for playing mp3's while in emulationstation. The steps have been summarized by @MapleStory here and I only replaced the mpg123 command with vlc.
        NOTE: I tested the instructions below only on a Raspberry PI system installed from the RetroPie. image, so YMMV.

        The steps must be executed either logged in to the RetroPie system via SSH or by exiting EmulationStation and dropping down to a command prompt.

        Playing a radio internet stream in the background

        Pre-requisites

        The instructions assume you have VLC and socat installed on the RetroPie system. The RetroPie setup script already installs VLC, but the latter must be installed explicitely. The command to install the packages is (copy paste in the SSH/terminal session logged in as the pi user):

        sudo apt-get -y install vlc-nox socat
        

        Step 1

        Edit /opt/retropie/configs/all/autostart.sh to add the command for music playing:

        sudo nano /opt/retropie/configs/all/autostart.sh
        

        Once in nano, hit enter to create a line break above emulationstation #auto. Go up to the blank line and type/paste the following:

        while pgrep omxplayer >/dev/null; do sleep 1; done
        (sleep 10; [[ -f /home/pi/radio/list.txt ]] && vlc -I oldrc --rc-fake-tty --rc-unix /tmp/radio.sock -Zq --no-video /home/pi/radio/list.txt >/dev/null 2>&1) &

        Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

        Step 2

        Edit the on-start file to stop the music playing once a game is started

        Execute the following command to edit the on-start script file

        sudo nano /opt/retropie/configs/all/runcommand-onstart.sh
        

        Once inside, type/paste the following:

        echo -n pause | socat -u - unix-client:/tmp/radio.sock >/dev/null 2>&1
        

        Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

        Edit the on-end file to start back the music once a game is finished.

        Execute the following command to edit the on-end script file:

        sudo nano /opt/retropie/configs/all/runcommand-onend.sh
        

        Once inside, type/paste the following:

        echo -n pause | socat -u - unix-client:/tmp/radio.sock >/dev/null 2>&1
        

        Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

        Step 3

        Edit your .bashrc so that music is stopped once you stop EmulationStation and drop to the CLI. Execute the following command:

        nano /home/pi/.bashrc
        

        Once inside, scroll to the very bottom of the file and create a line break under retropie_welcome but above # RETROPIE PROFILE END and type/paste the following:

        [[ $(tty) == "/dev/tty1" ]] && (echo -n quit | echo -n quit | socat -u - unix-client:/tmp/radio.sock >/dev/null 2>&1)
        

        Step 4

        Create the radio playlist folder and the input file:

        mkdir /home/pi/radio
        touch /home/pi/radio/list.txt

        Optional
        Adding the SLAY Radio High def stream to the file:

        echo "https://relay3.slayradio.org:8000" >> /home/pi/radio/list.txt
        

        And this is basically it. Add the URLs to the radio strreams in the list.txt file, one URL per line. You can do this while logged in via SSH on the RetroPie system by using nano to edit the file:

        nano /home/pi/radio/list.txt
        

        then add the HTTP URLs one per line with copy/paste.

        NOTE: URLs ending with m3u are not accepted by vlc, you have to download them first (they're just text files) and look-up the correct URL from the m3u file. For instance, the https://www.slayradio.org/tune_in.php/128kbps/slayradio.128.m3u file contains:

        #EXTM3U
        #EXTINF:-1,SLAY Radio - 128kbps, relay2 [shoutcast - kork]
        http://relay2.slayradio.org:8000/
        #EXTINF:-1,SLAY Radio - 128kbps, relay3 [shoutcast - farsan]
        http://relay3.slayradio.org:8000/
        #EXTINF:-1,SLAY Radio - 128kbps, relay1 [shoutcast - elpost]
        http://relay1.slayradio.org:8000/
        #EXTINF:-1,SLAY Radio - 128kbps, relay4 [icecast - icepic]
        http://relay4.slayradio.org:8000/

        The correct URL to add in the list.txt file would be one of the http... entries.

        Finally, reboot the system from the EmulationStation menus and enjoy.

        Addendum

        The vlc command will play randomly one of the radio streams in the file. If you want to have a new radio stream played every time you return from a game, then add the following line in Step 2, in the on-end script:

        echo -n next | socat -u - unix-client:/tmp/radio.sock >/dev/null 2>&1
        

        If you want to stop the background music, just rename or remove the /home/pi/radio/list.txt file, then modify the files /opt/retropie/configs/all/runcommand-onstart.sh and /opt/retropie/configs/all/runcommand-onebd.sh and remove the line added in Step 2.

        J N 2 Replies Last reply 30 Sept 2017, 20:42 Reply Quote 3
        • R
          robertybob
          last edited by 30 Sept 2017, 20:13

          This would be a great addition to the Wiki :)

          1 Reply Last reply Reply Quote 0
          • J
            jonnykesh @mitu
            last edited by 30 Sept 2017, 20:42

            @mitu This is cool. There is a script to toggle background music on / off. You could change this to toggle the radio on / off.

            #!/bin/bash
            #Toggle to start / stop any Music Player or Video Player
            command="mpg123"
            pids="$( pgrep "$command" )"
            #if [[ -z "$pids" ]]; then
            # printf '"%s" is not running\n' "$command" >&2
            # exit 1
            #fi
            for pid in $pids; do
            state="$( ps -ostate= -p "$pid" )"
            stopped=0
            case "$state" in
            *T*) stopped=1 ;;
            esac
            if (( stopped )); then
            kill -s CONT "$pid"
            # printf '"%s" (%d) has been unpaused\n' "$command" "$pid"
            else
            kill -s STOP "$pid"
            # printf '"%s" (%d) has been paused\n' "$command" "$pid"
            fi
            done

            I wish I could remember who wrote it so I could give them credit.

            M C 2 Replies Last reply 1 Oct 2017, 10:07 Reply Quote 0
            • M
              mitu Global Moderator @jonnykesh
              last edited by 1 Oct 2017, 10:07

              @jonnykesh It's quite similar to the method in the topic I mentioned first, so it might have originated there.
              I used the vlc control-over-unix-socket method instead of the script because it gives more control over how the playlist should be played - you can jump to the next radio station in the playlist when going back to ES from a game.

              1 Reply Last reply Reply Quote 0
              • P
                pipesfranco
                last edited by 2 Oct 2017, 19:53

                This is awesome thank you so much for your help :)

                1 Reply Last reply Reply Quote 0
                • P
                  pipesfranco
                  last edited by 3 Oct 2017, 21:28

                  One last thought guys...is there anyway to make the radio fade out rather than cut out once a game is selected and fade back in when you exit a game?

                  No big issue but just a thought?

                  Thanks again

                  :)

                  M 1 Reply Last reply 4 Oct 2017, 06:05 Reply Quote 0
                  • M
                    mitu Global Moderator @pipesfranco
                    last edited by 4 Oct 2017, 06:05

                    @pipesfranco I actually tried adding a cross-fade effect when stopping/resuming vlc, but it does not support that. Various searches on the interwebs show that it's not implemented in currently (see for instance this ticket).

                    I'll see if we can find an alternative to VLC that supports both streaming from internet radio sources and fade out/in for audio.

                    1 Reply Last reply Reply Quote 0
                    • N
                      NowArrivingHere @mitu
                      last edited by NowArrivingHere 10 Apr 2017, 12:13 4 Oct 2017, 10:49

                      @mitu

                      Raspberry Pi 3B
                      2.4A power supply
                      Raspbian Stretch
                      RetroPie 4.3.1

                      I haven't been able to get this working properly. I suspect there is a problem with my particular setup. I have RetroPie installed on top of Raspbian Stretch, which I know has issues.

                      Step 1 and 4 work fine for me. I was able to install everything, add my station (AI Radio), and get it to start playing automatically when emulationstation starts. However, step 2 and 3 are where everything falls apart.

                      The step 2 runcommand-onstart.sh breaks my runcommand. The music keeps playing and my chosen emulator fails to launch. I tried copy-pasting. I tried typing by hand. I even looked at the other thread and used chmod to allow execution privileges for all. It didn't work. The files were newly created and no other commands were added.

                      As for Step 3, my .bashrc doesn't have a retropie_welcome or #RETROPIE PROFILE END

                      Again, it is clear some people have gotten this working, so it is probably down to my particular setup. I'm just not sure what I did wrong.

                      M 1 Reply Last reply 4 Oct 2017, 16:08 Reply Quote 0
                      • M
                        mitu Global Moderator @NowArrivingHere
                        last edited by 4 Oct 2017, 16:08

                        @nowarrivinghere Can you paste here the contents of the /opt/retropie/configs/all/runcommand-onstart.sh file ? It seems this is the stuff that breaks for you.

                        N 1 Reply Last reply 4 Oct 2017, 16:18 Reply Quote 0
                        • N
                          NowArrivingHere @mitu
                          last edited by 4 Oct 2017, 16:18

                          @mitu
                          Sure. Here you go

                          echo -n pause | nc -U /tmp/radio.sock >/dev/null 2>&1
                          
                          M 1 Reply Last reply 4 Oct 2017, 16:19 Reply Quote 0
                          • M
                            mitu Global Moderator @NowArrivingHere
                            last edited by 4 Oct 2017, 16:19

                            @nowarrivinghere You might be missing the nc utility. Does the command works if you run it in a terminal ? Just type nc and see if you get any error.

                            N 1 Reply Last reply 4 Oct 2017, 16:22 Reply Quote 0
                            • N
                              NowArrivingHere @mitu
                              last edited by 4 Oct 2017, 16:22

                              @mitu

                              pi@raspberrypi:~ $ nc
                              usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-O length]
                                        [-P proxy_username] [-p source_port] [-q seconds] [-s source]
                                        [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]
                                        [-x proxy_address[:port]] [destination] [port]
                              
                              M 1 Reply Last reply 4 Oct 2017, 16:25 Reply Quote 0
                              • M
                                mitu Global Moderator @NowArrivingHere
                                last edited by mitu 10 Apr 2017, 17:25 4 Oct 2017, 16:25

                                @nowarrivinghere So netcat is installed. What happens if you run the command from the onstart file manually, after ES is started and the music plays ? It should pause the music.

                                echo -n pause | nc -U /tmp/radio.sock >/dev/null 2>&1
                                

                                Can you run the command from a SSH session and see what's the outcome ? If it works (i.e. music is paused), try starting a game and (after you get thrown back to ES ) then paste the contents of the /var/shm/runcommand.log file, we might have some clues there.

                                N 1 Reply Last reply 4 Oct 2017, 16:47 Reply Quote 0
                                • C
                                  cyperghost @jonnykesh
                                  last edited by cyperghost 10 Apr 2017, 17:44 4 Oct 2017, 16:44

                                  @jonnykesh said in Streaming internet radio when browsing for games and on screensaver?:

                                  I wish I could remember who wrote it so I could give them credit.

                                  Not written completly just modified a bit... but I introduced here.... with correspondending source ;)

                                  1 Reply Last reply Reply Quote 0
                                  • N
                                    NowArrivingHere @mitu
                                    last edited by 4 Oct 2017, 16:47

                                    @mitu

                                    Okay, I just used SSH to try the pause command while the music was playing. I've waited about 90 seconds. Music is still playing and the SSH window is unresponsive.

                                    M 1 Reply Last reply 4 Oct 2017, 17:02 Reply Quote 0
                                    • M
                                      mitu Global Moderator @NowArrivingHere
                                      last edited by mitu 10 Apr 2017, 18:03 4 Oct 2017, 17:02

                                      @nowarrivinghere Sorry, forgot about removing the redirection. Execute this:

                                      ls -l /tmp/radio.sock
                                      echo -n pause | nc -U /tmp/radio.sock

                                      I suspect it might be a permission problem.

                                      N 1 Reply Last reply 4 Oct 2017, 17:16 Reply Quote 0
                                      • N
                                        NowArrivingHere @mitu
                                        last edited by NowArrivingHere 10 Apr 2017, 18:17 4 Oct 2017, 17:16

                                        @mitu

                                        Still fails to pause and leaves the window stuck.

                                        pi@raspberrypi:~ $ ls -l /tmp/radio.sock
                                        srwxr-xr-x 1 pi pi 0 Oct  4 16:42 /tmp/radio.sock
                                        pi@raspberrypi:~ $ echo -n pause | nc -U /tmp/radio.sock
                                        
                                        M 1 Reply Last reply 4 Oct 2017, 17:40 Reply Quote 0
                                        • M
                                          mitu Global Moderator @NowArrivingHere
                                          last edited by 4 Oct 2017, 17:40

                                          @nowarrivinghere I have no idea why it does that - maybe Stretch has a different version of VLC that's not the same as the one I tested and the old interface doesn't work anymore ?

                                          Just to check if there is a problem with newer versions, kill the VLC that is started via the autostart with killall vlc, then start the playback directly from thessh session, by running

                                          vlc -I oldrc --rc-unix /tmp/radio.sock -Zq --no-video /home/pi/radio/list.txt
                                          

                                          You should get the radion playing this way with logging from VLC on the terminal.
                                          Now, from a 2nd SSH session, run the echo command that's giving you trouble and see if it pauses the stream or any error appears in the 1st terminal, where VLC is running.

                                          Other than that, maybe the output of /dev/shm/runcommand.log from starting a game might be of use.

                                          N 1 Reply Last reply 5 Oct 2017, 02:08 Reply Quote 0
                                          26 out of 47
                                          • First post
                                            26/47
                                            Last post

                                          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.

                                            This community forum collects and processes your personal information.
                                            consent.not_received