-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyomxplayer.py
51 lines (42 loc) · 1.39 KB
/
pyomxplayer.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
import pexpect
import re
from threading import Thread
from time import sleep
class OMXPlayer(object):
_LAUNCH_CMD = '/usr/bin/omxplayer --no-osd --blank --loop --orientation 90 --win 0,0,800,480 %s'
_PAUSE_CMD = 'p'
_TOGGLE_SUB_CMD = 's'
_QUIT_CMD = 'q'
_IMG_FILE = 'q'
_VOF=1
def __init__(self, mediafile):
self.play(mediafile)
def play(self, mediafile):
cmd = self._LAUNCH_CMD % (mediafile)
self._process = pexpect.spawn(cmd)
self._end_thread = Thread(target=self._get_end)
self._end_thread.start()
def _get_end(self):
while True:
sleep(0.5)
index = self._process.expect([pexpect.TIMEOUT,
pexpect.EOF])
if index == 1:
print('video press stop EOF '+str(index))
#self.stop()
break
else:
print('video TIMEOUT '+str(index))
#self.stop()
#break
continue
self._VOF=0
#self.stop()
self._process.send(self._QUIT_CMD)
self._process.terminate(force=True)
if index != 1:
self.play('/home/pi/gpmb/video.mp4')
def stop(self):
self._process.send(self._QUIT_CMD)
self._process.terminate(force=True)
#self._process = pexpect.spawn('feh -F '+self._IMG_FILE)