From db69f84c0a6a4f6d377e230343c5c19e4dd782a7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 25 Feb 2020 17:49:06 +1000 Subject: [PATCH] interrupt current audio when autoplay off --- qt/aqt/browser.py | 5 ++++- qt/aqt/reviewer.py | 4 ++++ qt/aqt/sound.py | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index d8ecb9fe3..277627698 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1772,8 +1772,11 @@ where id in %s""" else: audio = c.answer_av_tags() av_player.play_tags(audio) + else: + av_player.maybe_interrupt() - txt = self.mw.prepare_card_text_for_display(txt) + + txt = self.mw.prepare_card_text_for_display(txt) txt = gui_hooks.card_will_show( txt, c, "preview" + self._previewState.capitalize() ) diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py index 9200b15f6..316c33803 100644 --- a/qt/aqt/reviewer.py +++ b/qt/aqt/reviewer.py @@ -187,6 +187,8 @@ The front of this card is empty. Please run Tools>Empty Cards.""" # play audio? if self.autoplay(c): av_player.play_tags(c.question_av_tags()) + else: + av_player.maybe_interrupt() # render & update bottom q = self._mungeQA(q) @@ -230,6 +232,8 @@ The front of this card is empty. Please run Tools>Empty Cards.""" # play audio? if self.autoplay(c): av_player.play_tags(c.answer_av_tags()) + else: + av_player.maybe_interrupt() a = self._mungeQA(a) a = gui_hooks.card_will_show(a, c, "reviewAnswer") diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index fcebb3662..508a9611c 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -95,14 +95,17 @@ class AVPlayer: def play_tags(self, tags: List[AVTag]) -> None: """Clear the existing queue, then start playing provided tags.""" self._enqueued = tags[:] - if self.interrupt_current_audio: - self._stop_if_playing() + self.maybe_interrupt() self._play_next_if_idle() def stop_and_clear_queue(self) -> None: self._enqueued = [] self._stop_if_playing() + def maybe_interrupt(self) -> None: + if self.interrupt_current_audio: + self._stop_if_playing() + def play_file(self, filename: str) -> None: self.play_tags([SoundOrVideoTag(filename=filename)])