安卓微信版本 8.0.49
ios 机型测试没问题, 一到安卓就获取不到音频的时长,我加了循环获取也不行
getAudioInfo(url = '') {
const obj = {
src: url,
duration: 0,
}
return new Promise((resolve, reject) => {
const audioContext = wx.createInnerAudioContext()
audioContext.src = url
audioContext.onCanplay(() => {
let jsTime = 5
let intervalID = setInterval(function () {
if (audioContext.duration !== 0 || jsTime === 0) {
obj.duration = audioContext.duration;
clearInterval(intervalID);
resolve(obj);
audioContext.destroy();
}
--jsTime
}, 500);
})
audioContext.onError((err) => {
console.log(`发生错误:`, err)
this.$message.warning('无效的音频文件')
})
})
}
// 函数返回的数据音频信息 {"src": "wxfile://tmp_504b6a68382d12b167a8ff05b9e0fdc1a97b727dd109579f.m4a", "duration": 0}