audio音頻在vue播放整理javascript
this.audio = new Audio(); this.audio.src = mp3; let playPromise; playPromise = this.audio.play(); if (playPromise) { playPromise.then(() => { // 音頻加載成功 // 音頻的播放須要耗時 that.tiemr = setInterval(() => { second--; if (second <= 0) { that.audio.pause() clearInterval(that.tiemr); } }, 1000); }).catch((e) => { // 音頻加載失敗 console.error(e); }); }
// 從新加載 this.audio.load(); // 判斷是否正在播放 返回布爾值 this.audio.paused // 暫停 this.audio.pause();