diff --git a/anki/sound.py b/anki/sound.py index 46ad37e8d..d8735cc09 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -102,7 +102,7 @@ class MpvManager(MPV): super().__init__(window_id=None, debug=False) def queueFile(self, file): - runHook("mpvWillPlay") + runHook("mpvWillPlay", file) path = os.path.join(os.getcwd(), file) self.command("loadfile", path, "append-play") diff --git a/aqt/main.py b/aqt/main.py index 0ad101716..5de0d21bd 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -970,13 +970,19 @@ Difference to correct time: %s.""") % diffText Invalid property found on card. Please use Tools>Check Database, \ and if the problem comes up again, please ask on the support site.""")) - def onMpvWillPlay(self): - if not self._activeWindowOnPlay: - self._activeWindowOnPlay = self.app.activeWindow() + def _isVideo(self, file): + head, ext = os.path.splitext(file.lower()) + return ext in (".mp4", ".mov", ".mpg", ".mpeg", ".mkv", ".avi") + + def onMpvWillPlay(self, file): + if not self._isVideo(file): + return + + self._activeWindowOnPlay = self.app.activeWindow() or self._activeWindowOnPlay def onMpvIdle(self): w = self._activeWindowOnPlay - if w and not sip.isdeleted(w) and w.isVisible(): + if not self.app.activeWindow() and w and not sip.isdeleted(w) and w.isVisible(): w.activateWindow() w.raise_() self._activeWindowOnPlay = None