How to add "replay" hotkey for audio?

Hi, everyone

I want to set a key on the computer keyboard (“z”) so that after viewing the card, when you press it, the audio file is played from the beginning.

I found the following script on the internet but it is for a video clip:

<script>
    window.onkeyup = function(e) {
        var key = e.keyCode ? e.keyCode : e.which;
        if (key == 90) {
            video = document.getElementById('video');
            video.play();
        }
    }
</script>

Is it possible for audio?

This already exists. Use ‘R’.

I forgot to clarify. I am adding audio using html code:

<audio controls  src="Doctor Who/07.mp3" autoplay>

</audio>

So ‘R’ key doesn’t work for me.

I will try to explain why I am using html for audio. Although it may not be logical.

If many decks are created in one profile, then media files (inside the collection.media folder) for all decks will be confused into one heap. It is more convenient for me to store the media files for each deck (within 1 profile) in the separate folder.

So, I use html in order that all audio\video files are stored in a specific folder (“Doctor Who” in my case), which inside the collection.media folder.

So, again, Is there any script that I can add to HTML to set ‘replay’ hotkey for audio file?

Considering how audio and video tags are related, just follow these steps.

  1. Add an ID to the audio tag
<audio controls src="Doctor Who/07.mp3" id="myaudio" autoplay></audio>
  1. Replace the snippet of code.
// ...
        video = document.getElementById('myaudio'); // Change the parameter.
//...

And in theory, it should still work.

You should be aware that the Anki docs on media files has the following warning:

If you want to include audio and pictures from a text file import, copy the files into the collection.media folder. Do not put subdirectories in the media folder, or some features will not work.

2 Likes