[AnkiMobile] Auto-advance vs. html audio element?

I think you’re going to need to turn Anki’s own Auto Advance off and instead implement auto-advancing functionality with javascript where you include the condition of waiting for your audio to finish playing before automatically proceeding.

Using the basic code for auto-advancing (by Keks here)

Since you already have javascript for playing your audio in exactly the way you need, I think what you’d do is call the answer function buttonAnswerEase*/ pycmd('ease*') in your player’s “ended” event like this

        const audios = Array({{Repeat}} * 2).fill(`{{Audio}}`);
        const player = document.getElementById("player");
        let index = 0;

        player.addEventListener("ended", () => {
            if (++index < audios.length) {
                player.src = audios[index];
              player.muted = index % 2;
              player.playbackRate = {{Speed}}
                player.play();
            } else {
               // All audio played, automatically advance by answering "Good"
               try {
                  // AnkiDroid
                  buttonAnswerEase3();
               } catch {
                  // Desktop
                  pycmd(‘ease3’);
               }
            }
        });
        // play the first audio file

        
        player.src = audios[index];
        player.playbackRate = {{Speed}}
        player.play();

Assuming that the code is on your card Back. If you’re playing the audio on the Front then use

		try {
			// AnkiDroid
			showAnswer();
		} catch {
			// Desktop
			pycmd("ans");
		}

Then you’d just do buttonAnswerEase3();/pycmd(‘ease3’); on the Back side using the timer style or immediately.

2 Likes