interrupt current audio when autoplay off

This commit is contained in:
Damien Elmes 2020-02-25 17:49:06 +10:00
parent f71484a444
commit db69f84c0a
3 changed files with 13 additions and 3 deletions

View File

@ -1772,6 +1772,9 @@ where id in %s"""
else: else:
audio = c.answer_av_tags() audio = c.answer_av_tags()
av_player.play_tags(audio) 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 = gui_hooks.card_will_show(

View File

@ -187,6 +187,8 @@ The front of this card is empty. Please run Tools>Empty Cards."""
# play audio? # play audio?
if self.autoplay(c): if self.autoplay(c):
av_player.play_tags(c.question_av_tags()) av_player.play_tags(c.question_av_tags())
else:
av_player.maybe_interrupt()
# render & update bottom # render & update bottom
q = self._mungeQA(q) q = self._mungeQA(q)
@ -230,6 +232,8 @@ The front of this card is empty. Please run Tools>Empty Cards."""
# play audio? # play audio?
if self.autoplay(c): if self.autoplay(c):
av_player.play_tags(c.answer_av_tags()) av_player.play_tags(c.answer_av_tags())
else:
av_player.maybe_interrupt()
a = self._mungeQA(a) a = self._mungeQA(a)
a = gui_hooks.card_will_show(a, c, "reviewAnswer") a = gui_hooks.card_will_show(a, c, "reviewAnswer")

View File

@ -95,14 +95,17 @@ class AVPlayer:
def play_tags(self, tags: List[AVTag]) -> None: def play_tags(self, tags: List[AVTag]) -> None:
"""Clear the existing queue, then start playing provided tags.""" """Clear the existing queue, then start playing provided tags."""
self._enqueued = tags[:] self._enqueued = tags[:]
if self.interrupt_current_audio: self.maybe_interrupt()
self._stop_if_playing()
self._play_next_if_idle() self._play_next_if_idle()
def stop_and_clear_queue(self) -> None: def stop_and_clear_queue(self) -> None:
self._enqueued = [] self._enqueued = []
self._stop_if_playing() 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: def play_file(self, filename: str) -> None:
self.play_tags([SoundOrVideoTag(filename=filename)]) self.play_tags([SoundOrVideoTag(filename=filename)])