IOS 切入后台后无法播放音频?
"operateAudio:fail jsapi has no permission, event=operateAudio, runningState=background, permissionMsg=permission got, detail=jsapi has no permission"
app.json包含如下配置:
"requiredBackgroundModes": [
"location",
"audio"
],
const innerAudioContext = wx.createInnerAudioContext({
useWebAudioImplement: true // 是否使用 WebAudio 作为底层音频驱动,默认关闭。对于短音频、播放频繁的音频建议开启此选项,开启后将获得更优的性能表现。由于开启此选项后也会带来一定的内存增长,因此对于长音频建议关闭此选项
})
if (wx.setInnerAudioOption) {
wx.setInnerAudioOption({
mixWithOther: true,
obeyMuteSwitch: false,
autoplay: true
})
} else {
innerAudioContext.obeyMuteSwitch = false;
innerAudioContext.autoplay = true;
}
// const innerAudioContext = wx.getBackgroundAudioManager()
//监听各个阶段
innerAudioContext.onCanplay(() => {
console.log('可以播放');
innerAudioContext.play();
});
innerAudioContext.onPlay(() => {
console.log('监听到音频开始播放');
});
innerAudioContext.onEnded(() => {
console.log('音频自然播放结束事件');
innerAudioContext.src = 'nomusic'
});
innerAudioContext.onStop(() => {
console.log('音频停止事件');
});
innerAudioContext.onError((res) => {
console.log("播放失败", res);
});
innerAudioContext.onWaiting((res) => {
console.log('音频加载中事件,当音频因为数据不足,需要停下来加载时会触发')
});
innerAudioContext.src="http://xxxx"