<template>
<div class="v_coBox" @mouseover="moveIn=true" @mouseleave="moveIn=false">
<video class="pvideo" preload oncanplay @click="play" ref="vPlay" :src="vUrl" webkit-playsinline playsinline></video>
<div class="stopvBox" @click="play" v-if="showPause">
<img class="spImg" src="../images/pVideo.png" alt="">
</div>
</div>
</template>
<script>
export default {
name:'videoPlay',
data(){
return{
showPause:true,
moveIn:false,
allTime:0,
proTime:'00:00',
percentage:0
}
},
props:{
vUrl:''
},
methods:{
play(){
const video = this.$refs.vPlay;
video.webkitRequestFullScreen();
if(video.paused){
video.play();
this.showPause = false;
}else{
video.pause();
this.showPause = true;
};
},
timeStamp(second_time){
var time1 = ((parseInt(second_time)/100)).toString();
var time2 = time1.split(".")[1]? (time1.split(".")[1].length == 1 ? time1.split(".")[1]+'0' : time1.split(".")[1]) :'00';
var time = '00' + ':' + time2;
if( parseInt(second_time )>= 60){
var second = ((parseInt(second_time) % 60)/100).toString();
var min = (parseInt(second_time / 60)/100).toString();
var time3 = second.split(".")[1]? (second.split(".")[1].length == 1 ? second.split(".")[1]+'0' : second.split(".")[1]) :'00';
var time4 = min.split(".")[1]? (min.split(".")[1].length == 1 ? min.split(".")[1]+'0' : min.split(".")[1]) :'00';
time = time4 + ":" + time3;
};
return time;
},
changeTime(e){
const wTh = this.$refs.wTh;
const video = this.$refs.vPlay;
e.stopPropagation();
e = e || window.event
const time = e.offsetX/wTh.offsetWidth*video.duration;
this.percentage = e.offsetX;
video.currentTime = time;
},
fullPageVideo(){
const video = this.$refs.vPlay;
video.webkitRequestFullScreen();
}
},
mounted(){
this.$nextTick(()=>{
const video = this.$refs.vPlay;
video.addEventListener('ended',()=>{
this.showPause = true;
});
video.addEventListener('loadedmetadata',()=>{
let time = video.duration;
this.allTime = this.timeStamp(time);
});
video.addEventListener('timeupdate',()=>{
try{
const wTh = this.$refs.wTh.offsetWidth;
let time = video.currentTime,alltime = video.duration;
let percentage = (time / alltime) * wTh;
this.proTime = this.timeStamp(time);
this.percentage = percentage;
}catch(e){}
});
})
}
}
</script>
<style>
.v_coBox{
position: relative;
width: 100%;
height: 100%;
}
.v_coBox .pvideo{
width:100%;
height: 100%;
background-color: #000;
}
.v_coBox .stopvBox{
position: absolute;
top: 0;
left: 0;
width:100%;
cursor: pointer;
height: 100%;
background-color: rgba(0,0,0,.4);
}
.v_coBox .stopvBox>.spImg{
position:absolute;
top:50%;
left:50%;
transform: translateX(-50%) translateY(-50%);
color:#fff;
text-align: center;
font-size:1rem;
cursor:pointer;
width: 1rem!important;
height: 1rem!important;
}
.v_coBox .biggerBtn{
position: absolute;
font-size: 1rem;
bottom:0;
left:0;
width: 100%;
color: #fff;
padding: 0 6px;
box-sizing: border-box;
}
.v_coBox .biggerBtn .allTime{
position: absolute;
right: 28px;
top: 0;
}
.v_coBox .biggerBtn .fullPage{
position: absolute;
right: 6px;
top: -3px;
}
.v_coBox .biggerBtn .fullPage>img{
display: inline-block;
width: 14px;
vertical-align: middle;
margin-top: 3px;
cursor: pointer;
}
.v_coBox .biggerBtn .proBar{
display: inline-block;
height: 2px;
margin-left: 10px;
width: 60%;
background-color: rgba(255,255,255,.3);
border-radius: 2px;
position: relative;
vertical-align: middle;
margin-bottom: 3px;
cursor:pointer;
}
.v_coBox .biggerBtn .proBar b{
display: inline-block;
height: 2px;
background-color: #008CEE;
position: absolute;
top: 0;
left: 0;
}
.v_coBox .biggerBtn .proBar .proOption{
position: absolute;
top: -4px;
left: 0;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #fff;
}
</style>