Background Music [Continued from Help/Support]
-
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
-
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 ;)
-
@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? -
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.