index.vue
5.99 KB
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
<template>
<div class="extension-page">
<div class="j-player-wrapper">
<vion-player ref="vionPlayer" :watermarkText="params.watermarkText" :hideControls="false" :showPtz="false" :isXCXPage="true" @magnificationChange="magnificationChange"/>
</div>
<!-- 时间线组件 -->
<div class="extension-time-box">
<videoTime ref="videoTime" @videoTimeChange="videoTimeChange" @ptzControlClick="ptzControlClick" :dateFormatType="dateFormatType" :magnification="magnification" :ptzEnable="params.ptzEnable" :gateUnid="params.gateUnid" :appKey="params.appKey"/>
</div>
</div>
</template>
<script>
import { getUrlParams } from './utils';
import vionPlayer from '@/components/vionPlayer';
import videoTime from './videoTime';
import moment from "moment";
import tourApi from '@/api';
var {CryptoJS} = require('./aes')
import {
Toast
} from 'vant';
/**
* 此部分负责:
* 1. iframe通信postmessage
* 2. url获取参数window.location
* 3. 对接小程序需求
*/
export default {
name: 'JPlayerExtension',
components: {
vionPlayer,
videoTime,
},
data() {
return {
isNoBack: true,
datetimeRange: [],
params: {
gateUnid: '',
watermarkText: '',
appKey:'',
ptzEnable:'',
gateName:'',
terminalType:'',
},
panTiltList:{
up:0,
down:1,
left:2,
right:3,
leftUp:4,
leftDown:5,
rightUp:6,
rightDown:7,
zoomExpand:8,
zoomNarrow:9,
focusNear:10,
focusFar:11,
stop:-1
},
nowPanTilt:'',
terminalType:'',
dateFormatType:'YYYY-MM-DD',
magnification:1,
}
},
created() {
this.init();
},
mounted() {
window.playWebVideo = this.playWebVideo;
window.stopPlay = this.stopPlay;
window.screenshot = this.screenshot;
},
methods: {
// 播放倍率改变
magnificationChange(val) {
this.magnification = val
},
// 时间线改变
videoTimeChange(val) {
let valTime = moment(val).format('YYYY-MM-DD HH:mm:ss')
let nowTime = moment().format('YYYY-MM-DD HH:mm:ss')
if(valTime != nowTime){
this.getVideoAddress(valTime,nowTime)
} else {
this.getVideoAddress()
}
},
// 云台控制
ptzControlClick(type) {
console.log(type)
let par = {
direction:this.panTiltList[type],
speed:2,
gateUnid:this.params.gateUnid,
appKey:this.params.appKey,
}
if(type != 'stop') {
this.nowPanTilt = this.panTiltList[type]
} else {
par.direction = this.nowPanTilt
}
// 加密
let parStr = this.aesEncrypt(par)
if(type == 'stop') {
tourApi.ptzStop({param:parStr}).then(res => {
console.log(res)
})
} else {
tourApi.ptzStart({param:parStr}).then(res => {
console.log(res)
if(res.data&&res.data.code != 200) {
Toast.fail('云台当前操作失败');
}
})
}
},
init() {
// 通过URL获取相关参数
const urlParamsMap = getUrlParams(window.location.hash);
console.log('urlParamsMap', urlParamsMap);
Object.keys(this.params).forEach(key => {
if (urlParamsMap[key]) {
this.params[key] = urlParamsMap[key];
}
});
// this.params = obj
console.log(this.params)
//利用iframe的onload事件刷新页面
document.title = this.params.gateName||'视频详情'
var iframe = document.createElement('iframe');
iframe.style.visibility = 'hidden';
iframe.style.width = '1px';
iframe.style.height = '1px';
iframe.onload = function () {
setTimeout(function () {
document.body.removeChild(iframe);
}, 0);
};
document.body.appendChild(iframe);
this.params.ptzEnable = ''+this.params.ptzEnable
this.terminalType = this.params.terminalType
this.dateFormatType = this.terminalType == 'ios'||this.terminalType == 'mac' ? 'YYYY/MM/DD':'YYYY-MM-DD';
if(this.params.gateUnid) {
this.getVideoAddress()
}
},
playWebVideo(obj) {
// // 通过URL获取相关参数
// const urlParamsMap = getUrlParams(window.location.hash);
// console.log('urlParamsMap', urlParamsMap);
// Object.keys(this.params).forEach(key => {
// if (urlParamsMap[key]) {
// this.params[key] = urlParamsMap[key];
// }
// });
this.params = obj
this.getVideoAddress()
},
// 获取视频播放地址
getVideoAddress(startTime,stopTime) {
let par = {
gateUnid: this.params.gateUnid,
// appKey: this.params.appKey,
// playbackSpeed: 1,
startTime:startTime?startTime:null,
stopTime:stopTime?stopTime:null,
}
// 加密
// let parStr = this.aesEncrypt(par)
tourApi.getLiveAndPlaybackAddress(par).then(res => {
if (res.data&&res.data.code == 200) {
this.$refs.vionPlayer.play(res.data.msg);
} else {
Toast.fail('取流失败');
}
})
/* let par = {
gateUnid: this.params.gateUnid,
appKey: this.params.appKey,
playbackSpeed: 1,
startTime:startTime?startTime:null,
stopTime:stopTime?stopTime:null,
}
// 加密
let parStr = this.aesEncrypt(par)
tourApi.getThroughVideoUrl({param:parStr}).then(res => {
if (res.data&&res.data.code == 200) {
this.$refs.vionPlayer.play(res.data.msg);
} else {
Toast.fail('取流失败');
}
}) */
},
//加密
aesEncrypt (obj){
let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(JSON.stringify(obj)), CryptoJS.enc.Utf8.parse('0123456789abcdef'), {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}).toString();
return encrypted
},
// 暴露方法
// 截图方法
screenshot() {
this.$refs.vionPlayer.screenshot().then(data => {
console.log(data)
wx.miniProgram.postMessage({ data:{src:data} })
// Toast.success('截图成功');
}).catch(err => {
})
},
// 关闭视频播放
stopPlay() {
this.$refs.vionPlayer.destroy();
},
},
}
</script>
<style lang="scss" scoped>
.j-player-wrapper {
width: 100vw;
height: 56vw;
overflow: hidden;
position: relative;
z-index: 1;
}
.screen-shot-img{
position: absolute;
right:53px;
bottom: 10px;
width: 16px;
height: 16px;
z-index: 1000;
}
</style>