createInnerAudioContext模拟器可以播放,真机调试获取不到duration?
发布于 8 年前 作者 xiayuan 14088 次浏览 来自 问答

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

代码片段

回到顶部