如何随机播放 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-01-29

856 次浏览

开启你的 事业

完成课程,获得证书

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