<el-upload
:on-success="handleSuccess"
></el-upload>
async handleSuccess(res, file) {
let videoInfo = "";
// 防止触发两次
if (file.status !== "success") return;
if (file.raw.type === "video/mp4") {
videoInfo = await this.getFileDuration(file.raw);
} else {
videoInfo = "";
}
console.log('时长', videoInfo)
},
// 获取视频时长
getFileDuration(content) {
return new Promise((resolve) => {
const videoElement = document.createElement("video");
videoElement.src = URL.createObjectURL(content);
videoElement.addEventListener("loadedmetadata", function () {
resolve(videoElement.duration);
});
});
},