-
使用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
相关推荐
IvorySQL2 小时前
PostgreSQL 日报|恢复期 COPY TO 未日志表修复(10 月 21 日)贝猫说python4 小时前
大模型比赛2.3智能体开发(工具调用智能问答助手)许彰午5 小时前
28-ORA-01110数据文件读取错误凯凯姜5 小时前
MySQL 联合索引设计与索引失效猫咪很可爱6 小时前
Oracle TEMP 表空间不足(ORA-01652)问题分析与优化实践九零HTTP7 小时前
10月21号-CSDN配菜-IP池的5个坑Data-Miner7 小时前
需要做财务数据分析,有什么好用的工具?从准备到出报告的实操指南袋鼠云数栈8 小时前
让 SQL 解析不再重复造轮子:SqlParserX 正式开源这个DBA有点耶8 小时前
期货 CTP 系统 Oracle RAC 迁移国产库实战:读写分离架构设计与性能对标数据库安全8 小时前
AI数据访问安全 |如何控制AI访问权限,防止越权