getDuration(file) {
let url = this.getSrc(file);
let audioElement = new Audio(url);
audioElement.addEventListener("loadedmetadata", () => {
var time = audioElement.duration;
//分钟
var minute = time / 60;
var minutes = parseInt(minute);
if (minutes < 10) {
minutes = "0" + minutes;
}
//秒
var second = time % 60;
var seconds = Math.floor(second);
if (seconds < 10) {
seconds = "0" + seconds;
}
file.duration = minutes + ":" + seconds;
this.$set(file, file)
});
},
只有Audio对象,没有Video对象,用Audio也可以获取video文件的时长