1、源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <video id= "video" controls= "" preload= "" autoplay= "autoplay" style= "width: 1264px;" data-origwidth= "0" data-origheight= "0" ></video> 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 }, } } .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; } |
2、监听视频实时时长
1 2 3 4 5 6 | video.addEventListener( "timeupdate" , function () { var timeDisplay = Math.floor(video.currentTime); var duration = Math.floor(video.duration); console.log( "总时长" , duration); console.log( "当前播放的时长" , timeDisplay); }, false ); |
3、监听视频播放时长
1 2 3 4 5 6 | video.addEventListener( "play" , function () { var duration = Math.floor(video.duration); console.log( "总时长" , duration); var timeDisplay = Math.floor(video.currentTime); console.log( "视频开始时长" , timeDisplay); }) |
4、监听视频暂停时长
1 2 3 4 5 6 | video.addEventListener( "pause" , function () { var duration = Math.floor(video.duration); console.log( "总时长" , duration); var timeDisplay = Math.floor(video.currentTime); console.log( "视频结束时长" , timeDisplay); }) |
到此这篇关于Vue 监听视频播放时长的实例代码的文章就介绍到这了,更多相关vue播放时长内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!