<template>
<div class='videomp4' @dblclick="clickFun()">
<video-player class="video-player vjs-custom-skin"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions"
@pause="onPlayerPause($event)"
@play="onPlayerPlay($event)"
@ended="onPlayerEnded($event)"
@timeupdate="onPlayerTimeupdate($event)"
@dblclick="clickFun()"
@canplay="onPlayerCanplay($event)"
>
video-player>
<div class="tilt" @click="onPlayerClick">div>
div>
template>
<script>
export default {
name: "videoPlayerChild",
components:{
},
data() {
return {
poster: '',
isPlay: false,
playerOptions: {
autoplay: false,
muted: false,
loop: false,
playsinline: false,
progressBar: false,
preload: 'auto',
language: 'zh-CN',
aspectRatio: '16:9',
fluid: true,
sources: [{
type: "video/mp4",
src: this.$store.state.drug.video
}],
poster: '',
notSupportedMessage: '此视频暂无法播放,请稍后再试',
controlBar: {
timeDivider: true,
durationDisplay: true,
remainingTimeDisplay: false,
fullscreenToggle: true
}
}
}
},
computed:{
player () { return this.$refs.videoPlayer.player },
playsinline () {
let ua = navigator.userAgent.toLocaleLowerCase()
if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null)
{ return false }
else {
return true
}
}
},
methods: {
onPlayerTimeupdate(player) {
if ("cordova" in window) {
if (player.player_.isFullscreen_ == true) {
screen.orientation.lock('landscape');
} else {
screen.orientation.lock('portrait');
}
}
},
onPlayerCanplay (player) {
var ua = navigator.userAgent.toLocaleLowerCase()
if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
$('body').find('video').attr('x-webkit-airplay', true).attr('x5-playsinline', true).attr('webkit-playsinline', true).attr('playsinline', true)
} else {
$('body').find('video').attr('webkit-playsinline', 'true').attr('playsinline', 'true')
}
},
onUpdateAspectRatio(){
const pin = this.$getViewportSize()
this.playerOptions.aspectRatio =
pin.width+
':' +
pin.height;
},
onPlayerPause($event) {
console.log("暂停了.....")
this.isPlay = false;
},
onPlayerPlay($event) {
console.log("播放了.....")
this.isPlay = true;
},
onPlayerEnded($event) {},
stopVieo(){
console.log("暂停视频")
this.$refs.videoPlayer.player.pause();
this.isPlay = false;
},
onPlayerClick() {
if (this.isPlay) {
this.$refs.videoPlayer.player.pause();
this.isPlay = false;
} else {
this.$refs.videoPlayer.player.play();
this.isPlay = true;
}
},
clickFun(){
var clickid = 1;
var timer = null;
function a() {
console.log('点击');
}
function b() {
console.log('双击');
}
let startTime = new Date().getTime();
if(clickid === 1) {
clickid++;
timer = setTimeout(function () {
a();
clickid = 1;
}, 300)
}
if(clickid === 2) {
clickid ++ ;
} else {
var endTime = new Date().getTime();
if ((endTime - startTime) < 300) {
b();
clickid = 1;
clearTimeout(timer);
}
}
}
},
created() {
this.onUpdateAspectRatio()
},
watch: {
url(val){
console.log("视屏地址")
this.playerOptions.sources[0].src = val;
}
}
}
script>
<style lang="scss" scoped>
.videomp4{
width: 100%;
height: 100%;
margin: 0 auto;
text-align: center;
}
.tilt {
width: 540px;
height: 960px;
opacity: 1;
position: absolute;
top: 480px;
left: 270px;
z-index: 9;
}
.video {
margin: 48px 0;
}
::v-deep .video-js .vjs-control-bar{
height: 140px;
}
.vjs-poster {
background-color: #aaaaaa00;
}
.vjs-custom-skin > .video-js .vjs-big-play-button {
outline: none;
border: none;
width: 66px;
height: 66px !important;
background-color: rgba(0,0,0,0) !important;
}
.video-js .vjs-big-play-button .vjs-icon-placeholder:before {
content: '';
width: 66px;
height: 66px;
background-size: 100% 100%;
}
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-remaining-time{
order:3 !important;
}
::v-deep .vjs-custom-skin > .video-js .vjs-control-bar .vjs-play-control {
margin: 0;
line-height: 20px;
height: 94px;
padding: 50px 0 24px 0;
}
::v-deep .vjs-custom-skin > .video-js .vjs-control-bar .vjs-play-control .vjs-icon-placeholder:before {
position: absolute;
font-size: 20px;
top: 10px;
left: 24px;
width: 20px;
height: 20px;
}
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-time-control {
margin: 0;
line-height: 20px;
height: 94px;
padding: 50px 0 24px 0;
min-width: auto;
}
::v-deep .video-js .vjs-current-time, .vjs-no-flex .vjs-current-time {
display: none;
top: 16px;
left: 72px;
}
video-js .vjs-current-time, .vjs-no-flex .vjs-current-time {
min-width: 32px;
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
line-height: 20px;
margin: 0 0 0 24px !important;
}
::v-deep .vjs-time-divider {
display: none;
line-height: 72px;
top: 4px;
left: 100.8px;
//left: 106.8px;
position: relative;
}
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-time-divider {
min-width: 6px;
margin: 0 8px !important;
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: rgba(255,255,255,0.2);
line-height: 20px;
}
::v-deep .video-js .vjs-duration, .vjs-no-flex .vjs-duration {
display: none;
top: 16px;
left: 120px;
}
.video-js .vjs-duration, .vjs-no-flex .vjs-duration {
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
line-height: 20px;
}
.video-js .vjs-control-bar {
height: 94px;
background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.7) 100%)
}
::v-deep .vjs-custom-skin > .video-js .vjs-progress-control.vjs-control{
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 68px;
width: 100%;
height: 2px;
padding: 0 24px;
}
::v-deep .vjs-custom-skin > .video-js .vjs-play-progress:before {
top: -16px;
}
::v-deep .video-js .vjs-control:focus:before, .video-js .vjs-control:hover:before, .video-js .vjs-control:focus {
text-shadow: 0em 0em 1em rgba(0,0,0,.1);
}
.video-js .vjs-slider{
border-radius: 1em;
background-color: rgba(255,255,255,0.2);
}
.video-js .vjs-load-progress {
background: rgba(255,255,255,0.1);
}
.vjs-custom-skin > .video-js .vjs-play-progress, .vjs-custom-skin > .video-js .vjs-volume-level{
border-radius: 1px;
background: #FFFFFF;
}
.video-js:hover .vjs-big-play-button, .vjs-custom-skin>.video-js .vjs-big-play-button:active, .vjs-custom-skin>.video-js .vjs-big-play-button:focus{
background-color: rgba(0,0,0,0) !important;
}
.video-js .vjs-control-bar{
background-color: rgba(0,0,0,0.2) !important;
}
.video-js .vjs-control-bar button{
outline: none;
}
::v-deep .vjs-volume-panel .vjs-control .vjs-volume-panel-horizontal {
width: 0;
display: none;
}
::v-deep .vjs-custom-skin > .video-js .vjs-control-bar .vjs-playback-rate {
display: none;
}
::v-deep .video-js .vjs-volume-panel {
position: absolute;
right: 96px;
//bottom: 24px;
top: 10px;
width: 20px;
height: 20px;
}
.vjs-icon-volume-high:before, .video-js .vjs-mute-control .vjs-icon-placeholder:before {
font-size: 20px;
width: 20px;
height: 20px;
line-height: 20px;
color: rgba(255,255,255,0.9);
}
.video-js .vjs-volume-bar {
margin: 8px 16px 8px 0;
}
.video-js .vjs-volume-level {
left: -21px;
}
::v-deep .vjs-custom-skin > .video-js .vjs-control-bar .vjs-fullscreen-control {
position: absolute;
right: 48px;
//bottom: 24px;
top:10px;
width: 20px;
height: 20px;
}
.video-js .vjs-big-play-button .vjs-icon-placeholder:before, .vjs-button > .vjs-icon-placeholder:before {
text-align: right;
}
::v-deep .vjs-icon-fullscreen-enter:before, .video-js .vjs-fullscreen-control .vjs-icon-placeholder:before {
content: '';
width: 20px;
height: 20px;
background-size: 100% 100%;
}
.vjs-icon-fullscreen-exit:before, .video-js.vjs-fullscreen .vjs-fullscreen-control .vjs-icon-placeholder:before {
line-height: 20px;
margin-right: 10px;
}
@media screen and ( min-width: 600px) {
::v-deep .video-js .vjs-control-bar{
height: 120px;
}
::v-deep .vjs-custom-skin > .video-js .vjs-control-bar .vjs-play-control .vjs-icon-placeholder:before {
position: absolute;
font-size: 20px;
top: 20px;
left: 24px;
width: 20px;
height: 20px;
}
::v-deep .video-js .vjs-control-bar{
height: 130px;
}
::v-deep .vjs-custom-skin > .video-js .vjs-play-progress:before {
top: -8px;
}
.tilt {
width: 540px;
height: 960px;
opacity: 1;
position: absolute;
top: 20px;
left: 270px;
z-index: 9;
}
}
style>