-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvlc.py
63 lines (52 loc) · 1.47 KB
/
vlc.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
import os
from demosys.conf import settings
from .base import BaseTimer
try:
import vlc
except ImportError:
if not os.environ.get('DOCS_BUILDING'):
raise ImportError("python-vlc is needed for vlc timer")
class Timer(BaseTimer):
"""
Timer based on the python-vlc wrapper.
Plays the music file defined in ``settings.MUSIC``.
Requires ``python-vlc`` to be installed including the vlc application.
"""
def __init__(self, **kwargs):
self.player = vlc.MediaPlayer(settings.MUSIC)
self.paused = True
self.pause_time = 0
self.initialized = False
super().__init__(**kwargs)
def start(self):
"""Start the music"""
self.player.play()
self.paused = False
def pause(self):
"""Pause the music"""
self.pause_time = self.get_time()
self.paused = True
self.player.pause()
def toggle_pause(self):
"""Toggle pause mode"""
if self.paused:
self.start()
else:
self.pause()
def stop(self) -> float:
"""
Stop the music
Returns:
The current time in seconds
"""
self.player.stop()
return self.get_time()
def get_time(self) -> float:
"""
Get the current time in seconds
Returns:
The current time in seconds
"""
if self.paused:
return self.pause_time
return self.player.get_time() / 1000.0