mpv support

This commit is contained in:
Damien Elmes 2017-09-30 17:24:56 +10:00
parent bb661a4b7d
commit 7dc8f82906
2 changed files with 44 additions and 2 deletions

View File

@ -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

View File

@ -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