• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
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 324.3k 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
    retrobean
    last edited by 7 Dec 2016, 11:55

    I think i may have figured out why some mp3 files will play at slower speed.

    When the PyGame mixer is intialized using the default settings

    pygame.mixer.init()
    initialize the mixer module
    init(frequency=22050, size=-16, channels=2, buffer=4096) -> None

    So i suppose the mp3 files HAVE to be this format to play correctly, now i downloaded most of the music I am using and some files play at the correct speed and some play slower, so what I will do tonight is look at the information of the files and check to make sure they are the same.

    Once i have checked this I will update.

    Would anyone be able to conifrm or deny if this could make a difference?

    Thanks

    F S 2 Replies Last reply 7 Dec 2016, 16:12 Reply Quote 0
    • F
      felleg @retrobean
      last edited by 7 Dec 2016, 16:12

      @retrobean Nice find! I'm excited to see the results :)

      R 1 Reply Last reply 7 Dec 2016, 16:29 Reply Quote 0
      • R
        retrobean @felleg
        last edited by 7 Dec 2016, 16:29

        @felleg I shall report back when i've had a chance to look into it :D

        1 Reply Last reply Reply Quote 0
        • S
          synack @retrobean
          last edited by synack 12 Sept 2016, 01:24 7 Dec 2016, 16:50

          @retrobean Not to derail the thread or take away from @Livewire's contribution here, but you can also just use an external mp3 player such as mpg123 to play music without worrying about details.

          1. install mpg123
          sudo apt-get install mpg123
          
          1. edit /opt/retropie/configs/all/autostart.sh and before emulationstation is called;
          while pgrep omxplayer >/dev/null; do sleep 1; done
          mpg123 -Z /home/pi/bgm/*.mp3 >/dev/null 2>&1 &
          1. edit /opt/retropie/configs/all/runcommand-onstart.sh
          pkill -STOP mpg123
          
          1. edit /opt/retropie/configs/all/runcommand-onend.sh
          pkill -CONT mpg123
          
          1. edit /home/pi/.bashrc and add
          [[ $(tty) == "/dev/tty1" ]] && pkill mpg123
          

          This will randomly play mp3s from the specified folder (step 2), pause the player upon entering a game, resume when exiting, and also stop the player when exiting emulationstation and dropping to a bash shell.

          R R Z K H 13 Replies Last reply 7 Dec 2016, 17:27 Reply Quote 11
          • R
            retrobean @synack
            last edited by 7 Dec 2016, 17:27

            @synack nice! this looks like its worth doing.

            Thanks.

            1 Reply Last reply Reply Quote 0
            • R
              retrobean @synack
              last edited by 7 Dec 2016, 19:52

              @synack

              just added the code in now! fantastic works well first time.

              Thanks for that.

              Emulatiosstation with bgm is go go go!!

              1 Reply Last reply Reply Quote 0
              • J
                josete2k
                last edited by 7 Dec 2016, 20:52

                Does mpg123 also work with ogg files?

                S 1 Reply Last reply 7 Dec 2016, 20:56 Reply Quote 0
                • S
                  synack @josete2k
                  last edited by 7 Dec 2016, 20:56

                  @josete2k no, but ogg123 does. It's available in the vorbis-tools package.

                  sudo apt-get install vorbis-tools
                  
                  J 1 Reply Last reply 8 Dec 2016, 11:56 Reply Quote 0
                  • J
                    j.e.f.f
                    last edited by 8 Dec 2016, 02:49

                    Script is working for me -- Thanks for this!

                    I'm having one small issue where the music isn't fading out out properly when I start a game. I just cuts right out. If I set the fade delay to something really slow, the music comes back in partially faded after a couple of seconds and completes the fade out. So fade out is working but it is momentarily muted during the fade. Any ideas? If it helps, I'm using an MP3. I know you said there might be issues with MP3's... is this what you meant? Other than the fade problem, playback is fine.

                    Thanks!

                    • Jeff
                    R 1 Reply Last reply 8 Dec 2016, 10:40 Reply Quote 0
                    • R
                      retrobean @j.e.f.f
                      last edited by 8 Dec 2016, 10:40

                      @j.e.f.f Try the new code that synack has put up on the forum, it works like a charm and stops when it needs to and starts when it needs to.

                      Fantastic stuff, also fixes the issue with any slowdown in the mp3 tracks that pygame has.

                      1 Reply Last reply Reply Quote 0
                      • J
                        josete2k @synack
                        last edited by 8 Dec 2016, 11:56

                        @synack thanks I've tested ogg123 and it works fine.

                        But as the previous pyton script from Livewire, the music starts before my opening splash video ends...

                        S 1 Reply Last reply 8 Dec 2016, 12:05 Reply Quote 0
                        • S
                          synack @josete2k
                          last edited by 8 Dec 2016, 12:05

                          @josete2k
                          In that case, edit /opt/retropie/configs/all/autostart.sh, before the ogg123 command, add the following:

                          while pgrep omxplayer >/dev/null; do sleep 1; done
                          
                          F 1 Reply Last reply 9 Dec 2016, 01:19 Reply Quote 0
                          • F
                            felleg @synack
                            last edited by felleg 12 Sept 2016, 01:21 9 Dec 2016, 01:19

                            @synack said in Background Music [Continued from Help/Support]:

                            @josete2k
                            In that case, edit /opt/retropie/configs/all/autostart.sh, before the ogg123 command, add the following:

                            while pgrep omxplayer >/dev/null; do sleep 1; done
                            

                            @synack

                            Thanks for the quick fix, synack!
                            I think you should edit your how-to post and include this step in it, I had the same issue as josete2k right off the bat with splash videos.

                            Alsom, quick verification. Can ogg123 play mp3 ffiles as well? Because if I have to call both mpg123 and ogg123, I'm scared of what will happen!

                            S 1 Reply Last reply 9 Dec 2016, 01:37 Reply Quote 0
                            • S
                              synack @felleg
                              last edited by 9 Dec 2016, 01:37

                              @felleg No problem, and good suggestion -- I updated the post.

                              Unfortunately ogg123 will not play mp3. The simple fix would be to convert your .ogg files to .mp3, or vice versa.

                              To mass convert .ogg files to .mp3 on your pi, you can do so by installing libav-tools

                              sudo apt-get install libav-tools
                              

                              then navigate to your folder with the .ogg files execute the following

                              for f in *.ogg; do avconv -i "$f" "${f%.*}.mp3"; done
                              
                              F 1 Reply Last reply 9 Dec 2016, 01:53 Reply Quote 0
                              • F
                                felleg @synack
                                last edited by 9 Dec 2016, 01:53

                                @synack Sweet, thanks for the reply! Everything seems to be working smooth. Is it possible that your method doesn't "protect" against playing the same song twice? Maybe it's a mistake on my end, but somehow the same song played twice just now, and I have no duplicate in my playlist.

                                One last question: can you think of an easy way to output the name of the songs played to a text file (so that I can look via ssh what is currently playing and keep track of what has been played)? I had modified the Python script in such a way that, every time the program started, it appended "====== [date & time] ======" and the song names (as they came) at the end of a file called songs_played.txt. However, since your solution uses many script files, I don't really know where I could put this.

                                S 1 Reply Last reply 9 Dec 2016, 02:07 Reply Quote 0
                                • S
                                  synack @felleg
                                  last edited by 9 Dec 2016, 02:07

                                  @felleg the randomization algorithm is within mpg123, and in my tests it worked as expected. You might have just gotten lucky :-)

                                  If you'd like to see what is / has been playing, you can change the mpg123 command to the following

                                  mpg123 -Z /home/pi/bgm/*.mp3 2>/dev/shm/playlist &
                                  

                                  then cat /dev/shm/playlist to see what's been played (the last entry will be what's currently playing).

                                  Of course, you can change the output file to whatever you'd like.

                                  F 1 Reply Last reply 9 Dec 2016, 02:24 Reply Quote 2
                                  • F
                                    felleg @synack
                                    last edited by 9 Dec 2016, 02:24

                                    @synack Awesome!

                                    ... And finally, one last last question, for real. I notice the only things your version are missing compared to Livewire's original method is the fadeout when starting a game, and the option to start a new song after quitting a game (instead of starting the song from where we left off). Can this be quickly implemented as well?

                                    Thanks for your great help!

                                    S 1 Reply Last reply 9 Dec 2016, 02:46 Reply Quote 0
                                    • S
                                      synack @felleg
                                      last edited by 9 Dec 2016, 02:46

                                      @felleg fade out is not possible with my method, as far as I know.

                                      To start a new set of tracks (upon game exit) instead of continuing from the last, you'd replace the original instructions do the following

                                      edit /opt/retropie/configs/all/runcommand-onstart.sh

                                      pkill mpg123
                                      

                                      edit /opt/retropie/configs/all/runcommand-onend.sh

                                      mpg123 -Z /home/pi/bgm/*.mp3 >/dev/null 2>&1 &
                                      

                                      or if you wanted to keep logging the played tracks, you'd use this line instead in the runcommand-onend.sh script

                                      mpg123 -Z /home/pi/bgm/*.mp3 2>>/dev/shm/playlist &
                                      
                                      E 1 Reply Last reply 24 Aug 2017, 14:38 Reply Quote 1
                                      • D
                                        dynaram
                                        last edited by 9 Dec 2016, 16:09

                                        Sorry but i have never wrote a script or know python or anything like that - this will be my first attempt to do it. but I was wondering about the muting of the sound while in emulation station.

                                        from what i read this.
                                        #Check to see if the DisableMusic file exists; if it does, stop doing everything!
                                        if os.path.exists('/home/pi/PyScripts/DisableMusic'):

                                        if i create this folder or file the music will stop.

                                        It sounds to me i have to ssh into the box to do this. (while in emulation station

                                        is there a way to say another script to be written that when pressing a specif keyboard key or joystick key to write the file to that location?

                                        and if another keyboard key or joystick key or maybe the same key, to remove the file?

                                        if using the same key: when key is press it checks - if file is there remove it. if not there added.

                                        Thank you

                                        1 Reply Last reply Reply Quote 0
                                        • D
                                          dynaram
                                          last edited by 9 Dec 2016, 18:56

                                          One simple and stupid suggestion.

                                          Can you please add the version # to the top of the script.

                                          Thank you

                                          1 Reply Last reply Reply Quote 0
                                          49 out of 343
                                          • First post
                                            59/343
                                            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