mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
play question audio when preview set to 'show both sides'
This commit is contained in:
parent
c67fc3e769
commit
c451141f97
2 changed files with 20 additions and 7 deletions
|
@ -13,9 +13,12 @@ from anki.utils import tmpdir, isWin, isMac, isLin
|
||||||
_soundReg = "\[sound:(.*?)\]"
|
_soundReg = "\[sound:(.*?)\]"
|
||||||
|
|
||||||
def playFromText(text):
|
def playFromText(text):
|
||||||
for match in re.findall(_soundReg, text):
|
for match in allSounds(text):
|
||||||
play(match)
|
play(match)
|
||||||
|
|
||||||
|
def allSounds(text):
|
||||||
|
return re.findall(_soundReg, text)
|
||||||
|
|
||||||
def stripSounds(text):
|
def stripSounds(text):
|
||||||
return re.sub(_soundReg, "", text)
|
return re.sub(_soundReg, "", text)
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
|
||||||
from anki.hooks import runHook, addHook, remHook, runFilter
|
from anki.hooks import runHook, addHook, remHook, runFilter
|
||||||
from aqt.webview import AnkiWebView
|
from aqt.webview import AnkiWebView
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
from anki.sound import playFromText, clearAudioQueue
|
from anki.sound import playFromText, clearAudioQueue, allSounds, play
|
||||||
|
|
||||||
|
|
||||||
# Data model
|
# Data model
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -1337,12 +1338,15 @@ where id in %s""" % ids2str(sf))
|
||||||
txt = _("(please select 1 card)")
|
txt = _("(please select 1 card)")
|
||||||
bodyclass = ""
|
bodyclass = ""
|
||||||
else:
|
else:
|
||||||
if self._previewBothSides:
|
|
||||||
self._previewState = "answer"
|
|
||||||
elif cardChanged:
|
|
||||||
self._previewState = "question"
|
|
||||||
# need to force reload even if answer
|
# need to force reload even if answer
|
||||||
txt = c.q(reload=True)
|
txt = c.q(reload=True)
|
||||||
|
|
||||||
|
questionAudio = []
|
||||||
|
if self._previewBothSides:
|
||||||
|
self._previewState = "answer"
|
||||||
|
questionAudio = allSounds(txt)
|
||||||
|
elif cardChanged:
|
||||||
|
self._previewState = "question"
|
||||||
if self._previewState == "answer":
|
if self._previewState == "answer":
|
||||||
func = "_showAnswer"
|
func = "_showAnswer"
|
||||||
txt = c.a()
|
txt = c.a()
|
||||||
|
@ -1352,7 +1356,13 @@ where id in %s""" % ids2str(sf))
|
||||||
|
|
||||||
clearAudioQueue()
|
clearAudioQueue()
|
||||||
if self.mw.reviewer.autoplay(c):
|
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 = mungeQA(self.col, txt)
|
||||||
txt = runFilter("prepareQA", txt, c,
|
txt = runFilter("prepareQA", txt, c,
|
||||||
|
|
Loading…
Reference in a new issue