video-player.vue 1.84 KB
<template>
  <div class="video-player">
    <video
      ref="videoPlayer"
      class="video-js vjs-matrix vjs-yoho"
      :poster="coverImg"
      controls
      preload="auto"
      playsinline
      x5-playsinline
      webkit-playsinline="true">
      <source :src="source" type="video/mp4"></source>
      <p class="vjs-no-js">
        To view this video please enable JavaScript, and consider upgrading to a
        web browser
      </p>
    </video>
  </div>
</template>

<script>
import videojs from 'video.js';

export default {
  name: 'VideoPlayer',
  props: {
    source: String,
    cover: String,
    options: {
      type: Object,
      default() {
        return {
          muted: true,
          controls: true,
          aspectRatio: '1:1'
        };
      }
    }
  },
  data() {
    return {
      player: null
    };
  },
  computed: {
    coverImg() {
      if (this.cover) {
        return this.cover.split('?')[0];
      } else {
        return '';
      }
    },
  },
  mounted() {
    this.player = videojs(this.$refs.videoPlayer, this.options);
  },
  beforeDestroy() {
    if (this.player) {
      this.player.dispose();
    }
  }
};
</script>

<style lang="scss" scoped>
  .video-js {
    width: 100%;
    height: auto;

    video {
      width: 100%;
    }

    &.vjs-yoho /deep/ {
      .vjs-big-play-button {
        width: 120px;
        height: 120px;
        line-height: 120px;
        font-size: 60px;
        border-radius: 50%;
        left: 50%;
        top: 50%;
        margin: -60px auto auto -60px;
      }

      .vjs-control-bar {
        height: 60px;
        font-size: 26px;

        .vjs-control {
          width: 80px;
        }

        .vjs-time-control {
          line-height: 60px;
        }

        .vjs-icon-placeholder:before {
          font-size: 38px;
          line-height: 60px;
        }
      }
    }
  }
</style>