-
Notifications
You must be signed in to change notification settings - Fork 7
/
MultiMonitorVideoLooper_v1.py
91 lines (77 loc) · 3.44 KB
/
MultiMonitorVideoLooper_v1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#Copyright Jesse Stevens @ Cake Industries 12/9/19
#icing@cake.net.au www.cake.net.au
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#######################################################################################
# DUAL MONITOR 2 x VIDEO PLAYER:
# -No triggers, just plays back 2 separate videos on 2 separate monitors with loops
#######################################################################################
import sys
import os
import subprocess
import psutil
import time
import threading
###############################################################
# file locations for media
###############################################################
movie1 = ("/home/pi/video/video1.mp4")
movie2 = ("/home/pi/video/video2.mp4")
##################################################################
#variables for making sure we only trigger each video player once:
##################################################################
needtostart1 = 1
needtostart2 = 1
mode = 0
################################################################################
#Redirecting console output to null so we don't litter the window with feedback
################################################################################
FNULL = open(os.devnull,'w')
#########################################################################
#Main looping
#########################################################################
try:
while True:
###################################################################
#Base looping video
###################################################################
if (mode == 0):
if (needtostart1 == 1):
needtostart1 = 0
#for troubleshooting: uncomment
print("Starting main holding video")
m = subprocess.Popen(['omxplayer', '--display', '2', '-b', '--no-osd', movie1], stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True)
else:
#Not needed on base loop, but in case of crash
#Check for end of video
if m.poll() is not None:
#Relaunch the process to start again
needtostart1 = 1
if (needtostart2 == 1):
needtostart2 = 0
#for troubleshooting
print("Starting second monitor video")
n = subprocess.Popen(['omxplayer', '--display', '7', '-b', '--no-osd', movie2], stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True)
else:
#to sense ending and restart
if n.poll() is not None:
#Relaunch the process to start again
needtostart2 = 1
#give the loop some breathing space (eases up on resources, but delays response by 100ms)
time.sleep(0.1)
#when killed, get rid of players and any other stuff that needs doing
finally:
#make sure all players are killed fully off
os.system('killall omxplayer.bin')
os.system('killall omxplayer')
#turn the blinking cursor back on in the terminal
#os.system("setterm -cursor on > /dev/tty1")
print("Quitting, Goodbye!")