RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Toogle Music Player

    Scheduled Pinned Locked Moved Help and Support
    backgroundmusicomxplayer
    8 Posts 3 Posters 2.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.
    • cyperghostC
      cyperghost
      last edited by cyperghost

      Here is a nice sniplet to toogle between STOP and CONT state of any process.
      So you can easily disable bakground music via RetroPie Menu.

      #!/bin/bash 
      #Toggle to silent or restart any Music Player or Video Player
      
      command="mpg123"
      
      pids="$( pgrep "$command" )"
      
      if [[ -z "$pids" ]]; then
          "$command" -Z /media/usb0/BGM/*.mp3 >/dev/null 2>&1 &
          exit 0
      fi
      
      #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 use # to hide Textmessages.
      Orignal source is here: Thanks to user Kusalananda

      B 1 Reply Last reply Reply Quote 2
      • cyperghostC
        cyperghost
        last edited by cyperghost

        Small update:
        if mpg123 is not running (no valid PID found!) it can also started by script. Please use pathes and parameters and music player as you like.
        So we can start processes and STOP/CONT them!

        if [[ -z "$pids" ]]; then
            "$command" -Z /media/usb0/BGM/*.mp3 >/dev/null 2>&1 &
            exit 0
        fi
        

        BTW: My Background music are 350MB ambient from X-COM series...
        0_1498150776287_Clipboard01.jpg

        Kids! Don't play this at night when you're alone!

        X-COM2 is a masterpiece in sound technics but the old ones from 1994 and 1995 are frightning cool :)

        1 Reply Last reply Reply Quote 1
        • B
          backstander @cyperghost
          last edited by

          @cyperghost
          Nice work!
          Where are you putting these scripts? I'm having trouble getting my head around this lol!

          1 Reply Last reply Reply Quote 1
          • cyperghostC
            cyperghost
            last edited by

            @backstander I put them to ~/RetroPie/retropiemenu/
            The RetroPie Menu is able to show rp and sh files. But you can but them in any place you like and you have easy access to.

            1 Reply Last reply Reply Quote 1
            • S
              steve51184
              last edited by

              I can't get this working I just shows this error then boots back into emulationstation

              https://i.imgur.com/sRDwDgO.jpg

              I must have a bad / outdated togglebgm.sh but I used what you posted?

              cyperghostC 1 Reply Last reply Reply Quote 0
              • cyperghostC
                cyperghost @steve51184
                last edited by

                @steve51184 You are using Windows file format with CR LF ending
                Convert to Unix format

                S 1 Reply Last reply Reply Quote 0
                • S
                  steve51184 @cyperghost
                  last edited by steve51184

                  @cyperghost

                  Looks fine to me or is it still wrong:

                  https://i.imgur.com/JK7zhp8.jpg

                  Could you upload the file or post the code to pastebin if it's wrong

                  Edit: do you mean the file extension if so it's .sh

                  cyperghostC 1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost @steve51184
                    last edited by

                    @steve51184 please use Google for your issue. Mac Windows and Linux use different "invisible" control characters to enter new lines in texts. Use Notepad++ for ex and you see the difference.

                    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.