收藏
回答

createInnerAudioContext模拟器可以播放,真机调试获取不到duration?

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

代码片段

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签