audio.stop() audio.src = addr setTimeout(()=>audio.play(), 100)
小程序播放同一音频两次要怎么写?[代码] innerAudioContext.src = ""[代码][代码] [代码][代码]innerAudioContext.onEnded(() => {[代码][代码] [代码][代码]innerAudioContext.onPlay(() => {[代码][代码] [代码][代码]innerAudioContext.offEnded()[代码][代码] [代码][代码]})[代码][代码] [代码][代码]innerAudioContext.play()[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]innerAudioContext.play()[代码] 目前是上面这么写的,工具端没问题。请问还有别的写法吗? 问完发现应该追求更高一点,譬如封装成函数,输入播放次数和源地址数组然后调用? 或者loop参数是否应该传入boolean或者数值呢? [代码]function[代码] [代码]playTwice(srcs,maxtimes) {[代码][代码] [代码][代码]let secondIAC = wx.createInnerAudioContext()[代码][代码] [代码][代码]secondIAC.obeyMuteSwitch = [代码][代码]false[代码][代码] [代码][代码]secondIAC.onError(() => {[代码][代码] [代码][代码]showToast({[代码][代码] [代码][代码]icon: [代码][代码]'none'[代码][代码],[代码][代码] [代码][代码]title: [代码][代码]'发音加载失败'[代码][代码],[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]let times = 0[代码][代码] [代码][代码]secondIAC.src = src[times][代码][代码] [代码][代码]secondIAC.onPlay(() => {[代码][代码] [代码][代码]times++[代码][代码] [代码][代码]})[代码][代码] [代码][代码]secondIAC.onEnded(() => {[代码][代码] [代码][代码]if[代码] [代码](times === maxtimes) {[代码][代码] [代码][代码]secondIAC.destroy()[代码][代码] [代码][代码]}[代码] [代码][代码] [代码][代码]secondIAC.src = src[times][代码][代码] [代码] [代码][代码]secondIAC.play()[代码][代码] [代码][代码]})[代码][代码] [代码][代码]secondIAC.play()[代码][代码]}[代码]
2021-12-08微信小程序innerAudioContext本地音频播放文件路径不支持相对路径 innerAudioContext.src = '../images/test.mp3' 应该使用绝对路径 innerAudioContext.src = 'pages/images/test.mp3' ——————————————— 原文链接:https://blog.csdn.net/luolaihua2018/article/details/104540194
createInnerAudioContext不能播放本地mp3微信小程序,createInnerAudioContext本能播放本地mp3(放在js文件同路径下)吧? 试了一下如果mp3带上远程url是可以的。。。 但微信小游戏,为什么可以播放本地mp3啊。。。我看官方示例的那个飞机大战,子弹的声音,爆炸声音都是本地的mp3
2021-12-07