33import threading
44import logging
55import json
6+ import time
7+
8+ from omxplayer .player import OMXPlayer
9+
610logger = logging .getLogger ("RaspberryCast" )
711volume = 0
12+ player = None
13+
14+ def playeraction (action ):
15+ global player
16+ try :
17+ player .action (action )
18+ except :
19+ pass
820
921
1022def launchvideo (url , config , sub = False ):
1123 setState ("2" )
1224
13- os .system ("echo -n q > /tmp/cmd &" ) # Kill previous instance of OMX
25+ try :
26+ player .quit () #Kill previous instance of OMX
27+ except :
28+ pass
1429
1530 if config ["new_log" ]:
1631 os .system ("sudo fbi -T 1 -a --noverbose images/processing.jpg" )
@@ -25,8 +40,6 @@ def launchvideo(url, config, sub=False):
2540 new_log = config ["new_log" ]))
2641 thread .start ()
2742
28- os .system ("echo . > /tmp/cmd &" ) # Start signal for OMXplayer
29-
3043
3144def queuevideo (url , config , onlyqueue = False ):
3245 logger .info ('Extracting source video URL, before adding to queue...' )
@@ -42,7 +55,6 @@ def queuevideo(url, config, onlyqueue=False):
4255 kwargs = dict (width = config ["width" ], height = config ["height" ],
4356 new_log = config ["new_log" ]))
4457 thread .start ()
45- os .system ("echo . > /tmp/cmd &" ) # Start signal for OMXplayer
4658 else :
4759 if out is not None :
4860 with open ('video.queue' , 'a' ) as f :
@@ -140,6 +152,7 @@ def playlistToQueue(url, config):
140152
141153
142154def playWithOMX (url , sub , width = "" , height = "" , new_log = False ):
155+ global player
143156 logger .info ("Starting OMXPlayer now." )
144157
145158 logger .info ("Attempting to read resolution from configuration file." )
@@ -150,19 +163,19 @@ def playWithOMX(url, sub, width="", height="", new_log=False):
150163 resolution = " --win '0 0 {0} {1}'" .format (width , height )
151164
152165 setState ("1" )
166+ args = "-b" + resolution + " --vol " + str (volume )
153167 if sub :
154- os .system (
155- "omxplayer -b -r -o both '" + url + "'" + resolution +
156- " --vol " + str (volume ) +
157- " --subtitles subtitle.srt < /tmp/cmd"
158- )
168+ player = OMXPlayer (url , args + " --subtitles subtitle.srt" )
159169 elif url is None :
160170 pass
161171 else :
162- os .system (
163- "omxplayer -b -r -o both '" + url + "' " + resolution + " --vol " +
164- str (volume ) + " < /tmp/cmd"
165- )
172+ player = OMXPlayer (url , args )
173+
174+ try :
175+ while not player .playback_status () == "Stopped" : # Wait until video finished or stopped
176+ time .sleep (0.5 )
177+ except :
178+ pass
166179
167180 if getState () != "2" : # In case we are again in the launchvideo function
168181 setState ("0" )
@@ -181,7 +194,6 @@ def playWithOMX(url, sub, width="", height="", new_log=False):
181194 new_log = new_log ),
182195 )
183196 thread .start ()
184- os .system ("echo . > /tmp/cmd &" ) # Start signal for OMXplayer
185197 else :
186198 logger .info ("Playlist empty, skipping." )
187199 if new_log :
0 commit comments