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

Quick and easy guide for adding music to Emulatonstation on RetroPie. Noob friendly!

Scheduled Pinned Locked Moved General Discussion and Gaming
musicbgmsynackguide
165 Posts 59 Posters 112.8k 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.
  • M
    MapleStory
    last edited by MapleStory 24 Mar 2017, 21:44

    Posted this guide over on reddit and figured it would make sense to post it here as well.

    All credit goes to synack for putting together the easiest method for playing mp3's while in emulationstation. He left out a few steps in that specific post that I'm going to cover so that setting it up will be foolproof.

    I felt that synack's method was somewhat lost in the shuffle of that topic, as there are now nearly 200 posts and many are only aware of the python method posted by the topic creator. Having set this up on my Pi and for a couple friends, I figured I'd share it here as well and also to refresh my own memory should I need to set it up again in the future.

    Everything written in code should be done in terminal (or via putty) unless otherwise stated.

    Now on to the guide!

    Step 1.

    Install mpg123

    sudo apt-get install mpg123
    

    When prompted, type "y" and hit enter and it should install quickly.

    Step 2.

    Edit autostart.sh (note: this is not meant to be a link)

    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; mpg123 -Z /home/pi/bgm/*.mp3 >/dev/null 2>&1) &
    

    NOTE: You can delay how long it takes for mpg123 to begin playing music on boot, which is handy for those with splashscreens. Just replace the 10 in the second line(sleep 10; with any value in seconds you'd like. As shown, it's currently set to a 10 second delay.

    Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

    Step 3.

    Create and edit the runcommand-onstart and onend files.

    sudo nano /opt/retropie/configs/all/runcommand-onstart.sh
    

    Once inside, type/paste the following:

    pkill -STOP mpg123
    

    Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

    sudo nano /opt/retropie/configs/all/runcommand-onend.sh
    

    Once inside, type/paste the following:

    pkill -CONT mpg123
    

    Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

    At the terminal, type/paste:

    sudo chmod a+x /opt/retropie/configs/all/runcommand-onstart.sh  
    

    Followed by:

    sudo chmod a+x /opt/retropie/configs/all/runcommand-onend.sh
    

    Step 4.

    Edit .bashrc

    sudo 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" ]] && pkill mpg123
    

    Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.

    Step 5.

    Create the folder /home/pi/bgm

    mkdir /home/pi/bgm
    

    And you're finished! Now all that's left is to add your mp3s to the bgm folder you just created via your favorite ftp client or usb. Upon reboot after adding some songs, your music should play automatically and will pause when a game is launched and resuming when you return to emulationstation.

    I hope this helps some of you out and if there's any questions, please feel free to ask! Also, if there's any suggestions in how to tidy this guide up, please let me know as well.

    T M L C 4 Replies Last reply 25 Mar 2017, 00:11 Reply Quote 10
    • H
      herb_fargus administrators
      last edited by 25 Mar 2017, 00:02

      Now just need to compile this functionality into emulationstation ;) good guide

      If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

      Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

      1 Reply Last reply Reply Quote 0
      • T
        TMNTturtlguy @MapleStory
        last edited by 25 Mar 2017, 00:11

        @MapleStory This looks pretty cool. Question for you regarding the pkill command to start and stop the music. Is there a way to set the music to kill once you enter into a system detail page in emulationstation? I am running video preview with audio so it would be cool to have the music start after a splash screen video and play only on the main system selection screen. Once you enter a system the music would stop. Exit a system to main menu, the music would start. I am assuming this is probably to complicated until it is integrated into ES as @herb_fargus has indicated as you are using the launching and exiting of the roms as a command to start and stop the music.

        M W 2 Replies Last reply 25 Mar 2017, 17:21 Reply Quote 1
        • M
          MapleStory @TMNTturtlguy
          last edited by 25 Mar 2017, 17:21

          @TMNTturtlguy Unfortunately, I haven't set up video previews, so I have no way of testing out a method to get music to pause/mute when highlighting a game. I'd imagine that it is a bit more complicated, considering it would have to specifically run commands based on your actions in the emulationstation interface. Hopefully once it's integrated, someone will find a way to make that feature a reality.

          1 Reply Last reply Reply Quote 0
          • M
            meleu @MapleStory
            last edited by 25 Mar 2017, 20:57

            @MapleStory great guide!
            Since it's a noob friendly guide, I would like to suggest an improvement: the chmod part is unnecessary. ;-)
            The runcommand calls onstart|onend scripts in a way that they don't need permission to execute.

            • Useful topics
            • joystick-selection tool
            • rpie-art tool
            • achievements I made
            1 Reply Last reply Reply Quote 0
            • L
              Lodan-Zark
              last edited by 25 Mar 2017, 21:26

              Is it possible to use a different format alike midi or ogg?

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User
                last edited by 25 Mar 2017, 22:01

                I don't know about midi files, but ogg, I'm sure.
                For midi, there would need to be a base sound (like a piano or something) in order for it to work.

                L 1 Reply Last reply 26 Mar 2017, 20:02 Reply Quote 0
                • L
                  Lodan-Zark @A Former User
                  last edited by 26 Mar 2017, 20:02

                  @itsnitro I know some applications that plays midi files but i dont know how to make them run under the retropie
                  the applications are:
                  wildmidi (as used by gstreamer)
                  timidity
                  playmidi
                  fluidsynth

                  1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User
                    last edited by 26 Mar 2017, 20:08

                    Running those under retropie would need an emulator of some type.

                    1 Reply Last reply Reply Quote 0
                    • fnkngrvF
                      fnkngrv
                      last edited by 27 Mar 2017, 03:13

                      I have implemented the updates and one thing that I noticed is that I couldn't get my mp3 file to run if it had underscores it in so I removed them.

                      Also a second item of note is that if you execute the command to stop when exiting to the command line even though it does so cleanly when you enter back into EM it will not start again. I am assuming that there are other configurations required.

                      lastly I wonder if there is a way to set the volume level so that the mp3 track does not interfere with the game audio on video previews for games?

                      1 Reply Last reply Reply Quote 0
                      • D
                        darkSSide
                        last edited by 8 Jun 2017, 21:44

                        OK I did everything step by step and it works but.......once I shutdown or switch over to Attractmode and get back into ES no music. I get back into autostart.sh file and the command has disappeared! What could be happening? Any help is appreciated,thanx.

                        1 Reply Last reply Reply Quote 0
                        • J
                          jozzy1
                          last edited by 2 Jul 2017, 16:07

                          Great guide. Thanks!

                          1 Reply Last reply Reply Quote 0
                          • R
                            roci
                            last edited by 27 Jul 2017, 13:14

                            Great guide and works perfectly! I do have one small problem though, I installed Moonlight into Retropie and once I launch it the music just continues :/

                            does anyone know a fix for that?

                            ExarKunIvE B 2 Replies Last reply 27 Jul 2017, 14:19 Reply Quote 0
                            • ExarKunIvE
                              ExarKunIv @roci
                              last edited by 27 Jul 2017, 14:19

                              @roci

                              i dont use this method to have background music, but here is the start of this way here

                              got through and maybe someone asked a similar question

                              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
                              • B
                                backstander @roci
                                last edited by backstander 27 Jul 2017, 17:06

                                @roci

                                I installed Moonlight into Retropie and once I launch it the music just continues :/

                                I think this is because Moonlight is launched directly and not through the Runcommand like every other emulator in RetroPie. So basically runcommand-onstart.sh and runcommand-onend.sh are not called.

                                does anyone know a fix for that?

                                You might need to manually edit your Moonlight.sh script and add "pkill -STOP & -CONT mpg123" to it.
                                Something like this (I haven't tested it):

                                #!/bin/bash
                                pkill -STOP mpg123
                                moonlight stream -app Steam blah blah blah...
                                pkill -CONT mpg123
                                
                                1 Reply Last reply Reply Quote 0
                                • L
                                  Lumpeidi
                                  last edited by 16 Aug 2017, 09:16

                                  Hi,

                                  This works all fine! Thx!
                                  But i have a question.

                                  I have many songs in the rome file.
                                  Also i set a startsong for the first boot from ES.
                                  This all works great.
                                  Song play at start and than random music.

                                  But i wanna have a second "startsong" who plays if i leave the game /emulator.

                                  for example:

                                  RPI3 boot -> ES Starts -> Startsong "A" plays -> after song, random music starts -> Start game -> exit game -> Startsong "B" plays -> after song, random music starts

                                  can someone help me?

                                  System:

                                  • RPI3
                                  • Retropie 4.2.16
                                  1 Reply Last reply Reply Quote 0
                                  • L
                                    linkreincarnate
                                    last edited by linkreincarnate 10 Jun 2017, 21:29 6 Oct 2017, 20:28

                                    @MapleStory

                                    Could this be used to give audio control to google assistant? I have it working in desktop mode but during emulation station bootups it cannot grab the audio control because the audio device is busy (presumably being used by emulation station itself) I wouldn't even need it to check for emulators running to reduce the volume because I would want the google assistant to be able to output during gameplay

                                    1 Reply Last reply Reply Quote 0
                                    • HyruleslinkH
                                      Hyruleslink
                                      last edited by 12 Oct 2017, 02:55

                                      Thank you for posting this guide, I just implemented the music player on my build and it works great!

                                      1 Reply Last reply Reply Quote 0
                                      • C
                                        Cjax08
                                        last edited by 12 Oct 2017, 14:23

                                        I’m curious how this works in a set up with video snaps. Will the music pause or fade out when you are previewing a game video in the game select list? Or will it play over it and I should just wait until this is ironed out?

                                        fnkngrvF 1 Reply Last reply 21 Oct 2017, 20:44 Reply Quote 1
                                        • S
                                          SSimmers
                                          last edited by SSimmers 13 Oct 2017, 00:23

                                          I believe I might've missed something or typo'd somewhere. RPI3 starts up and song starts in the 10 seconds. Go into game and when I exit said game, mpg123 does not continue at all. How do you go about editing this sort of thing? Thanks! ^.^'

                                          Edit: I had checked and found that "[[ $(tty) == "/dev/tty1" ]] && pkill mpg123" was typo'd and missing a "K" in pkill. However that didn't resolve the issue.

                                          jonnykeshJ 1 Reply Last reply 13 Oct 2017, 00:42 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.

                                            This community forum collects and processes your personal information.
                                            consent.not_received