vue2获取视频时长

  1. 使用HTML5的video标签和JavaScript:

    <template>
      <video ref="video" autoplay controls loop muted @loadedmetadata="getVideoDuration">
        <source src="https://desktop-yikao.oss-cn-beijing.aliyuncs.com/avatar/kaissp.mp4" type="video/mp4">
      </video>
    </template>
     
    <script>
    export default {
      methods: {
        getVideoDuration() {
          const videoElement = this.$refs.video;
          const duration = videoElement.duration;
          console.log(duration);
        }
      }
    }
    </script>
  2. 使用Vue的@load事件:

    <template>
      <video ref="video" @load="getVideoDuration" :src="videoSource"></video>
    </template>
     
    <script>
    export default {
      data() {
        return {
          videoSource: "your_video_source",
        };
      },
      methods: {
        getVideoDuration() {
          const videoElement = this.$refs.video;
          const duration = videoElement.duration;
          console.log(duration);
        }
      }
    }
    </script>

  3. 使用第三方库,如video.js:

    <template>
      <video ref="video" class="video-js"></video>
    </template>
     
    <script>
    import videojs from "video.js";
    import "video.js/dist/video-js.css";
     
    export default {
      mounted() {
        this.initVideoPlayer();
      },
      methods: {
        initVideoPlayer() {
          const videoElement = this.$refs.video;
          const player = videojs(videoElement);
          
          player.on("loadedmetadata", () => {
            const duration = player.duration();
            console.log(duration);
          });
          
          player.src("your_video_source");
        }
      }
    }
    </script>

相关推荐

  1. vue2获取视频

    2024-07-21 16:58:03       25 阅读
  2. Golang获取视频信息

    2024-07-21 16:58:03       47 阅读
  3. js通过视频链接获取视频

    2024-07-21 16:58:03       37 阅读
  4. ffmpeg 获取视频的命令及其输出

    2024-07-21 16:58:03       27 阅读
  5. Php 通过 FFmpeg 获取远程视频和截图

    2024-07-21 16:58:03       35 阅读
  6. maya 设置半径 获取,设置

    2024-07-21 16:58:03       33 阅读
  7. uni-app获取音频播放

    2024-07-21 16:58:03       62 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-21 16:58:03       101 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-21 16:58:03       109 阅读
  3. 在Django里面运行非项目文件

    2024-07-21 16:58:03       87 阅读
  4. Python语言-面向对象

    2024-07-21 16:58:03       96 阅读

热门阅读

  1. mybatis中的useGeneratedKeys和keyProperty

    2024-07-21 16:58:03       23 阅读
  2. AI Agent的创新之路:AutoGen与LangGraph的比较

    2024-07-21 16:58:03       20 阅读
  3. Android笔试面试题AI答之Activity(3)

    2024-07-21 16:58:03       19 阅读
  4. 关闭终端后继续执行celery任务

    2024-07-21 16:58:03       24 阅读
  5. 学习C语言之 深入了解数据存储

    2024-07-21 16:58:03       18 阅读
  6. WordPress杂技

    2024-07-21 16:58:03       23 阅读
  7. 赞扬的10条原则

    2024-07-21 16:58:03       26 阅读
  8. WHAT - 贪心场景和算法实现

    2024-07-21 16:58:03       26 阅读
  9. 多级联动jquery-cxselect-js的使用

    2024-07-21 16:58:03       23 阅读
  10. 使用"山水博客"的排序功能制作"专题文章"

    2024-07-21 16:58:03       20 阅读
  11. C# Word转换HTML(附在线转换工具)

    2024-07-21 16:58:03       25 阅读