interrupt current audio when autoplay off

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

View file

@ -1735,6 +1735,9 @@ 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 = gui_hooks.card_will_show(

View file

@ -185,6 +185,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)
@ -228,6 +230,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")

View file

@ -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)])