js 根据音频/视频文件获取音频/视频时长
作者:互联网
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文件的时长
标签:seconds,音频,js,var,file,视频文件,audioElement,Audio,minutes 来源: https://www.cnblogs.com/guodadan/p/15524645.html