<!--全局 audio -->
    <audio
      id="audio"
      @playing="audioReady"
      @timeupdate="audioUpdateTime"
      @pause="audioPaused"
      @ended="audioEnd"
      @error="audioError"/>


// 监听微信端页面加载 触发音频load
    document.addEventListener('DOMContentLoaded', () => {
      const audio = document.getElementById('audio')
      audio.load()
      document.addEventListener('WeixinJSBridgeReady', () => {
        audio.load()
      }, false)
    })
audioUpdateTime(e) {
      // 更新时间和进度条 (默认一秒会执行多次 需要处理一秒只执行一次更新)
      let time = 0
      if (parseInt(e.target.currentTime) !== Number(time)) {
        time = parseInt(e.target.currentTime)
        const audio = document.getElementById('audio')
        const timeRanges = audio.buffered
        // 获取已缓存的时间  timeRanges.end(timeRanges.length - 1)
     // 计算百分比 展示进度
       parseInt(timeRanges.end(timeRanges.length - 1) * 100 / audio.duration * 100) / 100)
    }

 

相关文章:

  • 2021-10-10
  • 2021-12-05
  • 2022-12-23
  • 2021-08-25
  • 2021-08-10
  • 2021-12-27
  • 2022-12-23
猜你喜欢
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-01-26
相关资源
相似解决方案