I am using a RPi3 in a museum to connect to 2 buttons via GPIO. Each button plays an mp3 file. I used the Adafruit guide here: https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/overview
and everything works as advertised. However, the files are around 30 minutes long, and if the person starts playing one track, gets a few minutes then realizes they want to play the other track, they can't. The first file has to play to the end, and only then can the second button be pushed. So what I want to do if possible is to add a 'stop' button, a third button which, when pressed stops whichever track is playing, and allows the other track to be chosen. Or better still, when either of the 2 buttons is pushed to select a track, it stops whatever track is already playing. Below is the python script I'm using.
#!/usr/bin/env python import os from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN) GPIO.setup(24, GPIO.IN) while True: if (GPIO.input(23) == False): os.system('mpg123 -q audio1.mp3 &') if (GPIO.input(24) == False): os.system('mpg123 -q audio2.mp3 &') sleep(0.5);
Any guidance is much appreciated, thanks.