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.
    • 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
                            • cyperghostC
                              cyperghost @jonnykesh
                              last edited by cyperghost

                              @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

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

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

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

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

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

                                        @mitu

                                        Okay, this is interesting, I opened SSH Window 1, killed vlc, and reopened it via the command you gave. Then, in SSH Window 2, I ran the pause command. It appeared to sit there with the music still playing just as before. However, I then did a CTRL+C in Window 2 and it paused. Then I used the pause command in Window 2 again. Once again, it just sat there silently. Then I did CTRL+C and sure enough it started playing music again. Also, here is the output that appeared in Window 1.

                                        status change: ( new input: http://listen.ai-radio.org:8000/128.ogg?cc=US&now=1507110308.444& )
                                        status change: ( play state: 3 )
                                        pause: returned 0 (no error)
                                        status change: ( pause state: 3 ): Pause
                                        status change: ( pause state: 4 )
                                        pause: returned 0 (no error)
                                        status change: ( play state: 2 ): Play
                                        status change: ( play state: 3 )
                                        pause: returned 0 (no error)
                                        status change: ( pause state: 3 ): Pause
                                        status change: ( play state: 3 )
                                        pause: returned 0 (no error)
                                        

                                        EDIT: I decided to just place the script that jonnykesh brought us inside my runcommand-onstart.sh and runcommand-onend.sh with the mpg123 replaced with vlc. That seems to work and perform the function of the pause command on the cases I have tried so far. Its probably not as efficient as the actual vlc controls, but I haven't noticed a delay from a human perspective. It is more efficient than just using the kill all command and then that command we added in autostart.sh and restarting vlc every time though, which was my backup plan and did introduce a delay. Would be nice to have access to the other vlc controls, but I can't think of anything else to try right now.

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

                                          @nowarrivinghere This means the netcat commands you run in the 2nd window reads the pause command but it doesn't send it right away and awaits further input.
                                          I'll do some testing with the version in Stretch to see if it behaves differently than the one in the Jessie release, but glad you got it working with the alternate start/stop command.

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

                                            Ok, found out the difference - tested on a Stretch system. The netcat command doesn't return and still waits for input from the tty. To force it to close the input, using -N seems to do the trick.
                                            @NowArrivingHere you can try changing the on-start/on-end commands to

                                            echo -n pause | nc -UN /tmp/radio.sock
                                            

                                            Unfortunately the -N option doesn't exist in the Jessie version of netcat-openbsd, I'll see if we can ditch netcat completely and use something else.

                                            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.