如何随机播放 HTML5 音频
javascriptweb developmentfront end scripts更新于 2024/5/16 16:17:00
要随机播放,请添加如下歌曲:
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); }