In Anki it is possible to pause an audio on a card (and do -5s / +5s) by pressing keys 5,6 and 7.
Is there any way of doing this in Ankidroid aswell?
The only thing I know of is pressing the audiobutton on a card in Ankidroid restarts the whole audio instead of pausing it.
And -5s/+5s don’t seem to be available either.
Hi, you’re in luck since there’s a piece of code I just made for another person looking to control their video which ought to work for this case too with some slight modifications.
In any case, it’s not possible to control the audio like that using Anki’s or AnkiDroid’s default audio playback features. You’ll need to use javascript to play the audio which will then allow you to control it as well.
The same caveats apply in this case too: Auto-Advance will not wait for your audio to finish playing and playback might continue after moving on to the next card.
With some additional cases added to the onkeyup listener the below code should work on desktop and Ankidroid. You should be replacing your current audio placement in your card template with this (assuming you have all audios in one field and want to play them back-to-back):
<audio controls id="player" />
<div id="audio-error"/>
<button onclick="seekBack();>-⏪</button>
<button onclick="playPause();>⏯</button>
<button onclick="seekForward();>⏩</button>
<script>
{
try {
videos = JSON.parse(`{{Audios_Array}}`);
} catch {
document.getElementById("audio-error").innerHTML = "Couldn't parse audios, check field content is in array format.";
}
const player = document.getElementById("player");
let index = 0;
player.addEventListener("ended", async () => {
if (++index < audios.length) {
player.src = videos[index];
// player.playbackRate = 1;
player.play();
} else {
// If there are no more audio files, make it possible to play from
// the first file again when the play button is clicked.
index = 0;
player.src = videos[index];
}
});
// play the first audio file
player.src = videos[index];
// player.playbackRate = 1;
player.play();
function seekBack() {
player.currentTime -= 5;
}
function seekForward() {
player.currentTime += 5;
}
function playPause() {
if (player.paused) {
player.play();
} else {
player.pause();
}
}
// Call audio controls with keyboard keys
document.onkeyup = (e) => {
if (e.key == "r") {
// Go back to start and replace all sounds when pressing R
index = 0;
player.src = videos[index];
// player.playbackRate = 1;
player.play();
} else if (e.key == "5") {
seekBack();
} else if (e.key == "6") {
playPause();
} else if (e.key == "7") {
seekForward();
}
};
// Assign audio controls to AnkiDroid variables
globalThis.userJs1 = seekBack;
globalThis.userJs2 = playPause;
globalThis.userJs3 = seekForward;
}
</script>
On AnkiDroid you either
tap added buttons on the screen (style those as you wish) or
in Settings > Controls > User actions (at the very bottom), select what gesture, phone or controller button will perform the audio controls. For example, you could make your phone’s volume buttons seek -5/+5 seconds on the audio. AnkiDroid User Manual