diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 2e2f88f04..91c1fe12e 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -12,7 +12,7 @@ from anki.notes import Note from anki.utils import htmlToTextLine, isMac from aqt import AnkiQt, gui_hooks from aqt.qt import * -from aqt.sound import clearAudioQueue +from aqt.sound import av_player from aqt.utils import ( addCloseShortcut, askUser, @@ -207,8 +207,7 @@ question on all cards.""" if not self.addNote(self.editor.note): return tooltip(_("Added"), period=500) - # stop anything playing - clearAudioQueue() + av_player.stop_and_clear_queue() self.onReset(keep=True) self.mw.col.autosave() @@ -225,7 +224,7 @@ question on all cards.""" def _reject(self) -> None: gui_hooks.state_did_reset.remove(self.onReset) gui_hooks.current_note_type_did_change.remove(self.onModelChange) - clearAudioQueue() + av_player.stop_and_clear_queue() self.removeTempNote(self.editor.note) self.editor.cleanup() self.modelChooser.cleanup() diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index b8c38352d..da085252c 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -32,7 +32,7 @@ from anki.utils import ( from aqt import AnkiQt, gui_hooks from aqt.editor import Editor from aqt.qt import * -from aqt.sound import allSounds, clearAudioQueue, play +from aqt.sound import av_player from aqt.utils import ( MenuList, SubMenu, @@ -1703,7 +1703,7 @@ where id in %s""" questionAudio = [] if self._previewBothSides: - questionAudio = allSounds(txt) + questionAudio = self.mw.col.backend.get_av_tags(txt) if self._previewState == "answer": func = "_showAnswer" txt = c.a() @@ -1711,15 +1711,13 @@ where id in %s""" bodyclass = bodyClass(self.mw.col, c) - clearAudioQueue() if self.mw.reviewer.autoplay(c): # if we're showing both sides at once, play question audio first - for audio in questionAudio: - play(audio) + av_player.play_tags(questionAudio) # then play any audio that hasn't already been played - for audio in allSounds(txt): - if audio not in questionAudio: - play(audio) + answer_audio = self.mw.col.backend.get_av_tags(txt) + unplayed_audio = [x for x in answer_audio if x not in questionAudio] + av_player.extend_and_play(unplayed_audio) txt = mungeQA(self.col, txt) gui_hooks.card_will_show( diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py index ca0f0772d..dd6636a83 100644 --- a/qt/aqt/clayout.py +++ b/qt/aqt/clayout.py @@ -12,7 +12,7 @@ from anki.lang import _, ngettext from anki.utils import bodyClass, isMac, isWin, joinFields from aqt import gui_hooks from aqt.qt import * -from aqt.sound import clearAudioQueue, playFromText +from aqt.sound import av_player from aqt.utils import ( askUser, downArrow, @@ -344,10 +344,8 @@ Please create a new card type first.""" self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass)) self.pform.backWeb.eval("_showAnswer(%s, '%s');" % (json.dumps(a), bodyclass)) - clearAudioQueue() if c.id not in self.playedAudio: - playFromText(c.q()) - playFromText(c.a()) + av_player.play_from_text(self.mw.col, c.q() + c.a()) self.playedAudio[c.id] = True self.updateCardNames() @@ -593,7 +591,7 @@ Enter deck to place new %s cards in, or leave blank:""" def reject(self): self.cancelPreviewTimer() - clearAudioQueue() + av_player.stop_and_clear_queue() if self.addMode: # remove the filler fields we added for name in self.emptyFields: diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index 6a5eb8e60..d648b05ca 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -10,7 +10,7 @@ from anki.lang import _, ngettext from anki.utils import fmtTimeSpan, ids2str from aqt import gui_hooks from aqt.qt import * -from aqt.sound import clearAudioQueue +from aqt.sound import av_player from aqt.utils import askUser, getOnlyText, openHelp, openLink, shortcut, showWarning @@ -24,7 +24,7 @@ class DeckBrowser: self.scrollPos = QPoint(0, 0) def show(self): - clearAudioQueue() + av_player.stop_and_clear_queue() self.web.resetHandlers() self.web.onBridgeCmd = self._linkHandler self._renderPage() diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index a293c19c7..1009e2210 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -26,7 +26,7 @@ from anki.notes import Note from anki.utils import checksum, isWin, namedtmp, stripHTMLMedia from aqt import AnkiQt, gui_hooks from aqt.qt import * -from aqt.sound import getAudio +from aqt.sound import av_player, getAudio from aqt.utils import ( getFile, openHelp, @@ -702,8 +702,7 @@ to a cloze type first, via Edit>Change Note Type.""" name = urllib.parse.quote(fname.encode("utf8")) return '' % name else: - aqt.sound.clearAudioQueue() - aqt.sound.play(fname) + av_player.play_file(fname) return "[sound:%s]" % fname def urlToFile(self, url): diff --git a/qt/aqt/overview.py b/qt/aqt/overview.py index 80f5fb69c..619b3a61c 100644 --- a/qt/aqt/overview.py +++ b/qt/aqt/overview.py @@ -4,7 +4,7 @@ import aqt from anki.lang import _ -from aqt.sound import clearAudioQueue +from aqt.sound import av_player from aqt.utils import askUserDialog, openLink, shortcut, tooltip @@ -17,7 +17,7 @@ class Overview: self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb) def show(self): - clearAudioQueue() + av_player.stop_and_clear_queue() self.web.resetHandlers() self.web.onBridgeCmd = self._linkHandler self.mw.setStateShortcuts(self._shortcutKeys()) diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py index 42524df2e..7fb990ab0 100644 --- a/qt/aqt/reviewer.py +++ b/qt/aqt/reviewer.py @@ -17,7 +17,7 @@ from anki.lang import _, ngettext from anki.utils import bodyClass, stripHTML from aqt import AnkiQt, gui_hooks from aqt.qt import * -from aqt.sound import clearAudioQueue, getAudio, play, playFromText +from aqt.sound import av_player, getAudio from aqt.utils import ( askUserDialog, downArrow, @@ -95,7 +95,6 @@ class Reviewer: self.hadCardQueue = False c = self.mw.col.sched.getCard() self.card = c - clearAudioQueue() if not c: self.mw.moveToState("overview") return @@ -114,15 +113,14 @@ class Reviewer: else: state = self.state c = self.card - clearAudioQueue() if state == "question": - playFromText(c.q()) + av_player.play_from_text(self.mw.col, c.q()) elif state == "answer": txt = "" if self._replayq(c, previewer): txt = c.q() txt += c.a() - playFromText(txt) + av_player.play_from_text(self.mw.col, txt) # Initializing the webview ########################################################################## @@ -184,7 +182,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""" else: q = c.q() if self.autoplay(c): - playFromText(q) + av_player.play_from_text(self.mw.col, q) # render & update bottom q = self._mungeQA(q) q = gui_hooks.card_will_show(q, c, "reviewQuestion") @@ -225,9 +223,8 @@ The front of this card is empty. Please run Tools>Empty Cards.""" c = self.card a = c.a() # play audio? - clearAudioQueue() if self.autoplay(c): - playFromText(a) + av_player.play_from_text(self.mw.col, a) a = self._mungeQA(a) a = gui_hooks.card_will_show(a, c, "reviewAnswer") # render and update bottom @@ -788,5 +785,4 @@ time = %(time)d; def onReplayRecorded(self): if not self._recordedAudio: return tooltip(_("You haven't recorded your voice yet.")) - clearAudioQueue() - play(self._recordedAudio) + av_player.play_file(self._recordedAudio) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 6b22c8f27..eb084e37a 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -9,7 +9,6 @@ from typing import Optional import aqt from anki.lang import _ -from anki.sound import stripSounds from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild from aqt.qt import * @@ -481,7 +480,7 @@ def restoreHeader(widget, key): def mungeQA(col, txt): txt = col.media.escapeImages(txt) - txt = stripSounds(txt) + txt = col.backend.strip_av_tags(txt) return txt