如何隨機播放 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 次瀏覽

開啟你的 事業

完成課程,獲得證書

開始學習
廣告