I am using this python script to use 2 buttons to trigger 2 different mp3 files in a museum exhibit. As the files are 30 minutes long, I have also added a stop button to stop the playing mp3 so that the user doesn't have to listen to the end before listening to the other track. This is all working perfectly.
But I now need to disable the 2 trigger buttons for the duration of the audio tracks, otherwise the tracks can be played over the top of each other with multiple button pushes. (Kids.)
I tried to do this by increasing the sleep command which I assumed was in seconds, to be the same length as the audio file, but this didn't work. Is there another way?
I am also open to the idea of a 2 button system where each button press kills whatever mp3 is playing, then plays the selected mp3.
#!/usr/bin/env python import subprocess from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN) GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.IN) while True: if (GPIO.input(23) == False): subprocess.Popen(['mpg123', 'audio1.mp3']) sleep(1) if (GPIO.input(24) == False): subprocess.Popen(['mpg123', 'audio2.mp3']) sleep(1) if (GPIO.input(25) == False): subprocess.call(['killall', 'mpg123']) sleep(0.5);