方法1
<video :src="videoUrl" controls preload="auto" id="videoPlayer"></video>
<p>{{ videoDuration }}<p>
private videoDuration: any = ''
setTimeout(() => {
this.videoDuration = document.getElementId('videoPlayer').duration
},800)
方法2
<el-upload class="upload-demo" :action="actionUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload">
<button class="ce-button not-hover primary">
<i class="ce-icon_upload"></i>
<span>重新上传</span>
</button>
</el-upload>
传入参数为视频文件对象,js的代码如下:
beforeAvatarUpload(file) { {
let url = URL.createObjectURL(file);
let audioElement = new Audio(url);
let result;
audioElement.addEventListener("loadedmetadata", () => {
// 视频时长值的获取要等到这个匿名函数执行完毕才产生
result = audioElement.duration; //得到时长为秒,小数,182.36
});
}