Playing random Videos with omxplayer (PIR)

116 Views Asked by At

I am trying to do the following: I connected a PIR-Sensor to my raspberry pi to detect motion. If there is motion detected my pi should play random videos from the folder "videos" (about 20-30 videos in this folder). If there is no motion detected a static image should be shown.

With the following code I am able to start the specified video only (on motion detected).

import RPi.GPIO as GPIO
import time
import os

PIR=23                                            
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR,GPIO.IN)

while True:  
  if (GPIO.input(PIR)==True): 
    os.system("omxplayer -o hdmi videos/biene.mp4 -b > /dev/null") 
    while (GPIO.input(PIR) == True): time.sleep(.2);

Additionaly I would like to check every 30 seconds for motion, if there is motion detected keep playing the currently playing video and continue with random videos, if there is no motion detected stop playing videos and show the above mentioned specific image.

I am totally new to raspberry pi´s and python.

0

There are 0 best solutions below