-
Notifications
You must be signed in to change notification settings - Fork 1
/
mympv.py
53 lines (42 loc) · 1.84 KB
/
mympv.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
from config import VOLUME_PROPERTY
from mpv import MPV
class MyMPV(MPV):
# -------------------------------------------------------------------------
# Initialization.
# -------------------------------------------------------------------------
# The mpv process and the communication code run in their own thread
# context. This results in the callback methods below being run in that
# thread as well.
def __init__(self, player):
# Pass a window id to embed mpv into that window. Change debug to True
# to see the json communication.
super().__init__(window_id=None, debug=False)
self.__player = player
# -------------------------------------------------------------------------
# Callbacks
# -------------------------------------------------------------------------
# property change events:
# "time-pos" -> on_property_time_pos().
def on_property_chapter(self, chapter=None):
source = self.__player.getSelectedSource()
source.chapterWasChanged(chapter)
def on_property_metadata(self, metadata=None):
source = self.__player.getSelectedSource()
source.metadata_changed(metadata)
def on_property_pause(self, pause=None):
source = self.__player.getSelectedSource()
source.pause_changed(pause)
# -------------------------------------------------------------------------
# Commands
# -------------------------------------------------------------------------
# Many commands must be implemented by changing properties.
def play(self):
self.set_property("pause", False)
def pause(self):
self.set_property("pause", True)
def setVolume(self, volume: int):
try:
self.set_property(VOLUME_PROPERTY, int(volume))
except:
# not running, no problem
pass