7***@qq.com
7***@qq.com
  • 发布:2026-05-18 16:32
  • 更新:2026-05-18 16:32
  • 阅读:18

uni.createInnerAudioContext 在微信里首次执行没有声音

分类:uni-app

methods: {
playSuccessAudio() {
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
// 你的成功音频路径
innerAudioContext.src = '/static/audio/success.mp3';
innerAudioContext.onPlay(() => {
console.log('开始播放成功音');
});
innerAudioContext.onError((res) => {
console.log('音频报错', res.errMsg, res.errCode);
});
// 播放完销毁
innerAudioContext.onEnded(() => {
innerAudioContext.destroy();
});
}
}

请各位大神帮忙看看,问题出在什么地方
if (res) {
let status = res.code;
if (status == 1) {
let data = res.data || {};
let a = data.a || [];
let b = data.b || [];
let c = data.c || [];
uni.$emit('verify_source_code', {
codeObj: data.code,
code: code,
type: codeType,
a: a,
b: b,
c: c,
codes: data.codes || []
});
this.playSuccessAudio(); // 成功提示音 调用的地方
this.showToast(code + ' 添加成功');
this.scan();
} else {
this.playFailAudio(); // 失败提示音
this.showToast(res.msg ? res.msg : '发生错误');
this.scan();
}
} else {
this.playFailAudio(); // 失败提示音
this.showModal('请点击确定重试', '发生错误', false);
this.scan();
}
成功加入就播放声音,在微信里首次执行没有声音,第一次弹出扫码成功加入后没有声音,要把弹出层关上然后在弹出扫码加入成功才有声音,请各位大神看看怎么回事,

2026-05-18 16:32 负责人:无 分享
已邀请:

要回复问题请先登录注册