forked from willprice/python-omxplayer-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path76.py
More file actions
executable file
·54 lines (48 loc) · 1.45 KB
/
Copy path76.py
File metadata and controls
executable file
·54 lines (48 loc) · 1.45 KB
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
#!/usr/bin/env python2
from omxplayer.player import OMXPlayer
import os
from time import sleep
DEBUG = 1
def debug(*args):
if (DEBUG):
text = " ".join(list(map(str, args)))
print text
def play_film(filename="demo.mp4", duration=0, position=0):
debug("\nfilename:", filename)
debug(" position:", position)
debug(" duration:", duration)
trim_from_end = 0.5
#trim_from_end = 0
player = OMXPlayer(filename)
player.set_position(0.0)
debug(" pre-play pos:", player.position())
player.play()
# check and set position
full_length = player.duration()
# if the position is imposible, set it to 0
if position <= 0 or position > full_length:
position = 0.0
player.set_position(position)
# check and set duration
length_to_end = player.duration()
# if duration is imposible, set it to the length_to_end
if duration == 0 or duration > length_to_end:
wait = length_to_end - trim_from_end
else:
wait = duration
if wait < 0:
wait = 0
debug(" full length: ", full_length)
debug(" length to end: ", length_to_end)
debug(" wait: ", wait)
sleep(wait)
debug(" post sleep pos:", player.position())
player.pause()
player.quit()
debug(" post pause pos:", player.position())
return True
def main():
src = "../tests/media/test_media_1.mp4"
assert os.path.exists(src)
play_film(src, position=5, duration=5)
main()