Vue?監(jiān)聽視頻播放時(shí)長的實(shí)例代碼
1、源碼
<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 { // 標(biāo)題 title: null, // 是否顯示彈框 visible: false, // 視頻地址 videoUrl: null } }, methods: { /** * 初始化視頻 */ initVideo() { this.$nextTick(() => { let myVideo = document.getElementById('video') myVideo.pause() myVideo.load() }); }, /** * 監(jiān)聽視頻 */ getVideoDur() { //監(jiān)聽播放時(shí)間 var video = document.getElementById("video"); // //使用事件監(jiān)聽方式捕捉事件 // video.addEventListener("timeupdate", function () { // var timeDisplay = Math.floor(video.currentTime); // var duration = Math.floor(video.duration); // console.log("總時(shí)長", duration); // console.log("當(dāng)前播放的時(shí)長", timeDisplay); // }, false); // 監(jiān)聽視頻播放 // video.addEventListener("play", function () { // var duration = Math.floor(video.duration); // console.log("總時(shí)長", duration); // var timeDisplay = Math.floor(video.currentTime); // console.log("視頻開始時(shí)長", timeDisplay); // }) // 監(jiān)聽視頻暫停 video.addEventListener("pause", function () { var duration = Math.floor(video.duration); console.log("總時(shí)長", duration); var timeDisplay = Math.floor(video.currentTime); console.log("視頻結(jié)束時(shí)長", timeDisplay); }) }, /** * 關(guān)閉彈框 */ 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>
2、監(jiān)聽視頻實(shí)時(shí)時(shí)長
video.addEventListener("timeupdate", function () { var timeDisplay = Math.floor(video.currentTime); var duration = Math.floor(video.duration); console.log("總時(shí)長", duration); console.log("當(dāng)前播放的時(shí)長", timeDisplay); }, false);
3、監(jiān)聽視頻播放時(shí)長
video.addEventListener("play", function () { var duration = Math.floor(video.duration); console.log("總時(shí)長", duration); var timeDisplay = Math.floor(video.currentTime); console.log("視頻開始時(shí)長", timeDisplay); })
4、監(jiān)聽視頻暫停時(shí)長
video.addEventListener("pause", function () { var duration = Math.floor(video.duration); console.log("總時(shí)長", duration); var timeDisplay = Math.floor(video.currentTime); console.log("視頻結(jié)束時(shí)長", timeDisplay); })
到此這篇關(guān)于Vue 監(jiān)聽視頻播放時(shí)長的實(shí)例代碼的文章就介紹到這了,更多相關(guān)vue播放時(shí)長內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何啟動(dòng)一個(gè)Vue.js項(xiàng)目
這篇文章主要介紹了如何啟動(dòng)一個(gè)Vue.js項(xiàng)目,對(duì)Vue.js感興趣的同學(xué),可以參考下2021-04-04關(guān)于Vue不能監(jiān)聽(watch)數(shù)組變化的解決方法
本文主要介紹了Vue不能監(jiān)聽(watch)數(shù)組變化的解決方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09vue3?騰訊地圖設(shè)置簽到范圍并獲取經(jīng)緯度的實(shí)現(xiàn)代碼
本文給大家介紹vue3?騰訊地圖設(shè)置簽到范圍并獲取經(jīng)緯度的實(shí)現(xiàn)代碼,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2022-05-05vue2?使用echarts實(shí)現(xiàn)地圖點(diǎn)擊進(jìn)入下一層級(jí)+點(diǎn)擊空白處回退功能
這篇文章主要介紹了vue2?使用echarts實(shí)現(xiàn)地圖點(diǎn)擊進(jìn)入下一層級(jí)+點(diǎn)擊空白處回退,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-05-05Vue-scoped(局部)樣式使用方法及實(shí)例代碼
這篇文章主要介紹了Vue-scoped(局部)樣式使用方法及實(shí)例代碼,文中示例代碼介紹了的非常詳細(xì)感興趣的同學(xué)可以參考閱讀一下2023-05-05vue-cli3 取消eslint校驗(yàn)代碼的解決辦法
這篇文章主要介紹了vue-cli3 取消eslint校驗(yàn)代碼的解決辦法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01