微信小程序> 最新微信小程序获取音频时长与实时获取播放进度

最新微信小程序获取音频时长与实时获取播放进度

浏览量:1015 时间: 来源:mini韦

#微信小程序获取音频时长与实时获取播放进度
在小程序官方文档中
audio
注意:1.6.0 版本开始,该组件不再维护。建议使用能力更强的 wx.createInnerAudioContext 接口

##第一种方法 通过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/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);    })  }

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎