mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 04:37:22 -05:00
Added: Placeholder audio autoplay
This commit is contained in:
parent
4897ea8173
commit
7561bf8d6a
4 changed files with 20 additions and 12 deletions
|
|
@ -31,6 +31,8 @@ service FrontendService {
|
|||
// Save colour picker's custom colour palette
|
||||
rpc SaveCustomColours(generic.Empty) returns (generic.Empty);
|
||||
|
||||
// Plays an audio tag at an index in a specific card
|
||||
// If the index is blank, plays all audio on that side
|
||||
rpc PlayAudio(PlayAudioRequest) returns (generic.Empty);
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +50,6 @@ message SetSchedulingStatesRequest {
|
|||
|
||||
message PlayAudioRequest {
|
||||
bool answer_side = 1;
|
||||
uint32 index = 2;
|
||||
optional uint32 index = 2;
|
||||
uint64 cid = 3;
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ from aqt.operations import on_op_finished
|
|||
from aqt.operations.deck import update_deck_configs as update_deck_configs_op
|
||||
from aqt.progress import ProgressUpdate
|
||||
from aqt.qt import *
|
||||
from aqt.sound import play_clicked_audio_with_index
|
||||
from aqt.sound import play_tags
|
||||
from aqt.theme import ThemeManager
|
||||
from aqt.utils import aqt_data_path, show_warning, tr
|
||||
|
||||
|
|
@ -688,7 +688,12 @@ def next_card_data() -> bytes:
|
|||
def play_audio():
|
||||
req = PlayAudioRequest.FromString(request.data)
|
||||
card = aqt.mw.col.get_card(CardId(req.cid))
|
||||
play_clicked_audio_with_index(req.index, req.answer_side, card)
|
||||
# TODO: Pass tags with next_card_data rather than rendering the card here.
|
||||
tags = card.answer_av_tags() if req.answer_side else card.question_av_tags()
|
||||
if req.index is None:
|
||||
play_tags(tags)
|
||||
else:
|
||||
play_tags([tags[req.index]])
|
||||
|
||||
|
||||
post_handler_list = [
|
||||
|
|
|
|||
|
|
@ -925,16 +925,11 @@ def play_clicked_audio(pycmd: str, card: Card) -> None:
|
|||
"""eg. if pycmd is 'play:q:0', play the first audio on the question side."""
|
||||
play, context, str_idx = pycmd.split(":")
|
||||
idx = int(str_idx)
|
||||
play_clicked_audio_with_index(idx, context == "q", card)
|
||||
tags = card.question_av_tags() if context == "q" else card.answer_av_tags()
|
||||
play_tags([tags[idx]])
|
||||
|
||||
|
||||
def play_clicked_audio_with_index(index: int, answer_side: bool, card: Card):
|
||||
if answer_side:
|
||||
tags = card.answer_av_tags()
|
||||
else:
|
||||
tags = card.question_av_tags()
|
||||
av_player.play_tags([tags[index]])
|
||||
|
||||
play_tags = av_player.play_tags
|
||||
|
||||
# Init defaults
|
||||
##########################################################################
|
||||
|
|
|
|||
|
|
@ -41,10 +41,14 @@ export class ReviewerState {
|
|||
addEventListener("message", this.onMessage.bind(this));
|
||||
}
|
||||
|
||||
playAudio(answerSide: boolean, index?: number) {
|
||||
playAudio({ answerSide, index, cid: this.currentCard!.card!.id });
|
||||
}
|
||||
|
||||
onMessage(e: MessageEvent<ReviewerRequest>) {
|
||||
switch (e.data.type) {
|
||||
case "audio": {
|
||||
playAudio({ answerSide: e.data.answerSide, index: e.data.index, cid: this.currentCard!.card!.id });
|
||||
this.playAudio(e.data.answerSide, e.data.index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -108,6 +112,7 @@ export class ReviewerState {
|
|||
|
||||
const question = resp.nextCard?.front || "";
|
||||
this.updateHtml(question, resp?.nextCard?.css, resp?.nextCard?.bodyClass);
|
||||
this.playAudio(false)
|
||||
|
||||
this.beginAnsweringMs = Date.now();
|
||||
}
|
||||
|
|
@ -118,6 +123,7 @@ export class ReviewerState {
|
|||
|
||||
public showAnswer() {
|
||||
this.answerShown.set(true);
|
||||
this.playAudio(true)
|
||||
this.updateHtml(this._cardData?.back || "");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue