android获取小程序音频时长,最新微信小程序获取音频时长与实时获取播放进度...
#微信小程序獲取音頻時長與實時獲取播放進度
在小程序官方文檔中
audio
注意:1.6.0 版本開始,該組件不再維護。建議使用能力更強的 wx.createInnerAudioContext 接口
##第一種方法 通過audio組件獲取音頻時長和實時播放進度
audio 有一個bindtimeupdate 屬性
當播放進度改變時觸發 timeupdate 事件,detail = {currentTime, duration}
在JS 直接通過bindtimeupdate 方法獲取就可以了
bindtimeupdate(res) { console.log('bindtimeupdate', parseInt(res.detail.currentTime), '時間總時長-->', parseInt(res.detail.duration)); }
##第二種 通過wx.createInnerAudioContext 接口
通過這個接口
JS 通過獲取實例 設置播放連接 然后我們通過點擊播放按鈕 獲取實時進度
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('進度更新了總進度為:' + this.innerAudioContext.duration + '當前進度為:' + this.innerAudioContext.currentTime);
this.setData({
slider_max: parseInt(this.innerAudioContext.duration),
slider_value: parseInt(this.innerAudioContext.currentTime)
})
})
}
總結
以上是生活随笔為你收集整理的android获取小程序音频时长,最新微信小程序获取音频时长与实时获取播放进度...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android contacts电话查询
- 下一篇: android行高,android –