当前位置: 首页 > article >正文

VUE 获取视频时长,无需修改数据库,前提当前查看视频可以得到时长

第一字段处

 <el-table-column label="视频时长" align="center">
        <template slot-scope="scope">
          <span>{{ formatDuration(scope.row.duration) }}</span>
        </template>
      </el-table-column>

第二getlist

  getList() {
        this.loading = true;
             listFiles(this.queryParams).then(response => {
          this.fileList = response.rows.map(item => {
            return {
              ...item,
              duration: 0, // 初始化时长为 0
            };
          });

          this.fileList = response.rows;
          console.log(response)
          this.total = response.total;
          this.loading = false;
          // 加载视频元数据并更新时长
          this.loadVideoDurations();

        });
      },

loadVideoDurations() {
        this.fileList.forEach((item, index) => {
          const video = document.createElement('video');
          video.src = item.videourl;
          video.addEventListener('loadedmetadata', () => {
            // 更新时长(单位为秒)
            this.$set(this.fileList[index], 'duration', video.duration);
          });
        });
      },
      formatDuration(seconds) {
        if (!seconds) return '00:00';
        const minutes = Math.floor(seconds / 60);
        const secs = Math.floor(seconds % 60);
        return `${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
      },



点查看直接播放视频 添加autoplay 

<video
        width="100%"
        height="100%"
        :src=videourl
        controls="controls"
        ref="video"
        autoplay
></video>

http://www.kler.cn/a/562333.html

相关文章:

  • 第15章-超声波避障功能 HC-SR04超声波测距模块详解STM32超声波测距
  • Fisher信息矩阵(Fisher Information Matrix, FIM)与自然梯度下降:机器学习中的优化利器
  • KafkaTool
  • 使用 Redis 实现分布式锁
  • P8597 [蓝桥杯 2013 省 B] 翻硬币
  • TCP fast open
  • 存储产品和数据库产品之间有没有竞争关系
  • 了解大模型LLM:部署、优化与框架
  • 原生php实现redis缓存配置和使用方法
  • Android构建系统 - 01 环境准备
  • 深度学习-130-RAG技术之基于Anything LLM搭建本地私人知识库的应用策略问题总结(一)
  • 电脑不能正常启动了怎么办?查看解决方法
  • SQLite 删除表
  • 金和OA-C6 IncentivePlanFulfillAppprove sql注入漏洞复现(CNVD-2023-1)(附脚本)
  • UE5销毁Actor,移动Actor,简单的空气墙的制作
  • Redis面试题----MySQL 里有 2000w 数据,Redis 中只存 20w 的数据,如何保证 Redis 中的数据都是热点数据?
  • Unity游戏制作中的C#基础(5)条件语句和循环语句知识点全解析
  • 【音视频】音视频录制、播放原理
  • 计算机网络:应用层 —— 电子邮件
  • 【ISP】畸变校正 LDC