让 HTML5 音频做到随机播放


若要实现随机播放,请像这样添加歌曲 −

init ([
   'http://demo.com/songs/song1.mp3,
   'http://demo.com/songs/song2.mp3,
   'http://demo.com/songs/song3.mp3
]);

使用以下内容来使用 Math.random − 实现随机播放

function displayRandom() {
   var audio = Math.floor(Math.random() * (collection.length));
   audio = collection[audio];
   audio.play();
   setTimeout(loop,audio.duration*1000);
}

更新时间: 2020 年 6 月 25 日

319 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.