zouyu
2023-11-17 1cf81a64af5bac57f2af8c419db0b22b3d5ba7c8
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!--
  - Copyright (C) 2018-2019
  - All rights reserved, Designed By www.joolun.com
-->
<template>
  <div>
    <div v-if="!outTime"><i class="icon-shipinbofang" style="font-size: 80px!important;" @click="playVideo()"></i><p>点击播放视频</p></div>
    <div v-if="outTime">
      <i class="el-icon-video-play shipin-i"></i><p/>
      <i class="el-icon-time">&nbsp;该视频已过期</i>
    </div>
    <el-dialog
      title="视频播放"
      :visible.sync="dialogVideo"
      width="40%"
      v-loading="mainLoading"
      append-to-body>
      <video-player v-if="playerOptions.sources[0].src"
                    class="video-player vjs-custom-skin"
                    ref="videoPlayer"
                    :playsinline="true"
                    :options="playerOptions"
                    @play="onPlayerPlay($event)"
                    @pause="onPlayerPause($event)"
      >
      </video-player>
    </el-dialog>
  </div>
</template>
 
<script>
  import {videoPlayer} from 'vue-video-player'
  import { getTempMaterialOther, getMaterialOther } from '@/api/mp/wxmaterial'
  require('video.js/dist/video-js.css')
  require('vue-video-player/src/custom-theme.css')
  export default {
    name: "wxVideoPlayer",
    props: {
      objData: {
        type: Object
      }
    },
    components: {
      videoPlayer
    },
    data() {
      return {
        dialogVideo:false,
        outTime: false,
        mainLoading: false,
        playerOptions: {
//        playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
          autoplay: false, //如果true,浏览器准备好时开始回放。
          muted: false, // 默认情况下将会消除任何音频。
          loop: false, // 导致视频一结束就重新开始。
          preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
          language: 'zh-CN',
          aspectRatio: '4:3', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
          fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
          sources: [{
            type: "video/mp4",
            src: "" //你的视频地址(必填)
          }],
          poster: "", //你的封面地址
          width: document.documentElement.clientWidth,
          notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
//        controlBar: {
//          timeDivider: true,
//          durationDisplay: true,
//          remainingTimeDisplay: false,
//          fullscreenToggle: true  //全屏按钮
//        }
        }
      }
    },
    created() {
      this.outTime = this.objData.type === '1' && (parseInt(new Date().getTime() - new Date(this.objData.createTime).getTime()) >= 259200000)
    },
    mounted() {
 
    },
    computed: {},
    methods: {
      playVideo(){
        this.dialogVideo = true
        this.getVideo()
      },
      async getTempMaterialOther(repMediaId, fileName,appId) {
        let url
        this.mainLoading = true
        await getTempMaterialOther({
          appId: appId,
          mediaId: repMediaId,
          fileName: fileName
        }).then(response => {
          this.mainLoading = false
          url = window.URL.createObjectURL(new Blob([response.data]))
        })
        return url
      },
      async getMaterialOther(repMediaId, fileName,appId) {
        let url
        this.mainLoading = true
        await getMaterialOther({
          mediaId: repMediaId,
          fileName: fileName,
          appId: appId
        }).then(response => {
          this.mainLoading = false
          url = window.URL.createObjectURL(new Blob([response.data]))
        })
        return url
      },
      getVideo() {
        if (this.objData.type == '2') {
          this.$set(this.playerOptions.sources[0], 'src', this.objData.repUrl)
        } else if (this.objData.type == '1') {
          this.getTempMaterialOther(this.objData.repMediaId, this.objData.repMediaId + '.mp4')
            .then(val => {
              this.$set(this.playerOptions.sources[0], 'src', val)
            })
        }
      },
      onPlayerPlay(player) {
 
      },
      onPlayerPause(player) {
 
      },
    }
  };
</script>
 
<style lang="scss" scoped>
</style>