简体   繁体   English

连续播放可配置数量的MP3文件

[英]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. 因此,如果我选择数字1和34,则我希望播放所有34个.mp3文件,而每个.mp3文件都应在上一个结束时立即播放。

What would be the simplest way to do this in Javascript/Jquery? 用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 使用音频HTML元素
  2. push the list of mp3 files path in an array 推入数组中的mp3文件路径列表
  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 在结束事件的音频元素上添加事件侦听器,在简单的回调函数中弹出mp3文件并将其分配给音频src

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- 希望能帮助到你-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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