The play() request was interrupted by a new load request

切换音频会报错The play() request was interrupted by a new load request
处理方式:

playPause() {
  var audio = this.$refs.music;   // music为vue 中audio的ref值
  if(audio !== null) {
    if(this.playFlag) {		// 暂停
      audio.pause();
    }else {
      audio.currentTime = 0;		// 控制audio时间
      let playPromise = audio.play();
      if (playPromise) {
          playPromise.then(() => {
              // 音频加载成功
              setTimeout(() => {
              }, audio.duration * 1000); // audio.duration 为音频的时长单位为秒


          }).catch((e) => {
              // 失败后继续回调
              this.playPause();
          });
      }
    }
  }
},

你可能感兴趣的:(javaScript)