I'm playing with my Raspberry Pi GPIO. I connect 4 switch to GPIO.
I want to realize the function is
While hold switch 1. Stop the current movie, Play M01.mp4.
While hold switch 2. Stop the current movie, Play M02.mp4.
...
If no switch was holded, player M00.mp4 in loop.
I just learn python for 3days. I'm very appreciate that you can help me with detail code.
Popen.Terminate() or Kill() can kill scratch, why can not kill omxplayer?
#!/usr/bin/env python2.7
import subprocess,time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(22, GPIO.IN)
while True:
if GPIO.input(25) == True:
time.sleep(1)
playProcess=subprocess.Popen(['scratch'],stdout=True)
#Terminate() or Kill() can kill scratch.
playProcess=subprocess.Popen(['omxplayer','/home/pi/pyStudy/DSCF4021.MP4'],stdout=True)
#Terminate() or Kill() CAN NOT kill scratch.
time.sleep(5)
playProcess.terminate()