mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
Add the av_player_will_play_tags hook (#1842)
A general version of the reviewer_will_play_question_sounds and reviewer_will_play_answer_sounds hooks
This commit is contained in:
parent
d946e5ddd5
commit
7c543eeb2f
4 changed files with 38 additions and 11 deletions
|
@ -216,11 +216,11 @@ class Previewer(QDialog):
|
||||||
audio = c.question_av_tags()
|
audio = c.question_av_tags()
|
||||||
else:
|
else:
|
||||||
audio = c.answer_av_tags()
|
audio = c.answer_av_tags()
|
||||||
av_player.play_tags(audio)
|
|
||||||
else:
|
else:
|
||||||
|
audio = []
|
||||||
self._web.setPlaybackRequiresGesture(True)
|
self._web.setPlaybackRequiresGesture(True)
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
gui_hooks.av_player_will_play_tags(audio, self._state, self)
|
||||||
|
av_player.play_tags(audio)
|
||||||
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, f"preview{self._state.capitalize()}")
|
txt = gui_hooks.card_will_show(txt, c, f"preview{self._state.capitalize()}")
|
||||||
self._last_state = self._state_and_mod()
|
self._last_state = self._state_and_mod()
|
||||||
|
|
|
@ -548,10 +548,16 @@ class CardLayout(QDialog):
|
||||||
audio = c.question_av_tags()
|
audio = c.question_av_tags()
|
||||||
else:
|
else:
|
||||||
audio = c.answer_av_tags()
|
audio = c.answer_av_tags()
|
||||||
av_player.play_tags(audio)
|
|
||||||
else:
|
else:
|
||||||
|
audio = []
|
||||||
self.preview_web.setPlaybackRequiresGesture(True)
|
self.preview_web.setPlaybackRequiresGesture(True)
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
side = "question" if self.pform.preview_front.isChecked() else "answer"
|
||||||
|
gui_hooks.av_player_will_play_tags(
|
||||||
|
audio,
|
||||||
|
side,
|
||||||
|
self,
|
||||||
|
)
|
||||||
|
av_player.play_tags(audio)
|
||||||
|
|
||||||
self.updateCardNames()
|
self.updateCardNames()
|
||||||
|
|
||||||
|
|
|
@ -340,12 +340,11 @@ class Reviewer:
|
||||||
self.web.setPlaybackRequiresGesture(False)
|
self.web.setPlaybackRequiresGesture(False)
|
||||||
sounds = c.question_av_tags()
|
sounds = c.question_av_tags()
|
||||||
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
||||||
av_player.play_tags(sounds)
|
|
||||||
else:
|
else:
|
||||||
self.web.setPlaybackRequiresGesture(True)
|
self.web.setPlaybackRequiresGesture(True)
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
|
||||||
sounds = []
|
sounds = []
|
||||||
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
||||||
|
gui_hooks.av_player_will_play_tags(sounds, self.state, self)
|
||||||
av_player.play_tags(sounds)
|
av_player.play_tags(sounds)
|
||||||
# render & update bottom
|
# render & update bottom
|
||||||
q = self._mungeQA(q)
|
q = self._mungeQA(q)
|
||||||
|
@ -392,11 +391,10 @@ class Reviewer:
|
||||||
if c.autoplay():
|
if c.autoplay():
|
||||||
sounds = c.answer_av_tags()
|
sounds = c.answer_av_tags()
|
||||||
gui_hooks.reviewer_will_play_answer_sounds(c, sounds)
|
gui_hooks.reviewer_will_play_answer_sounds(c, sounds)
|
||||||
av_player.play_tags(sounds)
|
|
||||||
else:
|
else:
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
|
||||||
sounds = []
|
sounds = []
|
||||||
gui_hooks.reviewer_will_play_answer_sounds(c, sounds)
|
gui_hooks.reviewer_will_play_answer_sounds(c, sounds)
|
||||||
|
gui_hooks.av_player_will_play_tags(sounds, self.state, self)
|
||||||
av_player.play_tags(sounds)
|
av_player.play_tags(sounds)
|
||||||
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")
|
||||||
|
|
|
@ -925,6 +925,29 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
args=["player: aqt.sound.Player", "tag: anki.sound.AVTag"],
|
args=["player: aqt.sound.Player", "tag: anki.sound.AVTag"],
|
||||||
),
|
),
|
||||||
Hook(name="av_player_did_end_playing", args=["player: aqt.sound.Player"]),
|
Hook(name="av_player_did_end_playing", args=["player: aqt.sound.Player"]),
|
||||||
|
Hook(
|
||||||
|
name="av_player_will_play_tags",
|
||||||
|
args=[
|
||||||
|
"tags: list[anki.sound.AVTag]",
|
||||||
|
"side: str",
|
||||||
|
"context: Any",
|
||||||
|
],
|
||||||
|
doc="""Called before playing a card side's sounds.
|
||||||
|
|
||||||
|
`tags` can be used to inspect and manipulate the sounds
|
||||||
|
that will be played (if any).
|
||||||
|
|
||||||
|
`side` can either be "question" or "answer".
|
||||||
|
|
||||||
|
`context` is the screen where the sounds will be played (e.g., Reviewer, Previewer, and CardLayout).
|
||||||
|
|
||||||
|
This won't be called when the user manually plays sounds
|
||||||
|
using `Replay Audio`.
|
||||||
|
|
||||||
|
Note that this hook is called even when the `Automatically play audio`
|
||||||
|
option is unchecked; This is so as to allow playing custom
|
||||||
|
sounds regardless of that option.""",
|
||||||
|
),
|
||||||
# Addon
|
# Addon
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue