# Start Playing Audio from a Timestamp

**URL:** <https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315>\
**Category:** Help\
**Created:** [November 23, 2020, 11:05am UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315 "2020-11-23T11:05:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joa9743](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@joa9743](https://forums.ankiweb.net/u/joa9743)\
**Post date:** [November 23, 2020, 11:05am UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/1 "2020-11-23T11:05:19Z")

</div>

**Can you make audio start playing from a timestamp?**

I’m using anki to memorise lyrics. The question card tells me the song and section, I type in the lyrics for that section, and then the audio plays on the answer side, it’s been working well.

I’ve been splitting up each song’s sections using a audio editor and importing the subsequent audio files. However it would save time if I could just import the whole song and tell Anki what time to start playing it on each card.

I searched online, and messed around with the html on the cards audio field, but had no luck.

---

<div class="post-metadata">

**Author:** ![hkr](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@hkr](https://forums.ankiweb.net/u/hkr)\
**Post date:** [November 23, 2020, 6:25pm UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/2 "2020-11-23T18:25:01Z")

</div>

I’m not sure, but there might be an add-on for that. Alternatively, if you know javascript, you can do that by using HTML `audio` tag and manipulating the audio element with javascript. Here is an example:

### Fields

- `audio_file`
  - audio file name
  - make sure to add an underscore at the beginning of the file name so that it will not be deleted as an unused file during media check, and then put the file in the `collection.media` folder.
  - e.g. `_your_audio_file.mp3`

- `start_pos`
  - set the start position (in seconds)
  - can be empty
  - e.g. `5`

- `end_pos`
  - set the end position (in seconds)
  - can be empty
  - e.g. `10`

### Template

```auto
<audio id="my-audio" controls src="{{audio_file}}"></audio>

<script>
    var startPos = parseInt('{{start_pos}}', 10);
    startPos = startPos ? startPos : 0;
    var endPos = parseInt('{{end_pos}}', 10);
    var myAudio = document.querySelector('#my-audio');
    myAudio.currentTime = startPos;
    if (endPos) {
        myAudio.addEventListener('timeupdate', () => {
            if (myAudio.currentTime > endPos) {
                myAudio.pause();
                myAudio.currentTime = startPos;
            }
        });
    } else {
        myAudio.addEventListener('ended', () => {
            myAudio.currentTime = startPos;
        });
    }
    // To enable Autoplay:
    // Requires Anki 2.1.36 beta3 or higher
    // Enable "Automatically play audio" in the deck option
    // Uncomment the next line
    // myAudio.play();
</script>

```

### Screenshot

 ![seek_media](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/d/d6493cd1df9052beab156767e42813945d4faef9.png)

### Note

Anki 2.1.36 beta3 or higher is required to enable autoplay for `<audio>` tag.

I tested this template on Anki 2.1.36 beta3 and AnkiDroid 2.14.0. I’m not sure if this works on AnkiMobile, since I don’t have an iOS device.

---

<div class="post-metadata">

**Author:** ![joa9743](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@joa9743](https://forums.ankiweb.net/u/joa9743)\
**Post date:** [November 24, 2020, 3:03am UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/4 "2020-11-24T03:03:34Z")

</div>

Thanks heaps, that works great!

---

<div class="post-metadata">

**Author:** ![jcznk](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jcznk/32/15215_2.png) [@jcznk](https://forums.ankiweb.net/u/jcznk)\
**Post date:** [April 21, 2022, 9:59pm UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/6 "2022-04-21T21:59:05Z")

</div>

Is this supposed to work in Anki 2.1.49+ too?  
I tried it with Anki 2.1.49 (dc80804a)⁩ and unluckily it did nothing for me

The “control panel” ( ![image](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/2/24ef0b3ab9f3074f6f474450a86201d56d97bf6a.png)) is also completely static and unresponsive, the bar does not move and I cannot click on it

I wonder if I am doing something wrong (I did uncomment the “myAudio.play();” line)

---

<div class="post-metadata">

**Author:** ![hkr](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@hkr](https://forums.ankiweb.net/u/hkr)\
**Post date:** [April 22, 2022, 1:19pm UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/7 "2022-04-22T13:19:28Z")

</div>

I’ve just tested and confirmed it works with Anki 2.1.49 and 2.1.51 rc2 (Qt6) on Windows 10.

---

<div class="post-metadata">

**Author:** ![jcznk](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jcznk/32/15215_2.png) [@jcznk](https://forums.ankiweb.net/u/jcznk)\
**Post date:** [April 22, 2022, 3:31pm UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/8 "2022-04-22T15:31:11Z")

</div>

Thank you!  
My mistake was that I did not remove `[sound:` and `]` after copy-pasting the audio file from another note

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 4:24am UTC](https://forums.ankiweb.net/t/start-playing-audio-from-a-timestamp/5315/9 "2023-05-01T04:24:15Z")

</div>


