|
|
<template>
|
|
|
<div class="video-player">
|
|
|
<div class="video-player" :style="videoStyle">
|
|
|
<video
|
|
|
ref="videoPlayer"
|
|
|
class="video-js vjs-matrix vjs-yoho"
|
...
|
...
|
@@ -20,13 +20,17 @@ |
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import {get} from 'lodash';
|
|
|
import videojs from 'video.js';
|
|
|
import {getArticleImageSize, processImage} from 'utils/image-handler';
|
|
|
|
|
|
export default {
|
|
|
name: 'VideoPlayer',
|
|
|
props: {
|
|
|
source: String,
|
|
|
cover: String,
|
|
|
width: [Number, String],
|
|
|
height: [Number, String],
|
|
|
options: {
|
|
|
type: Object,
|
|
|
default() {
|
...
|
...
|
@@ -40,20 +44,38 @@ export default { |
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
player: null
|
|
|
player: null,
|
|
|
loaded: false
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
coverImg() {
|
|
|
if (this.cover) {
|
|
|
return this.cover.split('?')[0];
|
|
|
if (this.width && this.height) {
|
|
|
let imgSize = getArticleImageSize({
|
|
|
width: this.width,
|
|
|
height: this.height,
|
|
|
minScale: 0,
|
|
|
maxWidth: 500
|
|
|
});
|
|
|
|
|
|
return processImage(this.cover, 2, imgSize.width, imgSize.height, get(this.yoho, 'window.supportWebp'));
|
|
|
} else {
|
|
|
return this.cover.split('?')[0];
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
return '';
|
|
|
}
|
|
|
},
|
|
|
videoStyle() {
|
|
|
return {visibility: this.loaded ? 'visible' : 'hidden'};
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
this.player = videojs(this.$refs.videoPlayer, this.options);
|
|
|
this.player = videojs(this.$refs.videoPlayer, this.options, () => {
|
|
|
this.loaded = true;
|
|
|
});
|
|
|
|
|
|
this.voiceBtn = this.player.addChild('button');
|
|
|
this.voiceBtn.addClass('vjs-yoho-voice');
|
...
|
...
|
@@ -131,6 +153,24 @@ export default { |
|
|
}
|
|
|
}
|
|
|
|
|
|
.vjs-loading-spinner {
|
|
|
width: 120px;
|
|
|
height: 120px;
|
|
|
margin-top: -60px;
|
|
|
margin-left: -60px;
|
|
|
border: none;
|
|
|
background: url("~statics/image/components/video-loading-icon.png");
|
|
|
background-size: contain;
|
|
|
background-repeat: no-repeat;
|
|
|
background-position: center center;
|
|
|
|
|
|
&:before,
|
|
|
&:after,
|
|
|
> * {
|
|
|
display: none;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
.vjs-control-bar {
|
|
|
height: 80px;
|
|
|
opacity: 1 !important;
|
...
|
...
|
|