Vue?監(jiān)聽(tīng)視頻播放時(shí)長(zhǎng)的實(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)聽(tīng)視頻
*/
getVideoDur() {
//監(jiān)聽(tīng)播放時(shí)間
var video = document.getElementById("video");
// //使用事件監(jiān)聽(tīng)方式捕捉事件
// video.addEventListener("timeupdate", function () {
// var timeDisplay = Math.floor(video.currentTime);
// var duration = Math.floor(video.duration);
// console.log("總時(shí)長(zhǎng)", duration);
// console.log("當(dāng)前播放的時(shí)長(zhǎng)", timeDisplay);
// }, false);
// 監(jiān)聽(tīng)視頻播放
// video.addEventListener("play", function () {
// var duration = Math.floor(video.duration);
// console.log("總時(shí)長(zhǎng)", duration);
// var timeDisplay = Math.floor(video.currentTime);
// console.log("視頻開(kāi)始時(shí)長(zhǎng)", timeDisplay);
// })
// 監(jiān)聽(tīng)視頻暫停
video.addEventListener("pause", function () {
var duration = Math.floor(video.duration);
console.log("總時(shí)長(zhǎng)", duration);
var timeDisplay = Math.floor(video.currentTime);
console.log("視頻結(jié)束時(shí)長(zhǎng)", 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)聽(tīng)視頻實(shí)時(shí)時(shí)長(zhǎng)
video.addEventListener("timeupdate", function () {
var timeDisplay = Math.floor(video.currentTime);
var duration = Math.floor(video.duration);
console.log("總時(shí)長(zhǎng)", duration);
console.log("當(dāng)前播放的時(shí)長(zhǎng)", timeDisplay);
}, false);3、監(jiān)聽(tīng)視頻播放時(shí)長(zhǎng)
video.addEventListener("play", function () {
var duration = Math.floor(video.duration);
console.log("總時(shí)長(zhǎng)", duration);
var timeDisplay = Math.floor(video.currentTime);
console.log("視頻開(kāi)始時(shí)長(zhǎng)", timeDisplay);
})4、監(jiān)聽(tīng)視頻暫停時(shí)長(zhǎng)
video.addEventListener("pause", function () {
var duration = Math.floor(video.duration);
console.log("總時(shí)長(zhǎng)", duration);
var timeDisplay = Math.floor(video.currentTime);
console.log("視頻結(jié)束時(shí)長(zhǎng)", timeDisplay);
})到此這篇關(guān)于Vue 監(jiān)聽(tīng)視頻播放時(shí)長(zhǎng)的實(shí)例代碼的文章就介紹到這了,更多相關(guān)vue播放時(shí)長(zhǎng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue中通過(guò)iframe方式加載本地的vue頁(yè)面的解決方法
這篇文章主要給大家介紹了在vue中如何通過(guò)iframe方式加載本地的vue頁(yè)面的解決方法,文中有詳細(xì)的解決流程,需要的朋友可以參考下2023-06-06
Vue項(xiàng)目中v-bind動(dòng)態(tài)綁定src路徑不成功問(wèn)題及解決
這篇文章主要介紹了Vue項(xiàng)目中v-bind動(dòng)態(tài)綁定src路徑不成功問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
mpvue小程序循環(huán)動(dòng)畫(huà)開(kāi)啟暫停的實(shí)現(xiàn)方法
這篇文章主要介紹了mpvue小程序循環(huán)動(dòng)畫(huà)開(kāi)啟暫停的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
vue項(xiàng)目登錄成功拿到令牌跳轉(zhuǎn)失敗401無(wú)登錄信息的解決
這篇文章主要介紹了vue項(xiàng)目登錄成功拿到令牌跳轉(zhuǎn)失敗401無(wú)登錄信息的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
用 Vue.js 遞歸組件實(shí)現(xiàn)可折疊的樹(shù)形菜單(demo)
通過(guò)本文給您演示一下如何有效地使用遞歸組件,我將通過(guò)建立一個(gè)可擴(kuò)展/收縮的樹(shù)形菜單的來(lái)一步步進(jìn)行。下面通過(guò)本文給大家分享用 Vue.js 遞歸組件實(shí)現(xiàn)可折疊的樹(shù)形菜單,需要的朋友參考下吧2017-12-12
將VUE項(xiàng)目部署到服務(wù)器的詳細(xì)步驟
經(jīng)過(guò)一段時(shí)間的探索,前端后端都有大致的樣子了,下面就是部署到服務(wù)器,這篇文章主要給大家介紹了關(guān)于將VUE項(xiàng)目部署到服務(wù)器的詳細(xì)步驟,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
vue使用element-ui的el-input監(jiān)聽(tīng)不了回車事件的解決方法
小編在使用element-ui時(shí),el-input組件監(jiān)聽(tīng)不了回車事件,怎么回事呢?下面小編給大家?guī)?lái)了vue使用element-ui的el-input監(jiān)聽(tīng)不了回車事件的解決方法,一起看看吧2018-01-01

