liuxiaolong
2019-05-06 2418a2d61feea858e9e63aa52fd64ddfe17e392a
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
<template>
<div>
  <div :id="vxgPlayerId" :width="width" :height="height"></div>
</div>
</template>
<script>
export default {
  props: {
    url: {
      default: '',
      type: String
    },
    width: {
      default: '460',
      type: String
    },
    height: {
      default: '320',
      type: String
    }
  },
  computed: {
  },
  data() {
    return {
      vxgPlayer: 'vxgPlayer',
      vxgPlayerId: 'vxgPlayerId',
      videoUrl: ''
    }
  },
  methods: {
    /* eslint-disable */
    vxgplayerInit(optJson) {
      const {
        id = 'vxgPlayer',
        url = '',
        nmf_path = 'media_player.nmf',
        nmf_src = '/static/vxgplayer-1.8.31/pnacl/Release/media_player.nmf',
        latency = '10000',
        width = this.width,
        height = this.height,
        aspect_ratio_mode = 1,
        autohide = 3,
        controls = true,
        connection_timeout = 5000,
        connection_udp = 0,
        custom_digital_zoom = false,
        autostart = false
      } = optJson
      console.log(id,'==============id')
        vxgplayer(
          id,
          {
            ...optJson,
            url: url,
            nmf_path,
            nmf_src,
            latency,
            width,
            height,
            aspect_ratio_mode,
            autohide,
            controls,
            connection_timeout,
            connection_udp,
            custom_digital_zoom
          }
        ).ready(function(data) {
          vxgplayer(id).src(url)
          vxgplayer(id).play()
          /* 播放钩子函数 */
          vxgplayer(id).onStateChange(function(state){
            switch (state) {
                case 0:
                    // PLAYER_STOPPED
                    break
                case 1:
                    // PLAYER_CONNECTING
                    break
                case 2:
                    // PLAYER_PLAYING 成功播放
                    break
                case 3:
                    // PLAYER_STOPPING
                    break
                default:
                    // no ready
            }
            console.log('state', state)
          })
          vxgplayer(id).onError(function(player){
              console.log(player.error(), '播放错误');
          })
        })
    },
    // 获取随机数
    getRandomNum(limit) {
      let num
      while (true) {
        num = Math.random() * 1000
        if (num <= limit && num > 0) {
          break
        }
      }
      return parseInt(num)
    },
    /** 获取播放地址 */
    reciveUrl(data){
      this.videoUrl = 'rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream'
      this.vxgPlayerId = this.vxgPlayerId + new Date().getTime() + ''
      this.$nextTick(() => {
        this.vxgplayerInit({ id: this.vxgPlayerId, url: this.videoUrl, autostart:true })
      })
    }
  },
  mounted() {
    this.reciveUrl({})
  },
  created() {
    
  }
}
</script>
<style>
</style>