<el-upload
:before-upload="beforeAvatarUpload">
</el-upload>
beforeAvatarUpload(file) {
// 获取视频时长
var url = URL.createObjectURL(file);
var audioElement = new Audio(url);
var duration;
this.durationNumber = audioElement.addEventListener(
"loadedmetadata",
function(_event) {
duration = audioElement.duration; //时长为秒,小数
return duration;
}
);
setTimeout(() => {
//视频大小(MB)
let fileSize = file.size / 1024 / 1024;
this.bandwidth = fileSize / duration;
}, 50);
if (
[
"video/mp4",
"video/ogg",
"video/flv",
"video/avi",
"video/wmv",
"video/rmvb",
"video/mov"
].indexOf(file.type) == -1
) {
// layer.msg("请上传正确的视频格式");
this.$message({
type: "info",
message: "请上传正确的视频格式"
});
return false;
}
if (this.bandwidth > 2) {
// 视频带宽不能超过2MB/s
this.$message.error('视频带宽过大,上传失败!');
return false;
}
this.isShowUploadVideo = false;
},
12-12
1047
02-21
5041
03-27
1202
10-31
586