k, that last method was not the best... because the script checks ever 2 seconds to enable game audio.. not really the best and probably only 90% reliable. So.. I believe I found the best solution for mpg123 script method.
Credit goes to:
https://retropie.org.uk/forum/topic/546 ... nce-mp3/23
#Step 1.
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)
Code: Select all
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:
Code: Select all
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.
Code: Select all
sudo nano /opt/retropie/configs/all/runcommand-onstart.sh
Once inside, type/paste the following:
This is where I modified the original post because when you added pkill -STOP mpg123, the game sound would never start but this should fix that.
Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.
Code: Select all
sudo nano /opt/retropie/configs/all/runcommand-onend.sh
Once inside, type/paste the following:
Also modified...from original posting.
Code: Select all
mpg123 -Z /home/pi/bgm/*.mp3 > /dev/null 2>&1 &
Hit CTRL+O followed by Enter to save the file and CTRL+X to quit nano back to terminal.
At the terminal, type/paste:
Code: Select all
sudo chmod a+x /opt/retropie/configs/all/runcommand-onstart.sh
Followed by:
Code: Select all
sudo chmod a+x /opt/retropie/configs/all/runcommand-onend.sh
#Step 4.
Edit .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:
Code: Select all
s[[ $(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
Move your MP3 music to the new bgm directory, And you're finished! Make sure you reboot.