Need a GPIO button to stop the currently playing mp3 file

2018-02-24 22:49:13

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, GPI