From c451141f97d9f93336fd624bc4c03dbc9406cbc4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 4 Dec 2017 12:45:22 +1000 Subject: [PATCH] play question audio when preview set to 'show both sides' --- anki/sound.py | 5 ++++- aqt/browser.py | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/anki/sound.py b/anki/sound.py index c8e8db112..983a9bcd8 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -13,9 +13,12 @@ from anki.utils import tmpdir, isWin, isMac, isLin _soundReg = "\[sound:(.*?)\]" def playFromText(text): - for match in re.findall(_soundReg, text): + for match in allSounds(text): play(match) +def allSounds(text): + return re.findall(_soundReg, text) + def stripSounds(text): return re.sub(_soundReg, "", text) diff --git a/aqt/browser.py b/aqt/browser.py index 369b929b8..ddcbc7a4b 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -23,7 +23,8 @@ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \ from anki.hooks import runHook, addHook, remHook, runFilter from aqt.webview import AnkiWebView from anki.consts import * -from anki.sound import playFromText, clearAudioQueue +from anki.sound import playFromText, clearAudioQueue, allSounds, play + # Data model ########################################################################## @@ -1337,12 +1338,15 @@ where id in %s""" % ids2str(sf)) txt = _("(please select 1 card)") bodyclass = "" else: - if self._previewBothSides: - self._previewState = "answer" - elif cardChanged: - self._previewState = "question" # need to force reload even if answer txt = c.q(reload=True) + + questionAudio = [] + if self._previewBothSides: + self._previewState = "answer" + questionAudio = allSounds(txt) + elif cardChanged: + self._previewState = "question" if self._previewState == "answer": func = "_showAnswer" txt = c.a() @@ -1352,7 +1356,13 @@ where id in %s""" % ids2str(sf)) clearAudioQueue() if self.mw.reviewer.autoplay(c): - playFromText(txt) + # if we're showing both sides at once, play question audio first + for audio in questionAudio: + play(audio) + # then play any audio that hasn't already been played + for audio in allSounds(txt): + if audio not in questionAudio: + play(audio) txt = mungeQA(self.col, txt) txt = runFilter("prepareQA", txt, c,