<template>
<div>
<div class="video_box">
<div class="video_center">
<div class="resource-container" style="width:70%;position:relative;">
<div class="video-title">1233123</div>
<template>
<video
ref="video"
id="video"
src="./cat.mp4"
:autoplay="videolist.autoplay"
:controls="videolist.controls"
:controlslist="videolist.controlslist"
:webkit-playsinline="webkitplaysinline"
style="width:100%;height:100%"
>
</video>
</template>
</div>
<div style="width:30%" class="video_right">
<p style="padding:1rem;">选集</p>
<ul>
<li v-for="(item,index) in 3" :key="index"
style="cursor:pointer;padding:10px;"
:class="activeIndex == index + '' ? 'video-active':''"
@click="open(item,index)"
>{{index + 1}}. 中华人民...</li>
</ul>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: '',
data() {
return {
videolist:{
autoplay:false,
controls:'controls',
controlslist:'nodownload noplaybackrate'
},
webkitplaysinline:'true',
playHistory:{
resourceIndex:-1,
currentFileIndex:-1,
currenTime:0
},
videoPlayer:null,
activeIndex:'0',
currentResource:{}
}
},
mounted(){
this.querylist()
},
methods: {
querylist(){
this.$nextTick(() => {
this.initVideoplayer()
this.fileTimelengthRecord()
})
},
initVideoplayer(){
if(!this.videoPlayer && this.$refs.video){
this.videoPlayer = this.$refs.video
let sym
setInterval(() => {
let time = this.videoPlayer.currentTime
if(time-sym>1){
this.videoPlayer.currentTime=sym
}
sym=this.videoPlayer.currentTime
},500)
this.videoPlayer.addEventListener('timeupdate',(e) => {
sessionStorage.setItem('currentTime',this.videoPlayer.currentTime)
sessionStorage.setItem('duration',this.videoPlayer.duration)
})
this.videoPlayer.addEventListener('pause',(e) => {
})
this.videoPlayer.addEventListener('play',(e) => {})
this.videoPlayer.addEventListener('ended',(e) => {
console.log(this.videoPlayer.currentTime,'ended 播放完成')
})
}
},
fileTimelengthRecord(){
let stat = sessionStorage.getItem('currentTime')
if(stat > 0){
this.ifopen()
}else{
this.videoPlayer.currentTime = 0
}
},
ifopen(){
this.$confirm('是否从上次的记录开始播放?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let stat = sessionStorage.getItem('currentTime')
this.videoPlayer.currentTime = stat
this.videoPlayer.play()
}).catch(() => {
this.videoPlayer.currentTime = 0
this.videoPlayer.pause()
})
},
open(it,id){
sessionStorage.setItem('currentTime',0)
sessionStorage.setItem('duration',0)
this.activeIndex = id
}
}
}
</script>
<style scoped>
.video_box{
margin: 0 auto;
margin-top: 50px;
width: 1450px;
height: 640px;
border: 1px solid #ccc;
background: #000;
}
.video_center{
margin: 20px auto;
width: 1400px;
height: 600px;
background: #3f3f3f;
display: flex;
justify-content: space-between;
}
.video-title{
width: 100%;
display: none;
padding: 1rem;
position: absolute;
top: 0;
color: #fff;
background-color: rgb(6, 6, 6,0.3);
z-index: 2;
}
.resource-container:hover .video-title{
display: block;
}
.video_right > p{
background-color: rgb(6, 6, 6,0.3);
color: #fff;
}
.video-active{
background-color: rgb(6, 6, 6,0.3);
color: aqua;
}
</style>
|