-
使用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
相关推荐
2301_7950997428 分钟前
golang如何在Gin中自定义验证器_golang Gin自定义验证器实现方法2301_7662834437 分钟前
如何在MongoDB GridFS中进行按文件大小(length)范围的查询萧曵 丶1 小时前
MySQL 高频面试题(由浅到深 完整版,面试必背)czlczl200209251 小时前
MySQL 执行引擎:排序与临时表机制深度解析lifewange2 小时前
DBeaver如何安装m0_631529822 小时前
CSS如何利用CSS变量进行渐变色管理_提升渐变配置的灵活性2301_818008442 小时前
数据库模型设计实战:如何正向工程从模型建表_规范化项目开发流程期待のcode3 小时前
Redis的数据清理机制oradh3 小时前
Oracle数据库服务器端编程介绍2401_846339563 小时前
Vue 3 中集成 Three.js 场景的完整实现指南