gjj
2025-02-21 efe41f68868a8926dfc1a6851a492805b56786db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
  <video ref="videoPlayer" class="video-js vjs-big-play-centered" v-bind="$attrs"></video>
</template>
 
<script>
  import videojs from "video.js";
  import "video.js/dist/video-js.min.css";
  import { merge } from "lodash-es";
 
  export default {
    name: "VideoPlayer",
    inheritAttrs: false,
    props: {
      options: {
        type: Object,
        default() {
          return {};
        },
      },
    },
    data() {
      return {
        player: null,
        defaultOptions: {
          autoplay: "play", // false true muted play any
          controls: true,
          loop: false,
          muted: true,
          preload: "auto", // auto metadata none
 
          fluid: false,
          language: "zh-CN",
          notSupportedMessage: "此视频暂无法播放,请稍后再试",
          controlBar: {
            remainingTimeDisplay: true,
            currentTimeDisplay: true,
            timeDivider: true,
            durationDisplay: true,
            progressControl: true,
            customControlSpacer: true,
            fullscreenToggle: true,
            volumePanel: {
              inline: false,
            },
          },
          liveTracker: { trackingThreshold: 5, liveTolerance: 5 },
        },
      };
    },
    computed: {
      finalOptions() {
        return merge({}, this.defaultOptions, this.options);
      },
    },
    mounted() {
      this.init();
    },
    beforeDestroy() {
      this.player?.dispose();
      this.$emit("dispose");
    },
    methods: {
      init() {
        const that = this;
        videojs(this.$refs.videoPlayer, this.finalOptions, function () {
          that.player = this;
          that.$emit("ready", this);
        });
      },
    },
  };
</script>
 
<style lang="scss" scoped>
  ::v-deep .vjs-control-bar {
    background-color: rgba(0, 0, 0, 0.6);
  }
 
  ::v-deep .vjs-slider-horizontal {
    .vjs-volume-level::before {
      top: -4px;
    }
    .vjs-play-progress::before {
      top: -5px;
    }
  }
 
  ::v-deep .vjs-slider-vertical .vjs-volume-level:before {
    left: -4px;
  }
</style>