Toogle Music Player
-
Here is a nice sniplet to toogle between STOP and CONT state of any process.
So you can easily disable bakground music via RetroPie Menu.#!/bin/bash #Toggle to silent or restart any Music Player or Video Player command="mpg123" pids="$( pgrep "$command" )" if [[ -z "$pids" ]]; then "$command" -Z /media/usb0/BGM/*.mp3 >/dev/null 2>&1 & exit 0 fi #if [[ -z "$pids" ]]; then # printf '"%s" is not running\n' "$command" >&2 # exit 1 #fi for pid in $pids; do state="$( ps -ostate= -p "$pid" )" stopped=0 case "$state" in *T*) stopped=1 ;; esac if (( stopped )); then kill -s CONT "$pid" # printf '"%s" (%d) has been unpaused\n' "$command" "$pid" else kill -s STOP "$pid" # printf '"%s" (%d) has been paused\n' "$command" "$pid" fi done
I use # to hide Textmessages.
Orignal source is here: Thanks to user Kusalananda -
Small update:
if mpg123 is not running (no valid PID found!) it can also started by script. Please use pathes and parameters and music player as you like.
So we can start processes and STOP/CONT them!if [[ -z "$pids" ]]; then "$command" -Z /media/usb0/BGM/*.mp3 >/dev/null 2>&1 & exit 0 fi
BTW: My Background music are 350MB ambient from X-COM series...
Kids! Don't play this at night when you're alone!
X-COM2 is a masterpiece in sound technics but the old ones from 1994 and 1995 are frightning cool :)
-
@cyperghost
Nice work!
Where are you putting these scripts? I'm having trouble getting my head around this lol! -
@backstander I put them to
~/RetroPie/retropiemenu/
The RetroPie Menu is able to showrp
andsh
files. But you can but them in any place you like and you have easy access to. -
I can't get this working I just shows this error then boots back into emulationstation
https://i.imgur.com/sRDwDgO.jpg
I must have a bad / outdated togglebgm.sh but I used what you posted?
-
@steve51184 You are using Windows file format with CR LF ending
Convert to Unix format -
Looks fine to me or is it still wrong:
https://i.imgur.com/JK7zhp8.jpg
Could you upload the file or post the code to pastebin if it's wrong
Edit: do you mean the file extension if so it's .sh
-
@steve51184 please use Google for your issue. Mac Windows and Linux use different "invisible" control characters to enter new lines in texts. Use Notepad++ for ex and you see the difference.
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.