首页 > 技术文章 > el-upload上传视频获取视频宽高、时长信息

-liujia 2021-07-29 10:57 原文

<el-upload
    :on-change="uploadVideoChange">
    <el-button size="small" type="primary">
        <i class="el-icon-upload" />点击上传
    </el-button>
</el-upload>
uploadVideoChange (file, fileList) {
    // 防止触发两次
    if (file.status !== 'ready') return
    const getVideoInfo = new Promise((resolve) => {
        const videoElement = document.createElement("video");
        videoElement.src = URL.createObjectURL(file.raw);
        videoElement.addEventListener("loadedmetadata", function () {
            resolve({
          duration: videoElement.duration, height: videoElement.videoHeight, width: videoElement.videoWidth }); }); }); getVideoInfo.then((videoInfo)
=> { console.log(videoInfo); }) }

 

推荐阅读