-
使用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
相关推荐
这个DBA有点耶3 天前
MVCC深入:Read View、版本链与快照读——InnoDB并发控制的内核DBA_G3 天前
从地面到云霄:GBase数据库在民航三大场景的落地实践自由能燃气设备3 天前
商用全预混低氮冷凝锅炉免费方案vs付费方案对比+选型避坑指南科创致远3 天前
科创致远 ESOP 系统核心效能与实战价值展示2601_962218613 天前
万象生鲜系统称重自动多退少补算法解决生鲜非标品痛点张洛闻Eren3 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容于平安3 天前
MySQL-触发器白远山3 天前
上海24小时自助健身房解决方案实战指南与经验分享Omics Pro3 天前
斯坦福Nature+Science|广义虚拟细胞基础大模型2603_965148113 天前
AI+API选品:下一代智能商务助手雏形已现