13693261870
2023-06-21 cdf12fc9e88b1af69f5c85165eb9fef4e23bf57a
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<template>
  <div class="box">
    <div class="header">
      <div class="title1">视频播放区</div>
    </div>
    <div class="content">
      <div class="videoContent">
        <Video id="v_video"
               style="height: 100%; width: 100%; object-fit: fill;"
               autoplay="autoplay"
               preload="auto"
               controls="controls"
               muted="muted"></Video>
      </div>
      <div>
        <div class="subtract"></div>
        <div class="positionContent">{{ this.$store.state.videoName }}</div>
      </div>
    </div>
  </div>
</template>
 
<script>
import { channelIdList } from '../../../utils/api.js'
//
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data () {
    // 这里存放数据
    return {
      falg: 0,
      timer: null,
      lastId: null,
      flvPlayer: null,
      featureLayer: null
    }
  },
  // 方法集合
  methods: {
    // 停止
    stop () {
      this.$store.state.showVideoFlag = false
      //this.resetImg()
      //this.clsTimer()
      this.clsPlayer()
    },
    // 播放 *
    start (index) {
      if (!flvjs.isSupported()) {
        alert('当前浏览器不支持flvjs播放Flv视频!')
        return
      }
 
      var that = this, i = index
      var count = this.$store.state.data.length
      this.stop()
      this.playByIndex(i)
 
      this.timer = setInterval(function () {
        if (++i >= count) i = 0
 
        that.resetImg()
        that.clsPlayer()
        that.playByIndex(i)
      }, PLAY_TIMER)
    },
    // 重置图片
    resetImg: function () {
      if (this.lastId != null) {
        this.$store.commit('changeImg', { idx: this.lastId, flag: false })
        this.lastId = null
      }
    },
    // 清除定时器 *
    clsTimer () {
      if (this.timer != null) {
        clearInterval(this.timer)
        this.timer = null
      }
    },
    // 清除播放器
    clsPlayer () {
      if (this.flvPlayer != null) {
        this.flvPlayer.destroy()
        this.flvPlayer = null
      }
    },
    // 根据索引播放 *
    async playByIndex (i) {
      if (i == null || i < 0 || i > this.$store.state.data.length) return
 
      console.log('i => ', i)
      this.lastId = i
      var data = this.$store.state.data[i]
      this.$store.commit('changeImg', { idx: i, flag: true })
      // if (this.$store.state.videoName != '荣华路') {
      //   this.flyTo(data)
      // } else {
      // }
      var rs = await channelIdList(data.channelId)
      if (!rs || rs.status != 200 || !rs.data.data.length) return
      this.play(rs.data.data[0])
    },
    // 播放视频
    play (d) {
      var url = this.getVideoUrl(d)
      console.log('play.videoUrl =>', url)
      var videoElement = document.getElementById('v_video')
      this.flvPlayer = flvjs.createPlayer({
        type: 'flv',
        url: url
      })
      this.flvPlayer.attachMediaElement(videoElement)
      this.flvPlayer.load()
      this.flvPlayer.play()
    },
    // 获取视频Url
    getVideoUrl (d) {
      if (IS_TEST) return XI_GA_FLV;
 
      return (
        //(location.href.indexOf(API_HOST) > -1 ? '' : `http://${d.streamServerIp}:${d.streamServerPort}`) +
        (location.href.indexOf(API_HOST) > -1 ? '' : VIDEO_HOST) +
        `/play.flv?${d.accessWay}:${d.user}:${d.password}@${d.deviceIp}:${d.devicePort}:${d.channelNum}:1`
      ) // ${d.streamNum}
    },
    // 飞向 *
    flyTo (data) {
      var x = parseFloat(data.longitude)
      var y = parseFloat(data.latitude)
      if (x == 0 || y == 0) return
 
      var p = this.$store.state.transform(x, y)
      map.flyTo(p.x, p.y, 500, 0, -6, 0, 20000, null, 6) // -42, -27
    },
    // 开始漫游
    startManYou () {
      if (this.$store.state.videoId == null) return;
      var resid = this.$store.state.videoId;
 
      var data = this.$store.state.data;
      var pointer = this.getVideoPoint(data);
      var wander = this.getroamheight(resid);
 
      let params = {
        id: resid, //漫游线路的ID,现在只有1
        data: pointer, //点位和点位ID
        Rate: 1, //漫游速度,1是正常速度,全程60秒
        StopTime: STOP_TIME, //每个点位停止时间
        Range: wander.d, //距离点位多少停止漫游,单位厘米
        time: 2, //切换时间
        CameraHeight: wander.h, //漫游相机高度
        pitch: -6 //-60 //相机俯仰角
      }
 
      var that = this;
      map.execute('grapi', 'TurnOnLineRoaming', params, function (e) {
        console.log("TurnOnLineRoaming.id =>", e, e.args.id);
        if (e && e.args && e.args.id) {
          that.showVideo(e.args.id);
          that.changeImage(e.args.id);
        }
      });
    },
    // 获取漫游高度
    getroamheight (val) {
      switch (val) {
        case 1://'荣华路'
          return { h: 3000, d: 30000 }
        case 2:// '荣京东街'
          return { h: 2000, d: 30000 }
        case 3://'大族广场'
          return { h: 1000, d: 30000 }
        case 4://'博大公园'
          return { h: 1500, d: 25000 }
        case 5://'区域全景'
          return { h: 1000, d: 25000 }
        case 6://'高点摄像头'
          return { h: 3000, d: 30000 }
      }
    },
    // 切换图片
    changeImage (id) {
      var data = this.$store.state.data
      for (var i in data) {
        if (data[i].channelId == id) {
          this.$store.commit('changeVideo', i);
          break;
        }
      }
    },
    // 展示视频
    async showVideo (id) {
      this.clsPlayer();
      var rs = await channelIdList(id);
      console.log("showVideo =>", id, rs);
      if (!rs || rs.status != 200 || !rs.data.data.length) return;
 
      this.play(rs.data.data[0]);
    },
    // 获取视频点
    getVideoPoint (res) {
      var points = [];
      for (let i = 0; i < res.length; i++) {
        var p = this.$store.state.transform(res[i].longitude, res[i].latitude);
        points.push({
          Location: new TUVector3(p.x, p.y, 100),
          PointID: res[i].channelId
        });
      }
      return points;
    }
  },
  created () {
    this.$bus.$on('stopPlay', () => {
      this.stop()
    })
    this.$bus.$on('playVideo', (index) => {
      this.clsPlayer();
      this.startManYou();
    })
    this.$bus.$on('manYouVideo', (e) => {
      if (e && e.JsonNews && e.JsonNews.channelId) {
        console.log("manYouVideo.id =>", e.JsonNews.channelId);
        this.clsPlayer();
        this.showVideo(id);
      }
    })
    this.$bus.$on('manPoiVideo', (e) => {
      if (e && e.channelId) {
        console.log("manPoiVideo.id =>", e.channelId);
        this.clsPlayer();
        this.showVideo(e.channelId);
      }
    })
  },
  mounted () {
    this.showVideo(VIDEO_ID);
  }
}
</script>
<style lang="less" scoped>
//@import url(); 引入公共css类
.box {
  // display: flex;
  width: 100%;
  height: 100%;
  position: absolute;
 
  font-style: normal;
  font-weight: 500;
 
  .header {
    width: 100%;
    height: 75px;
    background: url('../../../assets/img/FoucesVideoHeader.png') no-repeat
      center;
    background-size: 100% 100%;
    position: absolute;
 
    .title1 {
      line-height: 75px;
      margin-left: 23.57px;
      position: absolute;
      float: left;
      font-size: 32px;
      color: white;
      font-family: SourceHanSansCN;
    }
  }
  .content {
    width: 100%;
    height: 612px;
    background: url('../../../assets/img/Rectangle 894.png') no-repeat center;
    background-size: 100% 100%;
 
    position: absolute;
    .videoContent {
      width: 100%;
      height: 460px;
      top: 75px;
      position: absolute;
    }
    .subtract {
      width: 31.11px;
      height: 37.78px;
      background: url('../../../assets/img/Subtract.png') no-repeat center;
      background-size: 100% 100%;
      left: 32px;
      bottom: 22px;
      position: absolute;
    }
    .positionContent {
      font-size: 32px;
      color: white;
      color: white;
      left: 72px;
      bottom: 22px;
      position: absolute;
      font-family: SourceHanSansCNRegular;
    }
  }
}
</style>