vue中audio音频播放

 

audio音频在vue播放整理

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();

  

转载于:https://www.cnblogs.com/amang/p/10386990.html

你可能感兴趣的:(vue中audio音频播放)