video.vue
8.76 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<script lang="ts" setup>
import { isNumber } from 'lodash';
import videoJs, { VideoJsPlayer, VideoJsPlayerOptions } from 'video.js';
import 'video.js/dist/video-js.css';
import { Tooltip } from 'ant-design-vue';
import { computed, CSSProperties, onMounted, onUnmounted, ref, unref } from 'vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { getJwtToken, getShareJwtToken } from '/@/utils/auth';
import { isShareMode } from '/@/views/sys/share/hook';
import 'videojs-flvjs-es6';
import { QuestionCircleOutlined } from '@ant-design/icons-vue';
import {
CaretUpOutlined,
CaretRightOutlined,
PauseOutlined,
CaretDownOutlined,
CaretLeftOutlined,
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons-vue';
import { Button } from 'ant-design-vue';
import { nextTick } from 'vue';
import { controlling } from '/@/api/camera/cameraManager';
const { prefixCls } = useDesign('basic-video-play');
const props = defineProps<{
options?: VideoJsPlayerOptions;
withToken?: boolean;
}>();
const emit = defineEmits<{
(event: 'ready', instance?: Nullable<VideoJsPlayer>): void;
(event: 'onUnmounted'): void;
}>();
const videoPlayEl = ref<HTMLVideoElement>();
const videoPlayInstance = ref<Nullable<VideoJsPlayer>>();
const getOptions = computed(() => {
const { options, withToken } = props;
const defaultOptions: VideoJsPlayerOptions & Recordable = {
language: 'zh',
muted: true,
liveui: true,
controls: true,
techOrder: ['html5', 'flvjs'],
flvjs: {
mediaDataSource: {
isLive: true,
cors: true,
hasAudio: false,
withCredentials: false,
},
config: {
headers: {
...(withToken
? {
'X-Authorization': `Bearer ${isShareMode() ? getShareJwtToken() : getJwtToken()}`,
}
: {}),
},
autoCleanupSourceBuffer: true,
},
},
};
return videoJs.mergeOptions(defaultOptions, options);
});
const getWidthHeight = computed(() => {
let { width = 300, height = 150 } = unref(getOptions);
width = isNumber(width) ? (`${width}px` as unknown as number) : width;
height = isNumber(height) ? (`${height}px` as unknown as number) : height;
return { width, height } as CSSProperties;
});
const init = () => {
if (unref(videoPlayInstance)) unref(videoPlayInstance)?.dispose();
videoPlayInstance.value = videoJs(unref(videoPlayEl)!, unref(getOptions), () => {
emit('ready', unref(videoPlayInstance));
});
};
//播放/暂停
const handleClick = () => {
unref(isPlay) && unref(videoPlayInstance)?.pause();
!unref(isPlay) && unref(videoPlayInstance)?.play();
};
const getId = () => {
const { options } = props || {};
const { sources }: any = options || {};
return sources?.[0]?.id;
};
const handleControl = (action: number, direction: string) => {
const organizationId = getId();
controlling({ cameralndexCode: organizationId, action, command: direction });
};
const isPlay = ref<Boolean | null | undefined>(false);
onMounted(async () => {
init();
await nextTick();
// isPlay.value = unref(videoPlayInstance)?.paused();
videoPlayInstance.value?.on('loadedmetadata', () => {});
videoPlayInstance.value?.on('waiting', () => {
isPlay.value = false;
});
videoPlayInstance.value?.on('play', () => {
isPlay.value = true;
});
videoPlayInstance.value?.on('playing', () => {
isPlay.value = true;
});
videoPlayInstance.value?.on('pause', () => {
isPlay.value = false;
});
videoPlayInstance.value?.on('ended', () => {
isPlay.value = false;
});
});
//长按开始
const moveStart = (action) => {
handleControl(0, action);
};
// 长按结束
const moveStop = (action) => {
handleControl(1, action);
};
onUnmounted(() => {
unref(videoPlayInstance)?.dispose();
videoPlayInstance.value = null;
emit('onUnmounted');
});
defineExpose({
reloadPlayer: init,
getInstance: () => unref(videoPlayInstance),
});
</script>
<template>
<div :class="prefixCls" class="!w-full h-full flex" :style="getWidthHeight">
<video
ref="videoPlayEl"
class="video-js vjs-big-play-centered vjs-show-big-play-button-on-pause !w-8/10 !h-full"
muted
>
</video>
<div class="!w-2/10 bg-white flex items-center flex-col">
<Tooltip>
<template #title
>长按按钮调用API,由于视频流媒体提供的流,有一定时延,请耐心等待。</template
>
<label class="validate-dot">云台控制</label>
<QuestionCircleOutlined :style="{ fontSize: '14px', marginLeft: '5px' }" />
</Tooltip>
<div class="home mt-5">
<Button class="front-sty-center child center" shape="circle" @click="handleClick()">
<PauseOutlined v-if="isPlay" class="child-icon" style="color: #fffbfb" />
<CaretRightOutlined v-else class="child-icon" style="color: #fffbfb" />
</Button>
<div class="box">
<div>
<Button
class="left-top in-block"
@mousedown="moveStart('up')"
@mouseup="moveStop('up')"
>
<CaretUpOutlined class="icon-rotate child-icon" />
</Button>
<Button
class="right-top in-block"
@mousedown="moveStart('RIGHT')"
@mouseup="moveStop('RIGHT')"
>
<CaretRightOutlined class="icon-rotate child-icon" />
</Button>
</div>
<div>
<Button
class="left-bottom in-block"
@mousedown="moveStart('LEFT')"
@mouseup="moveStop('LEFT')"
>
<CaretLeftOutlined class="icon-rotate child-icon" />
</Button>
<Button
class="right-bottom in-block"
@mousedown="moveStart('DOWN')"
@mouseup="moveStop('DOWN')"
>
<CaretDownOutlined class="icon-rotate child-icon" />
</Button>
</div>
<Button class="circle" @click="handleClick" />
</div>
</div>
<div class="flex justify-center mt-8">
<Button
class="button-icon"
@mousedown="moveStart('ZOOM_IN')"
@mouseup="moveStop('ZOOM_IN')"
style="border-radius: :50%;"
>
<ZoomInOutlined style="color: #315a9c; font-size: 1.5rem" />
</Button>
<Button
class="ml-10 button-icon"
@mousedown="moveStart('ZOOM_OUT')"
@mouseup="moveStop('ZOOM_OUT')"
style="border-radius: :50%;"
>
<ZoomOutOutlined style="color: #315a9c; font-size: 1.5rem" />
</Button>
</div>
</div>
</div>
</template>
<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-basic-video-play';
.@{prefix-cls} {
.vjs-error-display {
.vjs-modal-dialog-content::after {
content: '无法加载视频,原因可能是服务器或网络故障,也可能是格式不支持.';
}
}
}
.child {
position: absolute;
width: 3rem;
height: 3rem;
display: flex;
justify-content: center;
background: #e2dede;
align-items: center;
border: none;
}
.child-icon {
font-size: 1.5rem;
color: #fffbfb;
}
.button-icon {
width: 3rem;
height: 3rem;
background: #f5f5f5;
border: none;
border-radius: 50% !important;
}
.center {
top: 50%;
left: 50%;
width: 4rem;
height: 4rem;
transform: translate(-50%, -50%);
border-radius: 50%;
background: #5586d4;
}
.home {
position: relative;
width: 10rem;
height: 10rem;
}
.box {
transform: rotateZ(45deg);
width: 10rem;
height: 10rem;
}
.icon-rotate {
transform: rotate(315deg);
}
.front-sty-center {
position: absolute;
top: 50%;
z-index: 9999;
left: 50%;
transform: translate(-50%, -50%);
}
.circle {
display: inline-block;
border-radius: 50%;
background-color: #5586d4;
width: 4rem;
height: 4rem;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.in-block {
display: inline-block;
position: relative;
}
.left-top {
width: 5rem;
height: 5rem;
border-radius: 5rem 0 0 0;
background-color: #e2dede;
}
.right-top {
width: 5rem;
height: 5rem;
border-radius: 0 5rem 0 0;
background-color: #e2dede;
}
.left-bottom {
width: 5rem;
height: 5rem;
border-radius: 0 0 0 5rem;
background-color: #e2dede;
}
.right-bottom {
width: 5rem;
height: 5rem;
border-radius: 0 0 5rem 0;
background-color: #e2dede;
}
</style>