Initialization() {
var t = this;
//设置src
console.log(this.data.fileUrl);
innerAudioContext.src = this.data.fileUrl;
//运行一次
innerAudioContext.play();
innerAudioContext.pause();
innerAudioContext.onCanplay(() => {
console.log(‘运行一次’)
//初始化duration
innerAudioContext.duration;
setTimeout(function () {
//延时获取音频真正的duration
var duration = innerAudioContext.duration;
console.log(duration)
var min = parseInt(duration / 60);
var sec = parseInt(duration % 60);
if (min.toString().length == 1) {
min = `0${min}`;
}
if (sec.toString().length == 1) {
sec = `0${sec}`;
}
t.setData({
audioDuration: innerAudioContext.duration,
showTime2: `${min}:${sec}`
});
}, 1000)
})
},
输出的duration是0