demo
initInnerAudioContext() {
this.innerAudioContext = uni.createInnerAudioContext();
this.innerAudioContext.autoplay = true;
this.innerAudioContext.sessionCategory = 'ambient';
this.bindEvents();
},
// 销毁innerAudioContext实例,移除所有事件监听器
destroyInnerAudioContext() {
if (this.innerAudioContext) {
this.innerAudioContext.stop();
// 移除所有已绑定的事件监听器
this.innerAudioContext.offEnded();
this.innerAudioContext.offTimeUpdate();
this.innerAudioContext.offError();
this.innerAudioContext.destroy();
this.innerAudioContext = null;
}
},
// 监听音频播放错误事件
this.innerAudioContext.onError((error) => {
this.recordError(error);
// 记录错误信息并显示提示信息“音频播放错误”
console.error(`${this.playListKey}-音频播放错误: ` + JSON.stringify(error));
});
0 个回复