Created
August 14, 2019 05:47
-
-
Save umar14/1e578f909b308e2ff9c7cbcdb1b5d2f6 to your computer and use it in GitHub Desktop.
RPi script to loop videos in omxplayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# set here the path to the directory containing your videos | |
VIDEO_PATH1="/home/pi/PyLoopVideo/FINAL/MainVideo.mp4" | |
VIDEO_PATH2="/home/pi/PyLoopVideo/FINAL/Video1.mp4" | |
VIDEO_PATH3="/home/pi/PyLoopVideo/FINAL/Video2.mp4" | |
FILE_Button1="/home/pi/PyLoopVideo/FINAL/button1.txt" | |
FILE_Button2="/home/pi/PyLoopVideo/FINAL/button2.txt" | |
VIDEO_1_RUNNING=0 | |
VIDEO_2_RUNNING=0 | |
VIDEO_3_RUNNING=0 | |
echo `date` : Running Script!!! >> log.txt | |
gpio -1 mode 11 input | |
gpio -1 mode 11 up | |
gpio -1 mode 13 input | |
gpio -1 mode 13 up | |
pkill -9 -x omxplayer.bin | |
while true | |
do | |
if ! pgrep -x "omxplayer" > /dev/null | |
then | |
echo "Running Video-1..." | |
echo `date` : Running Video-1... >> log.txt | |
VIDEO_1_RUNNING=1 | |
omxplayer --no-osd --loop $VIDEO_PATH1 > /dev/null 2>&1 & | |
VIDEO_1_PID=`echo $!` | |
echo STOP > $FILE_Button1 | |
echo STOP > $FILE_Button2 | |
fi | |
val1=`gpio -1 read 11` | |
val2=`gpio -1 read 13` | |
if [ $val1 -eq 0 ] | |
then | |
sleep 0.5 | |
x=$(cat $FILE_Button1) | |
if [ $x = "START" ] | |
then | |
echo STOP > $FILE_Button1 | |
else | |
echo START > $FILE_Button1 | |
echo STOP > $FILE_Button2 | |
fi | |
fi | |
if [ $val2 -eq 0 ] | |
then | |
sleep 0.5 | |
y=$(cat $FILE_Button2) | |
if [ $y = "START" ] | |
then | |
echo STOP > $FILE_Button2 | |
else | |
echo START > $FILE_Button2 | |
echo STOP > $FILE_Button1 | |
fi | |
fi | |
button1=$(cat $FILE_Button1) | |
button2=$(cat $FILE_Button2) | |
if [ $button1 = "START" ] && [ $VIDEO_2_RUNNING -eq 0 ] | |
then | |
echo "Running Video-2..." | |
echo `date` : Running Video-2... >> log.txt | |
VIDEO_1_RUNNING=0 | |
VIDEO_2_RUNNING=1 | |
VIDEO_3_RUNNING=0 | |
pkill -9 -x omxplayer.bin | |
sleep 0.5 | |
omxplayer $VIDEO_PATH2 > /dev/null 2>&1 & | |
fi | |
if [ $button1 = "STOP" ] && [ $VIDEO_1_RUNNING -eq 0 ] && [ $VIDEO_3_RUNNING -eq 0 ] | |
then | |
VIDEO_2_RUNNING=0 | |
pkill -9 -x omxplayer.bin | |
fi | |
if [ $button2 = "START" ] && [ $VIDEO_3_RUNNING -eq 0 ] | |
then | |
echo "Running Video-3..." | |
echo `date` : Running Video-3... >> log.txt | |
VIDEO_1_RUNNING=0 | |
VIDEO_2_RUNNING=0 | |
VIDEO_3_RUNNING=1 | |
pkill -9 -x omxplayer.bin | |
sleep 0.5 | |
omxplayer $VIDEO_PATH3 > /dev/null 2>&1 & | |
fi | |
if [ $button2 = "STOP" ] && [ $VIDEO_1_RUNNING -eq 0 ] && [ $VIDEO_2_RUNNING -eq 0 ] | |
then | |
VIDEO_3_RUNNING=0 | |
pkill -9 -x omxplayer.bin | |
fi | |
done | |
pkill -9 -x omxplayer.bin | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment