How to add music in the background when I open Emulation Station?

interpretive language scripts


Moderator: Forum moderators

Post Reply
redandwhitestripes
Posts: 32
Joined: Thu Dec 03, 2020 12:20 pm

How to add music in the background when I open Emulation Station?

Post by redandwhitestripes »

Hi everyone,

I'm after a particular script to run in both Puppy and Linux Mint.

Quick bit of explanation: Emulation Station is software that runs inside Retropie. It launches video game emulators from separate software called Retroarch.

What I am after is a service to play music from a particular directory in the background when I open Retropie and emulation station (ES) and move through my game lists, and fade out when I launch a game inside ES and Retroarch starts. When I close the game and return to the ES menu, thus closing Retroarch, I'd like the music to start again.

I'm guessing a console-based player would be the best choice. I also guess that the script will tell Linux to check when ES services are running to start the player, then kill the player when the Retroarch services start, then kill the music player when those services stop. How to draft that though, I have no idea! I can use MOCP or any other console player, but it needs to *not* open a window.

Any help appreciated.

Last edited by Flash on Sun Oct 31, 2021 3:11 am, edited 1 time in total.
Reason: Original title: Playing music in the background for Emuylation Station
User avatar
mikewalsh
Moderator
Posts: 6165
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 796 times
Been thanked: 1985 times

Re: How to add music in the background when I open Emulation Station?

Post by mikewalsh »

@redandwhitestripes :-

Mm. Okay; sounds 'do-able', I guess.

What are we talking about here? Steadily working its way through a playlist of tunes.....or a single piece of music, repeated over & over? How much time, on average, would you say you spend browsing your lists before choosing a game?

It's easy enough to get music to play in the background. Peebee's Pups have had a 'startup sound' for a long while - that plays after 'X' has started (an idea I pinched for my own Pups. I found a startup jingle I like, and I use the old XP one at shutdown). This uses mplayer from the command-line for actually playing, along with setting the volume to a specific level before it does so.

Code: Select all

#!/bin/sh
amixer -c 0 -- sset Master playback -36dB
mplayer /usr/share/audio/logon-1.mp3 &

(You get the 'dB' reading by running 'alsamixer' in the terminal, setting the volume to where you want it to be, then noting the dB readout in the mixer. You then use that as the value in the script.)

The point being that you need to have a trigger for your script. My startup one runs from /root/Startup, and the shutdown one is linked in to the 'wmpoweroff' script. So; as you say, can the script detect when startup routines are running for Retroarch? That's the bit we need to work out.....

Mike. ;)

redandwhitestripes
Posts: 32
Joined: Thu Dec 03, 2020 12:20 pm

Re: How to add music in the background when I open Emulation Station?

Post by redandwhitestripes »

Thanks Mike! What I'm after is for my music player to play a random track from a specified folder.

I would happily attach the script to a keyboard shortcut that I launch at the same time I launch Retropie. In my mind, the trigger for fade out would be when Retroarch process start.

If it helps, I saw this script on another page, it won't work in Puppy or Mint I fear, but some of it looks familiar.

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

Post Reply

Return to “Scripts”