Replace default mpv quit keybindings if mpv version is >= 0.30

4614d432a8
This commit is contained in:
kelciour 2020-06-26 20:36:58 +03:00
parent 5e5dc517ca
commit 610f9eb236
2 changed files with 15 additions and 1 deletions

View file

@ -448,6 +448,10 @@ class MPV(MPVBase):
if not inspect.ismethod(method):
continue
# Bypass MPVError: no such event 'init'
if method_name == "on_init":
continue
if method_name.startswith("on_property_"):
name = method_name[12:]
name = name.replace("_", "-")

View file

@ -19,7 +19,7 @@ from anki.lang import _
from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag
from anki.utils import isLin, isMac, isWin
from aqt import gui_hooks
from aqt.mpv import MPV, MPVBase
from aqt.mpv import MPV, MPVBase, MPVCommandError
from aqt.qt import *
from aqt.taskman import TaskManager
from aqt.utils import restoreGeom, saveGeom, showWarning, startup_info
@ -334,6 +334,16 @@ class MpvManager(MPV, SoundOrVideoPlayer):
self.default_argv += ["--config-dir=" + base_path]
super().__init__(window_id=None, debug=False)
def on_init(self) -> None:
try:
self.command("keybind", "q", "stop")
self.command("keybind", "Q", "stop")
self.command("keybind", "CLOSE_WIN", "stop")
self.command("keybind", "ctrl+w", "stop")
self.command("keybind", "ctrl+c", "stop")
except MPVCommandError:
print("mpv too old")
def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
assert isinstance(tag, SoundOrVideoTag)
self._on_done = on_done