如何获取到音频文件是时长,duration获得是0

发布于 7 年前作者 li573838 次浏览最后编辑 7 年前来自 ask

this.innerAudioContext.src = data.sound;

let duration = this.innerAudioContext.duration;

console.log(duration)

输出来的是0

3 回复
qhe
qhe1 楼6 年前
cwen
cwen2 楼6 年前

还是不兼容各种手机,安卓的 就获取不到 时长

tgao
tgao3 楼5 年前

需要先写这个函数:innerAudioContext.onPlay(function callback),再调用InnerAudioContext.onTimeUpdate(function callback),然后在这个函数中获取音频时长即可。我试了,这个方法可以