From 7dc8f82906d57de19e1d94478e7e10dd57e057d4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 30 Sep 2017 17:24:56 +1000 Subject: [PATCH] mpv support --- anki/sound.py | 41 +++++++++++++++++++++++++++++++++++++++-- aqt/main.py | 5 +++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/anki/sound.py b/anki/sound.py index 383d94a4f..ff319887c 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -75,14 +75,51 @@ def retryWait(proc): except OSError: continue -# Mplayer settings +# MPV ########################################################################## -mplayerCmd = ["mplayer", "-really-quiet", "-noautosub"] +from anki.mpv import MPV + +class MpvManager(MPV): + def __init__(self): + super().__init__(window_id=None, debug=True) + + def queueFile(self, file): + path = os.path.join(os.getcwd(), file) + self.command("loadfile", path, "append") + self.set_property("playlist-pos", 0) + self.set_property("pause", False) + + def clearQueue(self): + self.command("stop") + + def togglePause(self): + self.set_property("pause", not self.get_property("pause")) + + def seekRelative(self, secs): + self.command("seek", secs, "relative") + +mpvManager = None + +def setupMPV(): + global mpvManager, _player, _queueEraser + mpvManager = MpvManager() + _player = mpvManager.queueFile + _queueEraser = mpvManager.clearQueue + +def cleanupMPV(): + global mpvManager, _player, _queueEraser + if mpvManager: + mpvManager.close() + mpvManager = None + _player = None + _queueEraser = None # Mplayer in slave mode ########################################################################## +mplayerCmd = ["mplayer", "-really-quiet", "-noautosub"] + mplayerQueue = [] mplayerManager = None mplayerReader = None diff --git a/aqt/main.py b/aqt/main.py index 70ec8b739..eff067e99 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -22,6 +22,10 @@ import aqt.webview import aqt.toolbar import aqt.stats import aqt.mediasrv + +from anki.sound import setupMPV, cleanupMPV +setupMPV() + from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \ restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \ openHelp, openLink, checkInvalidFilename, getFile @@ -294,6 +298,7 @@ close the profile or restart Anki.""")) def cleanupAndExit(self): self.errorHandler.unload() self.mediaServer.shutdown() + cleanupMPV() self.app.exit(0) # Collection load/unload