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.
    • mituM
      mitu Global Moderator
      last edited by mitu

      If you're using the method in https://retropie.org.uk/forum/topic/9133/quick-and-easy-guide-for-adding-music-to-emulatonstation-on-retropie-noob-friendly, it would as simple as replacing the the invocation of mpg123 -Z /home/pi/bgm/*.mp3 with a cli radio streaming player - live clvc (part of the VLC package, which I think is installed by default).

      Something like clvc <radio_url>. Then - in the accompanying scripts - replace mpg123 in the commands to pause/resume the playing with cvlc.

      You could do something more elaborate by having cvlc read the playlist from a file in /home/pi/fm, so it would be configurable.

      pipesfrancoP 1 Reply Last reply Reply Quote 1
      • pipesfrancoP
        pipesfranco @mitu
        last edited by

        @mitu Thank you for your response...would anyone be able to do this ...im a coding noob!

        mituM 1 Reply Last reply Reply Quote 0
        • mituM
          mitu Global Moderator @pipesfranco
          last edited by

          @pipesfranco Is the page I gave as an example simple enough ? I might replicate it and add explicitly the commands needed.

          pipesfrancoP 1 Reply Last reply Reply Quote 0
          • pipesfrancoP
            pipesfranco @mitu
            last edited by

            @mitu Thank you so much, you rock buddy :)

            mituM 1 Reply Last reply Reply Quote 0
            • mituM
              mitu Global Moderator @pipesfranco
              last edited by

              @pipesfranco since I don't have the RPI at hand now, I'll get back to you tomorrow, so I can test the scripts first.

              pipesfrancoP 1 Reply Last reply Reply Quote 0
              • pipesfrancoP
                pipesfranco @mitu
                last edited by

                @mitu Thats great thanks mitu :)

                1 Reply Last reply Reply Quote 0
                • pipesfrancoP
                  pipesfranco
                  last edited by pipesfranco

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

                  1 Reply Last reply Reply Quote 0
                  • mituM
                    mitu Global Moderator
                    last edited by mitu

                    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.

                    jonnykeshJ N 2 Replies Last reply Reply Quote 3
                    • R
                      robertybob
                      last edited by

                      This would be a great addition to the Wiki :)

                      1 Reply Last reply Reply Quote 0
                      • jonnykeshJ
                        jonnykesh @mitu
                        last edited by

                        @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.

                        mituM cyperghostC 2 Replies Last reply Reply Quote 0
                        • mituM
                          mitu Global Moderator @jonnykesh
                          last edited by

                          @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
                          • pipesfrancoP
                            pipesfranco
                            last edited by

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

                            1 Reply Last reply Reply Quote 0
                            • pipesfrancoP
                              pipesfranco
                              last edited by

                              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

                              :)

                              mituM 1 Reply Last reply Reply Quote 0
                              • mituM
                                mitu Global Moderator @pipesfranco
                                last edited by

                                @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

                                  @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.

                                  mituM 1 Reply Last reply Reply Quote 0
                                  • mituM
                                    mitu Global Moderator @NowArrivingHere
                                    last edited by

                                    @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 Reply Quote 0
                                    • N
                                      NowArrivingHere @mitu
                                      last edited by

                                      @mitu
                                      Sure. Here you go

                                      echo -n pause | nc -U /tmp/radio.sock >/dev/null 2>&1
                                      
                                      mituM 1 Reply Last reply Reply Quote 0
                                      • mituM
                                        mitu Global Moderator @NowArrivingHere
                                        last edited by

                                        @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 Reply Quote 0
                                        • N
                                          NowArrivingHere @mitu
                                          last edited by

                                          @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]
                                          
                                          mituM 1 Reply Last reply Reply Quote 0
                                          • mituM
                                            mitu Global Moderator @NowArrivingHere
                                            last edited by mitu

                                            @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 Reply Quote 0
                                            • First post
                                              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.