Commit 879642eabbfd6acf1134dc406efe154b62ceeaf7
1 parent
9a1b9a75
fix: camer split screen mode can not play stream
Showing
3 changed files
with
58 additions
and
13 deletions
@@ -28,14 +28,9 @@ | @@ -28,14 +28,9 @@ | ||
28 | import type { StreamingManageRecord, CameraModel } from '/@/api/camera/model/cameraModel'; | 28 | import type { StreamingManageRecord, CameraModel } from '/@/api/camera/model/cameraModel'; |
29 | import { videoPlay } from 'vue3-video-play'; // 引入组件 | 29 | import { videoPlay } from 'vue3-video-play'; // 引入组件 |
30 | import 'vue3-video-play/dist/style.css'; // 引入css | 30 | import 'vue3-video-play/dist/style.css'; // 引入css |
31 | - import { AccessMode } from './config.data'; | 31 | + import { AccessMode, MediaType } from './config.data'; |
32 | import { getStreamingPlayUrl } from '/@/api/camera/cameraManager'; | 32 | import { getStreamingPlayUrl } from '/@/api/camera/cameraManager'; |
33 | 33 | ||
34 | - enum MediaType { | ||
35 | - MP4 = 'mp4', | ||
36 | - M3U8 = 'm3u8', | ||
37 | - } | ||
38 | - | ||
39 | const heightNum = ref(800); | 34 | const heightNum = ref(800); |
40 | const showVideo = ref(false); | 35 | const showVideo = ref(false); |
41 | const options = reactive({ | 36 | const options = reactive({ |
@@ -10,11 +10,16 @@ | @@ -10,11 +10,16 @@ | ||
10 | import { useFullscreen } from '@vueuse/core'; | 10 | import { useFullscreen } from '@vueuse/core'; |
11 | import CameraDrawer from './CameraDrawer.vue'; | 11 | import CameraDrawer from './CameraDrawer.vue'; |
12 | import { useDrawer } from '/@/components/Drawer'; | 12 | import { useDrawer } from '/@/components/Drawer'; |
13 | - import { PageMode } from './config.data'; | 13 | + import { AccessMode, MediaType, PageMode } from './config.data'; |
14 | import SvgIcon from '/@/components/Icon/src/SvgIcon.vue'; | 14 | import SvgIcon from '/@/components/Icon/src/SvgIcon.vue'; |
15 | import { isDef } from '/@/utils/is'; | 15 | import { isDef } from '/@/utils/is'; |
16 | + import { getStreamingPlayUrl } from '/@/api/camera/cameraManager'; | ||
16 | 17 | ||
17 | - type CameraRecordItem = CameraRecord & { canPlay?: boolean }; | 18 | + type CameraRecordItem = CameraRecord & { |
19 | + canPlay?: boolean; | ||
20 | + type?: string; | ||
21 | + isTransform?: boolean; | ||
22 | + }; | ||
18 | 23 | ||
19 | const emit = defineEmits(['switchMode']); | 24 | const emit = defineEmits(['switchMode']); |
20 | const organizationIdTreeRef = ref(null); | 25 | const organizationIdTreeRef = ref(null); |
@@ -76,13 +81,48 @@ | @@ -76,13 +81,48 @@ | ||
76 | organizationId: unref(organizationId)!, | 81 | organizationId: unref(organizationId)!, |
77 | }); | 82 | }); |
78 | pagination.total = total; | 83 | pagination.total = total; |
84 | + | ||
85 | + for (const item of items) { | ||
86 | + // await beforeVideoPlay(item); | ||
87 | + (item as CameraRecordItem).isTransform = false; | ||
88 | + beforeVideoPlay(item); | ||
89 | + } | ||
79 | cameraList.value = items; | 90 | cameraList.value = items; |
80 | - console.log({ url: cameraList.value.map((item) => item.videoUrl) }); | ||
81 | } catch (error) { | 91 | } catch (error) { |
82 | } finally { | 92 | } finally { |
83 | loading.value = false; | 93 | loading.value = false; |
84 | } | 94 | } |
85 | }; | 95 | }; |
96 | + const getMediaType = (suffix: string) => { | ||
97 | + return suffix === MediaType.M3U8 ? suffix : `video/${suffix}`; | ||
98 | + }; | ||
99 | + | ||
100 | + const beforeVideoPlay = async (record: CameraRecordItem) => { | ||
101 | + let reg = /(?:.*)(?<=\.)/; | ||
102 | + if (record.accessMode === AccessMode.ManuallyEnter) { | ||
103 | + if (record.videoUrl) { | ||
104 | + const type = record.videoUrl.replace(reg, ''); | ||
105 | + record.type = getMediaType(type); | ||
106 | + record.isTransform = true; | ||
107 | + } | ||
108 | + } | ||
109 | + if (record.accessMode === AccessMode.Streaming) { | ||
110 | + try { | ||
111 | + const { data: { url } = { url: '' } } = await getStreamingPlayUrl(record.id!); | ||
112 | + const type = url.replace(reg, ''); | ||
113 | + const index = unref(cameraList).findIndex((item) => item.id === record.id); | ||
114 | + if (~index) { | ||
115 | + const oldRecord = unref(cameraList).at(index)!; | ||
116 | + unref(cameraList)[index] = { | ||
117 | + ...oldRecord, | ||
118 | + videoUrl: url, | ||
119 | + type: getMediaType(type), | ||
120 | + isTransform: true, | ||
121 | + }; | ||
122 | + } | ||
123 | + } catch (error) {} | ||
124 | + } | ||
125 | + }; | ||
86 | 126 | ||
87 | const handleSwitchLayoutWay = (pageSize: number, layout: number) => { | 127 | const handleSwitchLayoutWay = (pageSize: number, layout: number) => { |
88 | pagination.colNumber = layout; | 128 | pagination.colNumber = layout; |
@@ -115,7 +155,7 @@ | @@ -115,7 +155,7 @@ | ||
115 | ~index && | 155 | ~index && |
116 | !unref(cameraList).at(index)!.canPlay && | 156 | !unref(cameraList).at(index)!.canPlay && |
117 | (unref(cameraList).at(index)!.canPlay = false); | 157 | (unref(cameraList).at(index)!.canPlay = false); |
118 | - }, 10000); | 158 | + }, 30000); |
119 | }; | 159 | }; |
120 | 160 | ||
121 | const handleLoadData = (record: CameraRecordItem) => { | 161 | const handleLoadData = (record: CameraRecordItem) => { |
@@ -171,8 +211,8 @@ | @@ -171,8 +211,8 @@ | ||
171 | :page-size="pagination.pageSize" | 211 | :page-size="pagination.pageSize" |
172 | :show-size-changer="false" | 212 | :show-size-changer="false" |
173 | @change="getCameraList" | 213 | @change="getCameraList" |
214 | + :simple="true" | ||
174 | :show-quick-jumper="true" | 215 | :show-quick-jumper="true" |
175 | - size="small" | ||
176 | :show-total="(total) => `共 ${total} 条`" | 216 | :show-total="(total) => `共 ${total} 条`" |
177 | /> | 217 | /> |
178 | </div> | 218 | </div> |
@@ -203,16 +243,21 @@ | @@ -203,16 +243,21 @@ | ||
203 | :span="getColLayout" | 243 | :span="getColLayout" |
204 | > | 244 | > |
205 | <div class="box-border w-full h-full p-3"> | 245 | <div class="box-border w-full h-full p-3"> |
206 | - <div class="bg-yellow-50 w-full h-full overflow-hidden relative video-container"> | 246 | + <div class="bg-black w-full h-full overflow-hidden relative video-container"> |
247 | + <Spin v-show="!item.isTransform" :spinning="!item.isTransform"> | ||
248 | + <div class="bg-black text-light-50"> </div> | ||
249 | + </Spin> | ||
207 | <VideoPlay | 250 | <VideoPlay |
251 | + v-show="item.isTransform" | ||
208 | @loadstart="handleLoadStart(item)" | 252 | @loadstart="handleLoadStart(item)" |
209 | @loadeddata="handleLoadData(item)" | 253 | @loadeddata="handleLoadData(item)" |
210 | v-bind="options" | 254 | v-bind="options" |
211 | :src="item.videoUrl" | 255 | :src="item.videoUrl" |
212 | :title="item.name" | 256 | :title="item.name" |
257 | + :type="item.type" | ||
213 | /> | 258 | /> |
214 | <div | 259 | <div |
215 | - v-if="isDef(item.canPlay) && !item.canPlay" | 260 | + v-if="item.isTransform && isDef(item.canPlay) && !item.canPlay" |
216 | class="video-container-error-msk absolute top-0 left-0 text-lg w-full h-full text-light-50 flex justify-center items-center z-50 bg-black" | 261 | class="video-container-error-msk absolute top-0 left-0 text-lg w-full h-full text-light-50 flex justify-center items-center z-50 bg-black" |
217 | > | 262 | > |
218 | 视频加载出错了! | 263 | 视频加载出错了! |
@@ -29,6 +29,11 @@ export enum PageMode { | @@ -29,6 +29,11 @@ export enum PageMode { | ||
29 | FULL_SCREEN_MODE = 'fullScreenMode', | 29 | FULL_SCREEN_MODE = 'fullScreenMode', |
30 | } | 30 | } |
31 | 31 | ||
32 | +export enum MediaType { | ||
33 | + MP4 = 'mp4', | ||
34 | + M3U8 = 'm3u8', | ||
35 | +} | ||
36 | + | ||
32 | // 表格列数据 | 37 | // 表格列数据 |
33 | export const columns: BasicColumn[] = [ | 38 | export const columns: BasicColumn[] = [ |
34 | { | 39 | { |