mounted() {

this.audio = new Audio();
    this.audio.src = "../../src/assets/alarm/Alarm.mp3";
    let playPromise;
    let second = 10;
   //加载音频
    playPromise = this.audio.play();
    if (playPromise) {
      playPromise
        .then(() => {
          // 音频加载成功
          that.tiemr = setInterval(() => {
            second--;
            console.log(this.audio.paused);
            if (this.audio.paused) {
              playPromise = this.audio.play();
            }
            if (second <= 0) {
              this.audio.pause();
              clearInterval(that.tiemr);
            }
          }, 1000);
        })
        .catch(e => {
          console.error("音频加载失败" + e);
        });
    }

}

// 重新加载
this.audio.load();
 
// 判断是否正在播放 返回布尔值
this.audio.paused
 
// 暂停
this.audio.pause();

相关文章:

  • 2021-05-29
  • 2021-12-04
  • 2021-12-27
  • 2022-01-08
  • 2021-05-07
  • 2021-04-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-11-30
  • 2021-08-13
  • 2021-07-20
相关资源
相似解决方案