讓 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 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告