1
|
<script setup lang="ts">
|
1
|
<script setup lang="ts">
|
|
|
2
|
+import { Spin } from 'ant-design-vue'
|
2
|
import { computed, nextTick, onMounted, onUnmounted, ref, toRaw, unref } from 'vue'
|
3
|
import { computed, nextTick, onMounted, onUnmounted, ref, toRaw, unref } from 'vue'
|
3
|
import 'video.js/dist/video-js.css'
|
4
|
import 'video.js/dist/video-js.css'
|
4
|
|
5
|
|
|
@@ -21,6 +22,7 @@ const props = defineProps<{ |
|
@@ -21,6 +22,7 @@ const props = defineProps<{ |
21
|
// 获取节点数据
|
22
|
// 获取节点数据
|
22
|
const contentDataStore = useContentDataStore()
|
23
|
const contentDataStore = useContentDataStore()
|
23
|
const { getResult } = useFingerprint()
|
24
|
const { getResult } = useFingerprint()
|
|
|
25
|
+const loading = ref(false)
|
24
|
|
26
|
|
25
|
const getOptions = computed<VideoJsPlayerOptions>(() => {
|
27
|
const getOptions = computed<VideoJsPlayerOptions>(() => {
|
26
|
const { config } = props || {}
|
28
|
const { config } = props || {}
|
|
@@ -47,53 +49,58 @@ const playSource = ref<Record<'src' | 'type', string>>( |
|
@@ -47,53 +49,58 @@ const playSource = ref<Record<'src' | 'type', string>>( |
47
|
|
49
|
|
48
|
// 数据绑定获取的url
|
50
|
// 数据绑定获取的url
|
49
|
const handleGetVideoPlay = async () => {
|
51
|
const handleGetVideoPlay = async () => {
|
50
|
- const { dataSourceJson } = unref(videoConfig)[0] || {}
|
|
|
51
|
- const { videoOption } = dataSourceJson || {}
|
|
|
52
|
- const { id, accessMode, videoUrl, deviceId, channelId } = videoOption || {}
|
|
|
53
|
- let type = getVideoTypeByUrl(videoUrl!)
|
|
|
54
|
- let playUrl = videoUrl
|
|
|
55
|
-
|
|
|
56
|
- // 判断是否是流媒体播放
|
|
|
57
|
- if (accessMode === VideoAccessModeEnum.Streaming && id) {
|
|
|
58
|
- const { data: { url } = { url: '' } } = await getStreamingPlayUrl(id!)
|
|
|
59
|
- playUrl = url
|
|
|
60
|
- playUrl && (type = getVideoTypeByUrl(playUrl!))
|
|
|
61
|
- }
|
|
|
62
|
- else if (accessMode === VideoAccessModeEnum.GBT28181 && deviceId && channelId) {
|
|
|
63
|
- const {
|
|
|
64
|
- data: { flv },
|
|
|
65
|
- } = await getVideoControlStart({ channelId, deviceId })
|
52
|
+ try {
|
|
|
53
|
+ loading.value = true
|
|
|
54
|
+ const { dataSourceJson } = unref(videoConfig)[0] || {}
|
|
|
55
|
+ const { videoOption } = dataSourceJson || {}
|
|
|
56
|
+ const { id, accessMode, videoUrl, deviceId, channelId } = videoOption || {}
|
|
|
57
|
+ let type = getVideoTypeByUrl(videoUrl!)
|
|
|
58
|
+ let playUrl = videoUrl
|
|
|
59
|
+ // 判断是否是流媒体播放
|
|
|
60
|
+ if (accessMode === VideoAccessModeEnum.Streaming && id) {
|
|
|
61
|
+ const { data: { url } = { url: '' } } = await getStreamingPlayUrl(id!)
|
|
|
62
|
+ playUrl = url
|
|
|
63
|
+ playUrl && (type = getVideoTypeByUrl(playUrl!))
|
|
|
64
|
+ }
|
|
|
65
|
+ else if (accessMode === VideoAccessModeEnum.GBT28181 && deviceId && channelId) {
|
|
|
66
|
+ const {
|
|
|
67
|
+ data: { flv },
|
|
|
68
|
+ } = await getVideoControlStart({ channelId, deviceId })
|
66
|
|
69
|
|
67
|
- playUrl = flv
|
|
|
68
|
- type = VideoPlayerType.flv
|
|
|
69
|
- }
|
70
|
+ playUrl = flv
|
|
|
71
|
+ type = VideoPlayerType.flv
|
|
|
72
|
+ }
|
70
|
|
73
|
|
71
|
- // 判断是否是rtsp播放
|
|
|
72
|
- if (isRtspProtocol(videoUrl!)) {
|
|
|
73
|
- const result = await getResult()
|
|
|
74
|
- const { visitorId } = result
|
|
|
75
|
- playUrl = getFlvPlayUrl(playUrl!, visitorId)
|
|
|
76
|
- withToken.value = true
|
|
|
77
|
- }
|
74
|
+ // 判断是否是rtsp播放
|
|
|
75
|
+ if (isRtspProtocol(videoUrl!)) {
|
|
|
76
|
+ const result = await getResult()
|
|
|
77
|
+ const { visitorId } = result
|
|
|
78
|
+ playUrl = getFlvPlayUrl(playUrl!, visitorId)
|
|
|
79
|
+ withToken.value = true
|
|
|
80
|
+ }
|
78
|
|
81
|
|
79
|
- playSource.value = {
|
|
|
80
|
- src: playUrl!,
|
|
|
81
|
- type,
|
|
|
82
|
- }
|
82
|
+ playSource.value = {
|
|
|
83
|
+ src: playUrl!,
|
|
|
84
|
+ type,
|
|
|
85
|
+ }
|
83
|
|
86
|
|
84
|
- const instance = unref(basicVideoPlayEl)?.customInit((options) => {
|
|
|
85
|
- if (unref(withToken)) {
|
|
|
86
|
- (options as any).flvjs.config.headers = {
|
|
|
87
|
- 'X-Authorization': `Bearer ${isShareMode() ? getShareJwtToken() : getJwtToken()}`,
|
87
|
+ const instance = unref(basicVideoPlayEl)?.customInit((options) => {
|
|
|
88
|
+ if (unref(withToken)) {
|
|
|
89
|
+ (options as any).flvjs.config.headers = {
|
|
|
90
|
+ 'X-Authorization': `Bearer ${isShareMode() ? getShareJwtToken() : getJwtToken()}`,
|
|
|
91
|
+ }
|
88
|
}
|
92
|
}
|
89
|
- }
|
|
|
90
|
- return {
|
|
|
91
|
- ...options,
|
|
|
92
|
- sources: [toRaw(unref(playSource))],
|
|
|
93
|
- } as VideoJsPlayerOptions
|
|
|
94
|
- })
|
93
|
+ return {
|
|
|
94
|
+ ...options,
|
|
|
95
|
+ sources: [toRaw(unref(playSource))],
|
|
|
96
|
+ } as VideoJsPlayerOptions
|
|
|
97
|
+ })
|
95
|
|
98
|
|
96
|
- instance?.play()
|
99
|
+ instance?.play()
|
|
|
100
|
+ }
|
|
|
101
|
+ finally {
|
|
|
102
|
+ loading.value = false
|
|
|
103
|
+ }
|
97
|
}
|
104
|
}
|
98
|
|
105
|
|
99
|
// 默认播放
|
106
|
// 默认播放
|
|
@@ -135,12 +142,12 @@ onUnmounted(async () => { |
|
@@ -135,12 +142,12 @@ onUnmounted(async () => { |
135
|
|
142
|
|
136
|
<template>
|
143
|
<template>
|
137
|
<div class="w-full h-full flex justify-center items-center">
|
144
|
<div class="w-full h-full flex justify-center items-center">
|
138
|
- <!-- <Spin :spinning="loading" wrapper-class-name="video-spin" class="w-full h-full"> -->
|
|
|
139
|
- <BasicVideoPlay
|
|
|
140
|
- ref="basicVideoPlayEl" :options="getOptions" :with-token="withToken"
|
|
|
141
|
- :immediate-init-on-mounted="false"
|
|
|
142
|
- />
|
|
|
143
|
- <!-- </Spin> -->
|
145
|
+ <Spin :spinning="loading">
|
|
|
146
|
+ <BasicVideoPlay
|
|
|
147
|
+ ref="basicVideoPlayEl" :options="getOptions" :with-token="withToken"
|
|
|
148
|
+ :immediate-init-on-mounted="false"
|
|
|
149
|
+ />
|
|
|
150
|
+ </Spin>
|
144
|
</div>
|
151
|
</div>
|
145
|
</template>
|
152
|
</template>
|
146
|
|
153
|
|