android获取小程序音频时长,最新微信小程序获取音频时长与实时获取播放进度...
#微信小程序獲取音頻時長與實(shí)時獲取播放進(jìn)度
在小程序官方文檔中
audio
注意:1.6.0 版本開始,該組件不再維護(hù)。建議使用能力更強(qiáng)的 wx.createInnerAudioContext 接口
##第一種方法 通過audio組件獲取音頻時長和實(shí)時播放進(jìn)度
audio 有一個bindtimeupdate 屬性
當(dāng)播放進(jìn)度改變時觸發(fā) timeupdate 事件,detail = {currentTime, duration}
在JS 直接通過bindtimeupdate 方法獲取就可以了
bindtimeupdate(res) { console.log('bindtimeupdate', parseInt(res.detail.currentTime), '時間總時長-->', parseInt(res.detail.duration)); }
##第二種 通過wx.createInnerAudioContext 接口
通過這個接口
JS 通過獲取實(shí)例 設(shè)置播放連接 然后我們通過點(diǎn)擊播放按鈕 獲取實(shí)時進(jìn)度
this.innerAudioContext = wx.createInnerAudioContext()
this.innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46';;
audioPlay1(res) {
this.innerAudioContext.play();
this.innerAudioContext.onTimeUpdate(() => {
console.log('進(jìn)度更新了總進(jìn)度為:' + this.innerAudioContext.duration + '當(dāng)前進(jìn)度為:' + this.innerAudioContext.currentTime);
this.setData({
slider_max: parseInt(this.innerAudioContext.duration),
slider_value: parseInt(this.innerAudioContext.currentTime)
})
})
}
總結(jié)
以上是生活随笔為你收集整理的android获取小程序音频时长,最新微信小程序获取音频时长与实时获取播放进度...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android contacts电话查询
- 下一篇: android行高,android –