uniapp 监听推送的消息,然后播放音频,uni.createInnerAudioContext 只有第一次正常播放了,这是什么原因?求各位大佬支招
uni.onPushMessage((res) => {
console.log("收到推送消息:",res) //监听推送消息
let innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-hello-uniapp/2cc220e0-c27a-11ea-9dfb-6da8e309e0d8.mp3';
innerAudioContext.onPlay(() => {
console.log('开始播放');
});
innerAudioContext.onError((res) => {
console.log(res.errMsg);
console.log(res.errCode);
});
});
1***@qq.com (作者)
写到全局还是不行,我需要监听到消息就要播报音频,现在只能实现第一次播报
2023-05-26 09:28
Diligent_UI
回复 1***@qq.com: 写到全局你怎么写的
2023-05-26 09:29
1***@qq.com (作者)
回复 Diligent_UI: 就是在App.vue文件data中写的
2023-05-26 09:32
1***@qq.com (作者)
回复 Diligent_UI: 大佬,还有其他方法嘛,指教一下
2023-05-26 09:36
Diligent_UI
回复 1***@qq.com: 看不到整体怎么写的
2023-05-26 09:38
1***@qq.com (作者)
回复 Diligent_UI: 完整代码在楼下
2023-05-26 09:41