Adding Background Music to EmulationStation

Adding Background Music to EmulationStation

Learn how to assemble, install and customize retropie to build a home emulation console.

full course
  1. Overview and Prerequisites For Building a RetroPie
  2. Flashing Retropie
  3. RetroPie First Startup
  4. Installing ROMs
  5. Scraping ROM Metadata
  6. Adding Themes and Splashscreen
  7. Adding Background Music to EmulationStation
  8. Starting EmulationStation and Theme Setup

One of the features I saw used in some of the images I looked at was background music playing while browsing the library. I’ll show you how to get that setup.

I’ll be following the instructions here for the most part.

Setting up mpg123

SSH into your Pi and run this command to install the mpg123 package

pi@retropie:~ $ sudo apt-get install mpg123
Reading package lists... Done
Building dependency tree
...

Enable Music on Start

First, create a location to store the music files.

 $ mkdir RetroPie/roms/bgm

Edit the autostart script

$ sudo nano /opt/retropie/configs/all/autostart.sh

add this line above emulationstation #auto (following the docs here)

while pgrep omxplayer >/dev/null; do sleep 1; done
(sleep 5; mpg123 -f 5000 --random /home/pi/RetroPie/roms/bgm/*.mp3 >/dev/null 2>&1) &
emulationstation #auto

We’re telling the player to wait 5s to start up, then start the mpg player at 15% volume (5000/32768) and play at random all of the mp3 files in the RetroPie/roms/bgm folder (that we just created). Hit ctrl-o, enter, ctrl-x to save the file and exit

Pause the Music when Playing a Game

Edit the script that runs when a game starts to pause the music

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

Paste this into the editor

pkill -STOP mpg123

ctrl-o, enter, ctrl-x to save and exit

Edit the script that runs when a game ends to restart the music

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

paste this into the editor

pkill -CONT mpg123

ctrl-o, enter, ctrl-x to save and exit

now make the scripts runnable

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

Turn off the Music when on the Command Line

Edit your bash script

$ sudo nano /home/pi/.bashrc

Scroll to the end of the file, open up a line between retropie_welcome and # RETROPIE PROFILE END and make the file look like this:

retropie_welcome
[[ $(tty) == "/dev/tty1" ]] && pkill mpg123
# RETROPIE PROFILE END

ctrl-o, enter, ctrl-x to save and exit

Add Music

You can SCP or use a USB drive as we discussed earlier to copy files up. However, I’ve purposely put the music directory in the roms directory because if you connect via windows explorer the roms directory has already been mapped and this is probably the easiest way to copy music up.

Conclusion

Much appreciation to MapleStoryPSN. This is super easy to setup. Let me know if you have a better way to setup background music.

0 comments on “Adding Background Music to EmulationStationAdd yours →

Leave a Reply

Your email address will not be published. Required fields are marked *