<template>
<view v-if="videoShow" class="video-contain">
<u-popup
v-model="value"
mode="center"
:mask="true"
width="100%"
height="100%"
class="popups"
>
<view class="body-video">
<view
:class="{ 'video-js': isFullscreen, 'video-small': !isFullscreen }"
ref="video"
>
</view>
<view class="pause" v-if="isEnd" @click="replay">
<image
src="/static/base-module/common/replay.png"
class="pause-icon"
mode=""
/>
</view>
<view class="video-mask" @click="showBtn"></view>
<view class="close-video" @click="close">
<image
src="/static/base-module/common/close-video.png"
class="close-icon"
/>
</view>
<view class="pause" v-if="isPlay && isShowBtn" @click="pause">
<image
src="/static/base-module/common/pause.png"
class="pause-icon"
/>
</view>
<view class="pause" v-if="!isPlay && isShowBtn" @click="play">
<image src="/static/base-module/common/play.png" class="pause-icon" />
</view>
<view class="volume-control">
<view class="volume" v-if="muted">
<u-slider
v-model="slideVolume"
:use-slot="true"
@slideClick="slideClick"
class="video-slider"
inactive-color="#6E6E6E"
active-color="#FFFFFF"
height="2.2"
@end="volumeStart"
>
<template>
<view class="volume-cicle"> </view>
</template>
</u-slider>
</view>
<view class="icon">
<image
src="/static/base-module/common/volum.png"
class="volum"
v-if="muted"
@click="volum"
/>
<image
src="/static/base-module/common/close-volum.png"
class="volum"
v-if="!muted"
@click="volum"
/>
</view>
</view>
<view class="bottom">
<view class="time">
<view class="currentTime">{{ currentTime }}</view>
<view class="spet">/</view>
<view class="duration">{{ duration }}</view>
</view>
<view class="progressWrap">
<u-slider
v-model="slide"
class="video-slider"
:use-slot="true"
inactive-color="#6E6E6E"
active-color="#FFFFFF"
height="2.2"
@slideClick="slideVideo"
@end="sliderStart"
>
<template>
<view class="cicle"> </view>
</template>
</u-slider>
</view>
<view class="full">
<image
src="/static/base-module/common/scale1.png"
v-if="!isFullscreen"
class="scale"
@click="fullscreen"
/>
<image
src="/static/base-module/common/scale.png"
v-if="isFullscreen"
class="scale"
@click="fullscreen"
/>
</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
export default {
props: {
videoShow: {
type: Boolean,
default: false,
},
source: {
type: String,
default: "",
},
poster: {
type: String,
default: "",
},
type: {
type: String,
default: "video/mp4",
},
title: {
type: String,
default: "",
},
},
data() {
return {
player: null,
value: false,
isEnd: false,
isFullscreen: false,
isPlay: false,
isShowBtn: false,
duration: 0,
currentTime: 0,
muted: false,
playWidth: 0,
volume: 100,
slide: 0,
slideVolume: 100,
};
},
mounted() {},
watch: {
videoShow(n) {
this.value = n;
console.log(n);
},
value(n) {
if (!n) {
this.$emit("close");
this.destroyVideo();
}
},
},
methods: {
fullscreen() {
this.isFullscreen = !this.isFullscreen;
},
showBtn() {
this.isShowBtn = true;
setTimeout(() => {
if (this.isPlay) {
this.isShowBtn = false;
}
}, 3000);
},
volum() {
var video = document.getElementById("video").children[0];
this.muted = !this.muted;
if (this.muted) {
video.volume = 1;
this.slideVolume = 100
} else {
video.volume = 0;
this.slideVolume = 0
}
},
volumeStart() {
var video = document.getElementById("video").children[0];
var num = this.slideVolume/100;
video.volume = num;
if(video.volume===0){
this.muted = false
}
},
getInit() {
var progressFlag;
let video = document.createElement("video");
video.id = "video";
video.style =
"width: 100%; height: 100%;background: #000000;padding-top:0";
video.controls = true;
video.setAttribute("class", "vjs-big-play-centered");
video.setAttribute("playsinline", true);
video.setAttribute("webkit-playsinline", true);
video.setAttribute("x5-video-player-type", "h5");
let source = document.createElement("source");
source.src = this.source;
source.type = this.type;
video.appendChild(source);
this.$refs.video.$el.appendChild(video);
let that = this;
that.player = videojs(
"video",
{
poster: that.poster,
title: that.title,
autoDisable: true,
preload: "none",
language: "zh-CN",
fluid: true,
muted: true,
aspectRatio: "16:9",
controls: false,
autoplay: true,
loop: false,
screenshot: true,
controlBar: false,
currentTime: 0,
duration: 0,
},
function () {
this.on("error", function () {
that.$emit("error");
});
this.on("stalled", function () {
console.log("网速失速");
that.$emit("stalled");
});
this.on("play", function () {
that.isPlay = true;
that.isEnd = false;
that.$emit("play");
});
this.on("pause", function () {
console.log("暂停");
that.isPlay = false;
that.$emit("pause");
});
this.on("timeupdate", function () {
that.duration = that.formateSeconds(this.duration());
that.currentTime = that.formateSeconds(this.currentTime());
var percent = (this.currentTime() / this.duration()) * 100;
that.slide = percent;
that.$emit("timeupdate");
});
this.on("ended", function () {
that.isEnd = true;
that.isPlay = false;
that.isFullscreen = false;
that.$emit("ended");
});
}
);
},
sliderStart() {
var time = this.slide / 100;
var video = document.getElementById("video").children[0];
var total = video.duration;
video.currentTime = time * total;
},
slideVideo(){
var time = this.slide / 100;
var video = document.getElementById("video").children[0];
var total = video.duration;
video.currentTime = time * total;
},
slideClick(){
var video = document.getElementById("video").children[0];
var num = this.slideVolume/100;
video.volume = num;
if(video.volume===0){
this.muted = false
}
},
destroyVideo() {
if (this.player != null) {
this.player.dispose();
this.player = null;
}
},
close() {
if (this.player != null) {
this.player.dispose();
this.player = null;
}
this.$emit("close");
},
replay() {
this.play();
},
play() {
let that = this;
this.player.ready(function () {
that.player.play();
if (that.isShowBtn) {
setTimeout(() => {
that.isShowBtn = false;
}, 3000);
}
});
},
pause() {
let that = this;
this.player.ready(function () {
that.player.pause();
});
},
formateSeconds(endTime) {
let secondTime = parseInt(endTime);
let min = 0;
let h = 0;
let result = "";
if (secondTime > 60) {
min = parseInt(secondTime / 60);
secondTime = parseInt(secondTime % 60);
if (min > 60) {
h = parseInt(min / 60);
min = parseInt(min % 60);
}
}
result = `${min
.toString()
.padStart(2, "0")}:${secondTime.toString().padStart(2, "0")}`;
return result;
},
},
};
</script>
<style lang="scss" scoped>
.body-video {
width: 100%;
height: 100%;
background: #000000;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.video-js {
width: 100%;
height: calc(100% - 106rpx);
background: #000000;
}
.video-small {
width: calc(100% - 204rpx);
height: calc(100% - 219rpx);
background: #000000;
}
.video-mask {
width: 100%;
height: calc(100% - 106rpx);
position: absolute;
top: 53rpx;
z-index: 99;
}
.auto-speed {
position: absolute;
width: rpx(172);
height: rpx(172);
left: 50%;
top: 50%;
margin-left: rpx(-86);
margin-top: rpx(-86);
z-index: 999999999;
}
.close-video {
width: rpx(90);
height: rpx(90);
background: rgba(51, 51, 51, 0.8);
border-radius: rpx(20);
position: absolute;
left: rpx(60);
top: rpx(55);
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
.close-icon {
width: rpx(60);
height: rpx(60);
}
}
.pause {
width: rpx(172);
height: rpx(172);
left: 50%;
top: 50%;
position: absolute;
margin-left: rpx(-86);
margin-top: rpx(-86);
z-index: 999;
.pause-icon {
width: rpx(172);
height: rpx(172);
}
}
.bottom {
width: 100%;
position: absolute;
height: rpx(192);
bottom: 0;
z-index: 9999;
left: 0;
right: 0;
display: flex;
align-items: center;
.time {
display: flex;
align-items: center;
font-size: rpx(32);
font-family: HelveticaNeue;
color: rgba(255, 255, 255, 1);
margin-left: rpx(60);
.currentTime {
color: rgba(255, 255, 255, 1);
}
.spet {
color: rgba(136, 136, 136, 1);
margin-left: 4px;
}
.duration {
color: rgba(136, 136, 136, 1);
margin-left: 4px;
}
}
}
.progressWrap {
border-radius: rpx(6);
height: rpx(8);
cursor: pointer;
margin-left: rpx(30);
display: flex;
align-items: center;
flex: 1;
}
.cicle {
width: 10px;
height: 10px;
border-radius: 50%;
background: rgba(255, 255, 255, 1);
}
#playProgress {
background: rgba(217, 217, 217, 1);
width: 0px;
height: rpx(8);
}
.full {
width: rpx(60);
height: rpx(60);
display: flex;
align-items: center;
margin-right: rpx(61);
margin-left: rpx(60);
.scale {
width: rpx(60);
height: rpx(60);
}
}
.volume-control {
position: absolute;
top: rpx(55);
right: rpx(75);
height: rpx(90);
background: rgba(51, 51, 51, 0.8);
border-radius: rpx(20);
display: flex;
align-items: center;
.volume {
width: rpx(358);
height: rpx(8);
background: rgba(110, 110, 110, 1);
border-radius: rpx(4);
display: flex;
align-items: center;
margin-left: rpx(50);
margin-right: rpx(50);
display: flex;
align-items: center;
.volume-muted {
height: rpx(8);
background: rgba(217, 217, 217, 1);
border-radius: rpx(4);
}
.volume-cicle {
width: 10px;
height: 10px;
border-radius: 50%;
background: rgba(255, 255, 255, 1);
}
}
}
.volum {
width: rpx(60);
display: flex;
margin-left: rpx(15);
align-items: center;
margin-right: rpx(15);
height: rpx(60);
.volum-icon {
width: rpx(60);
height: rpx(60);
}
}
.video-slider {
width: 100%;
height: rpx(8);
}
</style>