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

    Background Music [Continued from Help/Support]

    Scheduled Pinned Locked Moved General Discussion and Gaming
    musicbgm
    343 Posts 109 Posters 326.9k 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.
    • C
      Chad921s
      last edited by Chad921s

      In the python script, why not just make the player adjust the volume down when it sees omxplayer running (while playing video snaps for example) instead of making it stop or pause the music and then resume every time?

      Just have a couple basic configs like "normal volume" and "omx volume" so that people can tweak the settings to their preference. It seems like it would be much more simple, coding-wise, to just have the script look for any instance of omxplayer running and then adjust the music volume to whatever setting is specified. This could be instantaneous and not have to involve the fadeout parameter. Seems like it would run cleaner. I know that for my retropie build, the music player stopping and resuming all the time messes with my system previews (I lose video snaps in the systems and have to restart ES or go into and back out of an emulator to reset everything). EDIT: I was wrong, the stopping and starting wasn't the problem. I removed omx player from the list of emulator names so that it runs continuously even over the video snaps and I'm still having the same problem. Even so, it still seems like a cleaner way to set the player up.

      Any skilled coders think they could reconfigure the python script in this way? Leave the emulator part the way it is, but change the omx player stuff to simply "when omx player is running, change the volume to 'x'"?

      madmodder123M 1 Reply Last reply Reply Quote 0
      • F
        fdotg
        last edited by fdotg

        Does anyone know how to make the music stop when the screen saver starts? I have my screen saver set to black.

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

          @fdotg No... this isn't possible. For VideoScreensaver it is possible with some scripts but not intended to be a good usecase.

          1 Reply Last reply Reply Quote 0
          • madmodder123M
            madmodder123 @Chad921s
            last edited by

            @chad921s I might give it a shot when I have time.

            I made a script that installs a modified version of this script which include overlays here!

            1 Reply Last reply Reply Quote 0
            • T
              tmak @anasazi29
              last edited by

              @anasazi29 Hi, I am having the same issue, all my emulators work for muting the music, except for PPSSPP. I have checked the music.py script and i see "ppsspp" listed but for some reason its not working. from your comment it sounds like you updated the emulator name in the script to "PPSSPPSDL" and that worked. Can you confirm. Also not being an expert on programming, is the script file case sensitive?
              Thanks,

              1 Reply Last reply Reply Quote 0
              • M
                michel30
                last edited by

                Hello,

                I run background music on my retropie raspberry pi 3 and when I start an emulation the music stop.

                I am using the py file music.py and the only emulator that does not stop the music is TI-99/4A I add in the music.py " ti99sim-sdl " but it does not stop when I start this emu.

                Hopefully somebody could help me why this is.

                Thanks,

                A 1 Reply Last reply Reply Quote 0
                • Z
                  zerel
                  last edited by

                  I'm trying to install this on EmulationStation on Windows, can someone help me or it's only for Linux?

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

                    @zerel It's only for Linux.

                    1 Reply Last reply Reply Quote 0
                    • J
                      joelkolb
                      last edited by

                      I am running a freshly installed and fully up to date image of RetroPie and when I set up this script the music will not stop when I start a game. I'm using RetroArch for everything and line 25 of my script looks as it should with retroarch listed as the first item in emulatornames. I started over from a clean install once already just to make sure I didn't mess anything up. My gut is telling me it's something in a recent update to RetroPie that's causing this. Can anyone help?

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

                        @joelkolb I prefer the mpg123 method. The python script uses an internal array to check running instances of an emulator and then stops music. The method above makes use of runcommand-onstart.sh and runcommand-onstop.sh which is more hands on.
                        If you want fade in and fade out effect on the mpg123 you can use this scripts here.

                        If you are eager in python coding you can release annother version that will get rid of this "libary" and uses also the runcommand options. That would be a more straight way. It's not a direct answer on your question I know.

                        J 1 Reply Last reply Reply Quote 0
                        • J
                          joelkolb @cyperghost
                          last edited by

                          @cyperghost I had used the mpg123 method previously but I never liked the way the music would stop abruptly when you launched a game so the fade in/out for with Livewire's method was nice. I'm happy to see that you came up with a method to do the fade in/out with mpg123. I will try this right away. Thank you!

                          ExarKunIvE 1 Reply Last reply Reply Quote 0
                          • ExarKunIvE
                            ExarKunIv @joelkolb
                            last edited by

                            @joelkolb i would recommend the script here

                            it uses mpg123 and it has fade in and out

                            RPi3B+ / 200GB/ RetroPie v4.5.14, RPi4 Model B 4gb / 256gb / RetroPie 4.8.2
                            RPi5 4gb / 512gb / RetroPie 4.8.9 -Basic
                            Maintainer of RetroPie-Extra .

                            J cyperghostC 2 Replies Last reply Reply Quote 0
                            • J
                              joelkolb @ExarKunIv
                              last edited by

                              @ExarKunIv Wow, nice and simple with RetroPie menu controls. This is great. I will give it a try. Thanks!

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

                                @ExarKunIv Oh yes forget about this. It uses mpg123 for mp3 and the fade feature was taken out from my script with much faster jumps in altering volume level so the fade is a bit messed (imho)

                                ExarKunIvE 1 Reply Last reply Reply Quote 0
                                • ExarKunIvE
                                  ExarKunIv @cyperghost
                                  last edited by

                                  @cyperghost i never really hear it but i dont have the BGM up that much. so for me its all good :)

                                  RPi3B+ / 200GB/ RetroPie v4.5.14, RPi4 Model B 4gb / 256gb / RetroPie 4.8.2
                                  RPi5 4gb / 512gb / RetroPie 4.8.9 -Basic
                                  Maintainer of RetroPie-Extra .

                                  1 Reply Last reply Reply Quote 0
                                  • S
                                    stefano.sudati
                                    last edited by

                                    how do i uninstall it?

                                    mituM 1 Reply Last reply Reply Quote 0
                                    • mituM
                                      mitu Global Moderator @stefano.sudati
                                      last edited by

                                      @stefano-sudati Remove the line that starts it from autostart.sh.

                                      1 Reply Last reply Reply Quote 0
                                      • J
                                        joethefox
                                        last edited by

                                        Hello,

                                        it's working great here, thank you. I have some little modifications to enable fade in/fade out and also added the capability to not turn off the background music while playing but just lowering the volume. It works great with arcade ambience :)

                                        The trick to make a smooth fade effect was to launch mpg123 with zero volume, in remote control mode and with the fifo feature.

                                        There are four scripts involved and one ini file to be created in any path you want. In the scripts we will use the /path/to/ path.
                                        The files are:
                                        emulationstation_music.ini
                                        is the file where we store the desired fade in while not playing games (volume_idle) and the final volume when the fade out occurs during playing the games (volume_game)

                                        volume_idle=40
                                        volume_game=10  # Put 0 to disable background music while playing
                                        

                                        mpg123_load.sh

                                        #!/bin/bash
                                        source <(grep = /path/to/emulationstation_music.ini)
                                        echo "LOAD /path/to/music/arcade.mp3" > /tmp/mpg123fif
                                        sleep 1
                                        for ((i=0;i<=$volume_idle;i++))
                                        do
                                          echo "v $i" > /tmp/mpg123fif
                                          sleep 0.1
                                        done
                                        
                                        

                                        mpg123_fadein.sh

                                        #!/bin/bash
                                        source <(grep = /path/to/emulationstation_music.ini)
                                        if [ $volume_game -eq 0 ]
                                        then
                                          echo "LOAD /path/to/music/arcade.mp3" > /tmp/mpg123fif
                                          sleep 1 
                                        fi
                                        for ((i=$volume_game;i<=$volume_idle;i++))
                                        do
                                          echo "v $i" > /tmp/mpg123fif
                                          sleep 0.1
                                        done
                                        

                                        mpg123_fadeout.sh

                                        #!/bin/bash
                                        source <(grep = /path/to/emulationstation_music.ini)
                                        for ((i=$volume_idle;i>=$volume_game;i--))
                                        do
                                          echo "v $i" > /tmp/mpg123fif
                                          sleep 0.1
                                        done
                                        if [ $volume_game -eq 0 ]
                                        then
                                          echo "stop" > /tmp/mpg123fif
                                        fi
                                        
                                        

                                        mpg123_quit.sh

                                        #!/bin/bash
                                        source <(grep = /path/to/emulationstation_music.ini)
                                        for ((i=$volume_idle;i>=0;i--))
                                        do
                                          echo "v $i" > /tmp/mpg123fif
                                          sleep 0.1
                                        done
                                        echo "stop" > /tmp/mpg123fif
                                        echo "quit" > /tmp/mpg123fif
                                        

                                        Then I have modified the entry to start mpg123 in autostart.sh with:

                                        /usr/bin/mpg123 -f 0 --remote --fifo /tmp/mpg123fif >/dev/null 2>&1 &
                                        sleep 1
                                        /path/to/mpg123_load.sh &
                                        

                                        the file runcommand-onstart.sh in:

                                        /path/to/mpg123_fadeout.sh &
                                        

                                        the file runcommand-onend.sh in:

                                        /home/gio/scripts/mpg123_fadein.sh &
                                        

                                        and the exit command:

                                        /path/to/mpg123_quit.sh
                                        

                                        Now the bad news ;)

                                        • At the moment I haven't figured out how to load music in loop mode with mpg123 when in remote control mode
                                        • I'm using a single mp3 file (about two hours of duration), modifying the scripts to load a playlist shouldn't be an issue.

                                        Of course there is room for improvements. I hope this is useful for you

                                        Joe

                                        1 Reply Last reply Reply Quote 0
                                        • DomiswanD
                                          Domiswan
                                          last edited by

                                          Hi. A small suggestion about Synack method: as someone mentionned, if you have a splash video it delays the startup of emulationstation, because emulationstation waits for the commands in autostart to execute instead of loading.

                                          A simple way to fix that is to launch the whole set of instructions in the backgroung (instead of mpg123 only). The only thing to do is to add parentheses:

                                          (while pgrep omxplayer >/dev/null; do sleep 1; done
                                          mpg123 -Z /home/pi/bgm/*.mp3 >/dev/null 2>&1)  &  
                                          

                                          No more delay ;)

                                          1 Reply Last reply Reply Quote 0
                                          • A
                                            AHLONNAE @michel30
                                            last edited by

                                            @michel30
                                            hello, I'm a noobie.
                                            But I have a question:
                                            Are you saying you have a code that will constantly play a mp3 file and play in the background and will continue to play while you do other things in the background
                                            using pygame?

                                            I got mine to play when i boot up the raspberry pi but, as soon as I do something like start my MAIN.py the mp3 stops playing: and I need it to KEEP PLAYING?
                                            Can you help?
                                            Thank you?

                                            1 Reply Last reply Reply Quote 0
                                            • I illando referenced this topic on
                                            • 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.