简体   繁体   中英

Playing a Configurable Number of MP3 Files in Succession

So I will have the user select a range of tracks (all tracks are numbered) from a select box. So if I select the numbers 1 and 34, I want all 34 .mp3 files to be played, with each .mp3 file playing as soon as the previous one ends.

What would be the simplest way to do this in Javascript/Jquery? Will I have to load each individual audio file, and clear the last one played? What are your suggestions/recommendations?

The most simple answer is -

  1. using audio html element
  2. push the list of mp3 files path in an array
  3. add event listener on audio element for ended event, inside the callback function simple pop the mp3 files and assign it to audio src that's it

No you don't have to clear the last played file because browser has it's own pruning logic, although you can have your pruning logic at more granular level but that is required only when you have lot's of video elements of high resolution preventing your system's memory to consumed too much.

Hope it helps-

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