innerAudioContext二次播放失效了?
发布于 6 年前 作者 guiyinggong 12101 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

二次播放失效

  • 预期表现

每次进入页面都该播放音频的,作为提示音。但是目前只有第一次进入界面有。再进入界面就不播放了。。。

工具不行,手机还行

  • 复现路径
  • 提供一个最简复现 Demo

https://developers.weixin.qq.com/s/Nzb80Rmf7B5g

3 回复

刚才测试了一下,把自动播放改成播放(InnerAudioContext.play())再次进入就可以了!

可以播放啊:就用的官方例子

onLoad: function (options) {

_this = this;

_this.playAudio();

},

onUnload: function () {

_this.innerAudioContext.stop()

},

playAudio(){

// 使用 wx.createAudioContext 获取 audio 上下文 context

_this.innerAudioContext = wx.createInnerAudioContext();

_this.innerAudioContext.obeyMuteSwitch = false;

_this.innerAudioContext.onWaiting(() => {

console.log(‘onWaiting’);

});

_this.innerAudioContext.onCanplay(() => {

console.log(‘onCanplay’);

});

_this.innerAudioContext.onPlay(() => {

console.log(‘onPlay’);

});

_this.innerAudioContext.onTimeUpdate(() => {

console.log(‘onTimeUpdate’);

});

_this.innerAudioContext.onEnded(function (e) {

console.log(“onEnded”)

});

_this.innerAudioContext.src = https://rescdn.kingsunedu.com/resources/syn-29/6m/pagecontent/audio/176365e9-638d-bfad-0625-7783c07f82cf.mp3;

_this.innerAudioContext.autoplay = true;

}

代码片段中没有放音频,我自己测用的自家服务器,你们自己放一个吧

回到顶部