Commit 879642eabbfd6acf1134dc406efe154b62ceeaf7

Authored by ww
1 parent 9a1b9a75

fix: camer split screen mode can not play stream

... ... @@ -28,14 +28,9 @@
28 28 import type { StreamingManageRecord, CameraModel } from '/@/api/camera/model/cameraModel';
29 29 import { videoPlay } from 'vue3-video-play'; // 引入组件
30 30 import 'vue3-video-play/dist/style.css'; // 引入css
31   - import { AccessMode } from './config.data';
  31 + import { AccessMode, MediaType } from './config.data';
32 32 import { getStreamingPlayUrl } from '/@/api/camera/cameraManager';
33 33
34   - enum MediaType {
35   - MP4 = 'mp4',
36   - M3U8 = 'm3u8',
37   - }
38   -
39 34 const heightNum = ref(800);
40 35 const showVideo = ref(false);
41 36 const options = reactive({
... ...
... ... @@ -10,11 +10,16 @@
10 10 import { useFullscreen } from '@vueuse/core';
11 11 import CameraDrawer from './CameraDrawer.vue';
12 12 import { useDrawer } from '/@/components/Drawer';
13   - import { PageMode } from './config.data';
  13 + import { AccessMode, MediaType, PageMode } from './config.data';
14 14 import SvgIcon from '/@/components/Icon/src/SvgIcon.vue';
15 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 24 const emit = defineEmits(['switchMode']);
20 25 const organizationIdTreeRef = ref(null);
... ... @@ -76,13 +81,48 @@
76 81 organizationId: unref(organizationId)!,
77 82 });
78 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 90 cameraList.value = items;
80   - console.log({ url: cameraList.value.map((item) => item.videoUrl) });
81 91 } catch (error) {
82 92 } finally {
83 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 127 const handleSwitchLayoutWay = (pageSize: number, layout: number) => {
88 128 pagination.colNumber = layout;
... ... @@ -115,7 +155,7 @@
115 155 ~index &&
116 156 !unref(cameraList).at(index)!.canPlay &&
117 157 (unref(cameraList).at(index)!.canPlay = false);
118   - }, 10000);
  158 + }, 30000);
119 159 };
120 160
121 161 const handleLoadData = (record: CameraRecordItem) => {
... ... @@ -171,8 +211,8 @@
171 211 :page-size="pagination.pageSize"
172 212 :show-size-changer="false"
173 213 @change="getCameraList"
  214 + :simple="true"
174 215 :show-quick-jumper="true"
175   - size="small"
176 216 :show-total="(total) => `共 ${total} 条`"
177 217 />
178 218 </div>
... ... @@ -203,16 +243,21 @@
203 243 :span="getColLayout"
204 244 >
205 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 250 <VideoPlay
  251 + v-show="item.isTransform"
208 252 @loadstart="handleLoadStart(item)"
209 253 @loadeddata="handleLoadData(item)"
210 254 v-bind="options"
211 255 :src="item.videoUrl"
212 256 :title="item.name"
  257 + :type="item.type"
213 258 />
214 259 <div
215   - v-if="isDef(item.canPlay) && !item.canPlay"
  260 + v-if="item.isTransform && isDef(item.canPlay) && !item.canPlay"
216 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 29 FULL_SCREEN_MODE = 'fullScreenMode',
30 30 }
31 31
  32 +export enum MediaType {
  33 + MP4 = 'mp4',
  34 + M3U8 = 'm3u8',
  35 +}
  36 +
32 37 // 表格列数据
33 38 export const columns: BasicColumn[] = [
34 39 {
... ...