# Autoplay multiple audio files in sequence

**URL:** <https://forums.ankiweb.net/t/autoplay-multiple-audio-files-in-sequence/30469>\
**Category:** Card Design\
**Created:** [May 21, 2023, 10:22am UTC](https://forums.ankiweb.net/t/autoplay-multiple-audio-files-in-sequence/30469 "2023-05-21T10:22:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex11](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/alex11/32/6147_2.png) [@alex11](https://forums.ankiweb.net/u/alex11)\
**Post date:** [May 21, 2023, 10:22am UTC](https://forums.ankiweb.net/t/autoplay-multiple-audio-files-in-sequence/30469/1 "2023-05-21T10:22:27Z")

</div>

Recently as I went through some of my old wordlists for test preparation, I noticed lots of `<a href>` tags on my cards that link to audio files, so I did some simple jquery tricks to make the cards audible, but there is still one problem remain, which is that I want for the first two audio files to autoplay.

Luckily, I did find the script that “sometimes” works, so with that being said, the script doesn’t do the whole job. In some rare cases, the first two audio files do autoplay, but in most cases it only make the first audio file autoplay, and I’m guessing there might be something wrong with the script.

Below is the script and [here](https://drive.google.com/file/d/1P_ZHckI2lVhrX2Xu7ZJYsxg46TrI8B7N/view?usp=sharing) is a link to my test desk in case anyone wants to check that out.

```auto
<script>
jQuery(document).ready(function (){
var audioArray = document.getElementsByClassName('soundfiles');
var i = 0;
audioArray[i].play();
for (i = 0; i < audioArray.length - 1; ++i) {
    audioArray[i].addEventListener('ended', function(e){
        var currentSong = e.target;
        var next = $(currentSong).nextAll('audio');
        if (next.length) $(next[0]).trigger('play');
    });
}
});
</script>

```

---

<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:** [June 20, 2023, 10:22am UTC](https://forums.ankiweb.net/t/autoplay-multiple-audio-files-in-sequence/30469/2 "2023-06-20T10:22:31Z")

</div>

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