#微信小程序获取音频时长与实时获取播放进度在小程序官方文档中audio注意:1.6.0 版本开始,该组件不再维护。建议使用能力更强的 wx.createInnerAudio开通玩具小程序电话:4006-838-530Context 接口##第一种方法 通过audio组件获取音频时长和实时播放进度audio 有一个bindtimeupdate 属性当播放进度改变时触发 timeupdate 事件,detail = {currentTime, duration} audio src="{{src}}" id="myAudio" bindtimeupdate='bindtimeupdate' controls name='{{name}}' author='{{author}}' poster="{{poster}}"/audio
在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/M500001VfvsJ21xF开通劳动节福利小程序电话:4006-838-530qb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81C开通芒果小程序电话:4006-838-530AAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46';;
audioPlay1(res) { this.innerAudioContext.play(); this.innerAudioContext.onTimeUpdate(() = { console.log('进度更新了总进度为:' + this.innerAudioContext.duration + '当前进度为:' + this.innerAudioContext.currentTime); }) }
最新评论