京东6.18大促主会场领京享红包更优惠

 找回密码
 立即注册

QQ登录

只需一步,快速开始

Vue 监听视频播放时长的实例代码

2024-11-3 10:52| 发布者: 44f6fa4f5| 查看: 65| 评论: 0

摘要: 1、源码 [code]<template> <el-dialog class="videoBox" :title="title" :visible.sync="visible" width="40%" :before-close="handleClose" :close-on-click-modal="false" :close-on-press-escape="false">

1、源码

[code]<template> <el-dialog class="videoBox" :title="title" :visible.sync="visible" width="40%" :before-close="handleClose" :close-on-click-modal="false" :close-on-press-escape="false"> <video id="video" controls preload autoplay="autoplay" style="width: 100%" @canplay="getVideoDur"> <source :src="videoUrl" type="video/mp4"> </video> </el-dialog> </template> <script> export default { name: 'VideoPlayBack', data() { return { // 标题 title: null, // 是否表现弹框 visible: false, // 视频地址 videoUrl: null } }, methods: { /** * 初始化视频 */ initVideo() { this.$nextTick(() => { let myVideo = document.getElementById('video') myVideo.pause() myVideo.load() }); }, /** * 监听视频 */ getVideoDur() { //监听播放时间 var video = document.getElementById("video"); // //使用变乱监听方式捕捉变乱 // video.addEventListener("timeupdate", function () { // var timeDisplay = Math.floor(video.currentTime); // var duration = Math.floor(video.duration); // console.log("总时长", duration); // console.log("当前播放的时长", timeDisplay); // }, false); // 监听视频播放 // video.addEventListener("play", function () { // var duration = Math.floor(video.duration); // console.log("总时长", duration); // var timeDisplay = Math.floor(video.currentTime); // console.log("视频开始时长", timeDisplay); // }) // 监听视频暂停 video.addEventListener("pause", function () { var duration = Math.floor(video.duration); console.log("总时长", duration); var timeDisplay = Math.floor(video.currentTime); console.log("视频竣事时长", timeDisplay); }) }, /** * 关闭弹框 */ handleClose() { this.videoUrl = null this.visible = false }, } } </script> <style> .videoBox .el-dialog__header { background-color: #000000; } .videoBox .el-dialog__header .el-dialog__title { color: #fff; } .videoBox .el-dialog__body { padding: 0 !important; background-color: #000000; } </style>[/code]

2、监听视频及时时长

[code]video.addEventListener("timeupdate", function () { var timeDisplay = Math.floor(video.currentTime); var duration = Math.floor(video.duration); console.log("总时长", duration); console.log("当前播放的时长", timeDisplay); }, false);[/code]

3、监听视频播放时长

[code]video.addEventListener("play", function () { var duration = Math.floor(video.duration); console.log("总时长", duration); var timeDisplay = Math.floor(video.currentTime); console.log("视频开始时长", timeDisplay); })[/code]

4、监听视频暂停时长

[code]video.addEventListener("pause", function () { var duration = Math.floor(video.duration); console.log("总时长", duration); var timeDisplay = Math.floor(video.currentTime); console.log("视频竣事时长", timeDisplay); })[/code]

到此这篇关于Vue 监听视频播放时长的实例代码的文章就先容到这了,更多相干vue播放时长内容请搜刮脚本之家以前的文章或继续欣赏下面的相干文章希望各人以后多多支持脚本之家!


来源:https://www.jb51.net/javascript/328939rgn.htm
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
关闭

站长推荐上一条 /6 下一条

QQ|手机版|小黑屋|梦想之都-俊月星空 ( 粤ICP备18056059号 )|网站地图

GMT+8, 2025-7-2 03:19 , Processed in 0.027810 second(s), 18 queries .

Powered by Mxzdjyxk! X3.5

© 2001-2025 Discuz! Team.

返回顶部