隨意播放 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.