简体   繁体   中英

MediaElement.js - how to autoplay next audio

How to play next audio tag when the current one ends? I am using plagin's MediaElement.js.

<div class="audio-player track quotations">
  <audio src="http://k003.kiwi6.com/hotlink/9ucf2r3yo6/chasing_cars_cover_chris_-    _for_hollie_s_cover.mp3" type="audio/mp3" controls="controls">
  </audio>
</div>
<div class="audio-player track quotations">
  <audio src="http://k004.kiwi6.com/hotlink/vvy55kc7c5/new_distance.mp3" type="audio/mp3" controls="controls">
  </audio>
</div>

You can add an ended eventlistener to the audio tag, and automatically play the next one. For example;

    var selector = 'audio'; // CHANGE as per your requirements
    var audios = $(selector), len = audios.length, i = 0;
    audios.bind('ended', function(e){
        i++;
        if(i === len)   i=0;
        audios[i].play();
    });   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM