innerAudioContext.src = "" innerAudioContext.onEnded(() => { innerAudioContext.onPlay(() => { innerAudioContext.offEnded() }) 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.play() }) secondIAC.play() } |
audio.stop()
audio.src = addr
setTimeout(()=>audio.play(), 100)