vue 获取视频时长的实例代码
直接通过element-ui自带的上传组件结合js即可,代码如下:
HTML:
重新上传
js:
beforeAvatarUpload(file){
varfileName=file.name||''
varext=fileName.split('.')[fileName.split('.').length-1]
if(ext!=="doc"&&ext!=="docx"&&ext!=="xls"&&ext!=="xlsx"
&&ext!=="ppt"&&ext!=="pptx"&&ext!=="pdf"&&ext!=="mp4"){
this.$notify({
title:"失败",
message:"上传资源只能是doc/docx/xls/xlsx/ppt/pptx/pdf/mp4格式!",
type:"error",
duration:3000
});
returnfalse
}
//ppt(10MB),word(10MB),excel(5MB)
if(ext=="doc"||ext=="docx"||ext=="ppt"||ext=="pptx"){
debugger
if(parseInt(file.size)>parseInt('10485760')){
this.$notify({
title:"失败",
message:"上传word、ppt文件上限为10MB!",
type:"error",
duration:3000
});
returnfalse
}
}
if(ext=='mp4'){//获取视频时长
varurl=URL.createObjectURL(file);
varaudioElement=newAudio(url);
varduration;
audioElement.addEventListener("loadedmetadata",function(_event){
duration=audioElement.duration;//时长为秒,小数,182.36
this.$parent.$data.wDuration=parseInt(duration)
console.log(duration);
});
}
this.$parent.$data.wFileName=file.name
this.$parent.$data.wSize=parseFloat(file.size/1024).toFixed(2)//获取文件大小
}
总结
以上所述是小编给大家介绍的vue获取视频时长的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎欢迎给我留言,小编会及时回复大家的!
热门推荐
1 怎么说祝福语简短
3 带清的简短祝福语
7 修祖屋祝福语简短
10 入学祝福语简短走心
11 圆圆的祝福语简短
12 庆双节祝福语简短
13 女神节日简短祝福语大全
14 学生开心成语祝福语简短
15 拜年啦祝福语大全简短
16 发小结婚简短祝福语
17 国庆简短幽默祝福语
18 18岁祝福语搞笑简短