this.audioContext = uni.createInnerAudioContext(); // 创建音频上下文
this.audioContext.onCanplay(() => {
console.log('-----可以播放音频-----');
})
this.audioContext.onError((err) => {
console.error('音频播放失败', err);
console.log('音频路径',this.audioContext.src)
toast('音频播放失败');
if (this.onFinish) this.onFinish(); // 发生错误时调用回调
});
// 播放指定索引的音频
private playAudioAtIndex(index: number) {
if (index < 0 || index >= this.audioList.length) return;
this.audioContext.stop(); // 停止当前音频
this.audioContext.src = this.audioList[index]; // 设置音频文件路径
this.audioContext.volume = this.volume; // 设置音量
this.audioContext.play(); // 开始播放
}
2 个回复
DCloud_UNI_yuhe
hello,可以私信我发一下你这个文件链接吗?我测试一下
菜菜2 (作者) - 11
这个网络路径的链接使用createInnerAudioContext播放在h5正常,在app才会报错:{"errMsg":"MediaError","errCode":-99}
菜菜2 (作者)
目前app使用renderjs的方式来播放音频
2025-07-01 18:58