I have zero coding experience, but my son and I are trying to tackle a headless, Pi-based bluetooth soundboard to play his Little League team's walkup songs from the dugout. We've used pygame music and have gotten the gpio buttons to play the songs for a specific amount of time, and then fadeout. However, we also need a stop or "abort" button in case we need to interrupt and stop the music before its done playing. The problem is, I'm using time.sleep to set playtime, and I can't interrupt .sleep with a button wired to a .stop or .fadeout call. Time.wait doesn't seem to work either. I'm not sure if I need to learn threading, or asyncro, or something else, so looking for some help. Below is the code I've come up with for the stop button and a sample batter's button.
def Batter1():
if pygame.mixer.music.get_busy() == True:
pass
else:
pygame.mixer.music.load(BatterSong1)
pygame.mixer.music.play(0,6.2)
time.sleep(20)
pygame.mixer.music.fadeout(3000)
def StopSong():
pygame.mixer.music.fadeout(1000)
Appreciate any help!