随意播放 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);
}

更新于:25-06-2020

319 浏览量

开启你的职业生涯

完成课程获得认证

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