-
使用HTML5的video标签和JavaScript:
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> -
使用Vue的@load事件:
javascript<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> -
使用第三方库,如video.js:
javascript<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>
vue2获取视频时长
xingxingwuxin2024-07-21 14:08
相关推荐
better_liang28 分钟前
每日Java面试场景题知识点之-MySQL索引AgCl2329 分钟前
MYSQL-4-DQL数据查询语言-3/14-15别抢我的锅包肉35 分钟前
【MySQL】第五节 - 事务实战详解:从基础到并发控制(附 Navicat 可运行实验脚本)AgCl231 小时前
MYSQL-5-DCL数据查询语言-3/16IvorySQL1 小时前
PostgreSQL 技术日报 (4月7日)|内核开发新动态,多项功能优化落地IvorySQL2 小时前
PostgreSQL 技术日报 (4月6日)|内核补丁与性能优化速递IvorySQL2 小时前
PostgreSQL 技术日报 (4月5日)|六大核心补丁进展,生产环境必看想唱rap2 小时前
线程的同步与互斥IvorySQL2 小时前
走进高校,走近开源|IvorySQL 社区即将亮相应急管理大学开源学术报告会splage2 小时前
Oracle分页sql