收藏
回答

音频iso获取时长duration为0?

myaudio.src = "https://hmj-api.tapfun.cc/file/downloadFileMedia/d1928912-9b0d-4b6c-9328-ae7183246c12.mp3";
that.duration=that.formatSeconds(res.data.audioDuration);
myaudio.onTimeUpdate(function(){
  setTimeout(() => {
    let durationnum = parseInt(myaudio.duration);
    let time = that.formatSeconds(myaudio.duration);
    that.duration = time;
    that.durationNum = durationnum;
  });
  that.changeCurrent(myaudio.currentTime)
})


回答关注问题邀请回答
收藏

2 个回答

  • 彦斌
    彦斌
    2020-10-26

    应该是有BUG。不过我按以下方式可以获取了

    const audioContext = wx.createInnerAudioContext();
    const loadDuration = function () {
         setTimeout(() => {
            if (audioContext.duration === 0) {
                loadDuration();
             } else {
                // 获取到正确的duration
             }
         }, 100);
    };
    audioContext.onCanplay(loadDuration);
    
    2020-10-26
    有用
    回复
  • 今天天气很好
    今天天气很好
    2020-10-10

    先写个myaudio.onPlay(function callback),再用myaudio.onTimeUpdate(function callback)

    2020-10-10
    有用
    回复 1
    • 懒喵喵🐱
      懒喵喵🐱
      2020-10-12
      我试了下,还是获取不到
      2020-10-12
      回复
登录 后发表内容
问题标签