# How to start playing second audio after first one has been ended?

**URL:** <https://forums.ankiweb.net/t/how-to-start-playing-second-audio-after-first-one-has-been-ended/24646>\
**Category:** Card Design\
**Created:** [November 14, 2022, 3:53am UTC](https://forums.ankiweb.net/t/how-to-start-playing-second-audio-after-first-one-has-been-ended/24646 "2022-11-14T03:53:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brumby](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@brumby](https://forums.ankiweb.net/u/brumby)\
**Post date:** [November 14, 2022, 3:53am UTC](https://forums.ankiweb.net/t/how-to-start-playing-second-audio-after-first-one-has-been-ended/24646/1 "2022-11-14T03:53:41Z")

</div>

Hello everyone! I need to make a card template with two playing audios but the second one is different each time. There are 6 fields with audios but only two of them should be played.  
The second audio should be determined by a random number and should be started after the first one has finished.

```auto
<script>
  {

    const audios = document.querySelectorAll(".soundLink");
    const rand = Math.floor(Math.random() * audios.length);

    let firstAudio = audios[0];
    let secondAudio = audios[rand + 1];

    firstAudio.click();

    //second audio should be played after the first one has been ended
    secondAudio.click();

  }
</script>

```

I tried to use an `.onended()’ method, but this code doesn’t work:

```auto
<script>
{

 const audios = document.querySelectorAll(".soundLink");
 const rand = Math.floor(Math.random() * audios.length);

  let firstAudio = audios[0];
  let secondAudio = audios[rand + 1];

  firstAudio.click();

  firstAudio.onended = function () {
    secondAudio.click();
  }

}
</script>

```

So, how to trigger playing the second audio after the first one has been finished?

---

<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:** [December 14, 2022, 3:53am UTC](https://forums.ankiweb.net/t/how-to-start-playing-second-audio-after-first-one-has-been-ended/24646/2 "2022-12-14T03:53:44Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
