小程序播放器远程音频不会自动停止播放
发布于 6 年前 作者 jie36 2065 次浏览 来自 问答

使用小程序录音功能,录音完成,使用audio进行播放,可以正常使用自动停止,并执行事件。

但是

把audio上传到服务端之后

回头再播放的时候就不能正常使用自动停止事件了,不会执行audio.onEnded事件?

怎么回事?

class PlayVoice {
 
  constructor() {
    this.src = '';
    this.innerAudioContext = null;
  }
  // 播放
  playVoice(temppath) {
    console.log(temppath)
    console.log(temppath)
    this.innerAudioContext && this.innerAudioContext.destroy();
    this.innerAudioContext = wx.createInnerAudioContext();
 
    this.src = this.innerAudioContext.src = temppath;
    this.src && this.stopVoice(this.src);
    this.innerAudioContext.play();
  }
 
  // 自动播放停止
  endVoice(fn) {
    console.log('自动播放停止', fn)
    console.log('ddjhsajhj',this.innerAudioContext.onEnded)
 
    this.innerAudioContext.onEnded((res) => {
      console.log(789798)
      fn && fn()
    })
  }
 
  // 停止播放
  stopVoice(temppath) {
    this.innerAudioContext.src = temppath;
    this.innerAudioContext.stop();
  }
   
}

播放代码如上。


求解

在线等~急急急~

1 回复

提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

回到顶部