-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.py
58 lines (42 loc) · 1.41 KB
/
player.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
import os
import signal
import sys
from random import shuffle
from time import sleep
from omxplayer.player import OMXPlayer
from pathlib import Path
def play():
print('Starting player...')
cinemagraphs_path = os.path.join('cinemagraphs', 'processed')
cinemagraphs = os.listdir(cinemagraphs_path)
shuffle(cinemagraphs)
global current_player
current_player = None
for i, cinemagraph in enumerate(cinemagraphs):
path_str = os.path.join(cinemagraphs_path, cinemagraph)
path = Path(path_str)
dbus_name = 'org.mpris.MediaPlayer2.omxplayer{}'.format(i)
print('Now playing "{}".'.format(path_str))
previous_player = current_player
current_player = OMXPlayer(path, args=['--loop', '--no-osd', '-b'], dbus_name=dbus_name)
current_player.set_video_pos(0, 0, 1024, 600)
if previous_player is not None:
previous_player.quit()
for alpha_fade_in in range(0, 255):
current_player.set_alpha(alpha_fade_in)
sleep(0.01)
sleep(600)
for alpha_fade_out in reversed(range(0, 255)):
current_player.set_alpha(alpha_fade_out)
sleep(0.02)
current_player.quit()
def exit_handler(sig, frame):
print('\nQuitting...')
if current_player is not None:
try:
current_player.quit()
except Exception as e:
print(e)
sleep(1)
sys.exit(0)
signal.signal(signal.SIGINT, exit_handler)