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)
})
最后咋解决了
应该是有BUG。不过我按以下方式可以获取了
const audioContext = wx.createInnerAudioContext(); const loadDuration = function () { setTimeout(() => { if (audioContext.duration === 0) { loadDuration(); } else { // 获取到正确的duration } }, 100); }; audioContext.onCanplay(loadDuration);
先写个myaudio.onPlay(function callback),再用myaudio.onTimeUpdate(function callback)