I'm pretty new with Python and Raspberry Pi so please excuse if the issue is naive. I'm writing a program where the it plays a video when triggered by a PIR sensor. The trigger sensed is visible but the video plays when I terminate/stop the program in Thonny.
import os
import sys
from subprocess import Popen
import RPi.GPIO as GPIO
import time
movie1 = ("/home/pi/Desktop/2.mp4")
movie2 = ("/home/pi/Desktop/1.mp4")
pir_sensor = 11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pir_sensor, GPIO.IN)
current_state = 0
try:
while True:
time.sleep(0.1)
current_state = GPIO.input(pir_sensor)
if current_state == 1:
#print("GPIO pin %s is %s" % (pir_sensor, current_state))
os.system('killall omxplayer.bin')
omxc = Popen(['omxplayer', '-b', movie1])
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
The video should play immediately when triggered.