From 6315aadc470c3e9251ac72ceec0cab16213c5314 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Tue, 11 Feb 2025 11:29:19 +0800 Subject: [PATCH] fix: VideoConfig.ets --- entry/src/main/ets/model/Common.ets | 3 + entry/src/main/ets/model/VideoConfig.ets | 12 ++ entry/src/main/ets/model/index.ets | 4 +- entry/src/main/ets/pages/VideoConfig.ets | 149 +++++++++++++++++++---- 4 files changed, 144 insertions(+), 24 deletions(-) diff --git a/entry/src/main/ets/model/Common.ets b/entry/src/main/ets/model/Common.ets index ee321098..55bba409 100644 --- a/entry/src/main/ets/model/Common.ets +++ b/entry/src/main/ets/model/Common.ets @@ -70,3 +70,6 @@ export interface VideoConfig { zdyz: string, } +export interface CommonType { + key: string; +} \ No newline at end of file diff --git a/entry/src/main/ets/model/VideoConfig.ets b/entry/src/main/ets/model/VideoConfig.ets index e69de29b..6ceeef1c 100644 --- a/entry/src/main/ets/model/VideoConfig.ets +++ b/entry/src/main/ets/model/VideoConfig.ets @@ -0,0 +1,12 @@ +export interface RecordHandleType { + rocord_handle1: number; + rocord_handle2: number; + rocord_handle3: number; + rocord_handle4: number; +} + +export interface VideoItemType { + td: string; + controller: VideoController; + src: string; +} \ No newline at end of file diff --git a/entry/src/main/ets/model/index.ets b/entry/src/main/ets/model/index.ets index 5a0770be..6518e40c 100644 --- a/entry/src/main/ets/model/index.ets +++ b/entry/src/main/ets/model/index.ets @@ -6,4 +6,6 @@ export * from "./Common" export * from "./Judge" -export * from "./Register" \ No newline at end of file +export * from "./Register" + +export * from "./VideoConfig" \ No newline at end of file diff --git a/entry/src/main/ets/pages/VideoConfig.ets b/entry/src/main/ets/pages/VideoConfig.ets index a4fe9a2a..df586057 100644 --- a/entry/src/main/ets/pages/VideoConfig.ets +++ b/entry/src/main/ets/pages/VideoConfig.ets @@ -5,7 +5,7 @@ import promptAction from '@ohos.promptAction'; import { endRecordVideo, startRecordVideo, takePhoto } from '../service/videoService'; import { GlobalConfig } from '../config/index'; import { VideoConfigData } from '../mock'; -import { VideoConfig } from '../model'; +import { CommonType, RecordHandleType, VideoConfig, VideoItemType } from '../model'; @Entry @Component @@ -15,7 +15,7 @@ struct Index { @State previewUri: Resource = $r('app.media.2_nor') @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X @State inputFontSize: number = 10 //12 - @State rocordHandleObj: any = { + @State rocordHandleObj: RecordHandleType = { rocord_handle1: 0, rocord_handle2: 0, rocord_handle3: 0, @@ -30,7 +30,7 @@ struct Index { @State oldParam: VideoConfig = VideoConfigData @State param: VideoConfig = VideoConfigData @State openFlag: boolean = true - @State lsArr: Array = [ + @State lsArr: Array = [ { key: '第一路' }, { key: '第二路' }, { key: '第三路' }, @@ -42,7 +42,7 @@ struct Index { private controller2: VideoController = new VideoController() private controller3: VideoController = new VideoController() private controller4: VideoController = new VideoController() - @State videoArr: Array = [ + @State videoArr: Array = [ { td: 'td1', controller: this.controller1, src: '' }, { td: 'td2', controller: this.controller2, src: '' }, { td: 'td3', controller: this.controller3, src: '' }, @@ -55,10 +55,10 @@ struct Index { TopLogo({ outFlag: $outFlag }) Flex({ justifyContent: FlexAlign.SpaceBetween }) { Flex({ wrap: FlexWrap.Wrap, direction: FlexDirection.Row }) { - ForEach(this.videoArr, (item, index) => { + ForEach(this.videoArr, (item: VideoItemType, index) => { Video({ src: this.openFlag ? - `rtsp://${this.param.userName}:${this.param.pwd}@${this.param.ip}:${this.param.port}/h264/ch${this.param[item.td]}/main/av_stream` : + `rtsp://${this.param.userName}:${this.param.pwd}@${this.param.ip}:${this.param.port}/h264/ch${this.getTdValueByTd(item.td)}/main/av_stream` : '', currentProgressRate: this.curRate, controller: item.controller @@ -101,9 +101,14 @@ struct Index { return } this.videoStartFlag = true + // for (let i = 1; i <= 4; i++) { + // if (this.param['videoRecord'+i]) { + // await this.getFileHandleCode(i) + // } + // } for (let i = 1; i <= 4; i++) { - if (this.param['videoRecord'+i]) { - await this.getfilehandleCode(i) + if (this.getVideoRecordValue(i)) { + await this.getFileHandleCode(i); } } this.videoStartFlag = false @@ -118,11 +123,17 @@ struct Index { .margin({ bottom: 10 * this.ratio }) .onClick(() => { + // for (let i = 1; i <= 4; i++) { + // if (this.rocordHandleObj['rocord_handle'+i]) { + // endRecordVideo(this.rocordHandleObj['rocord_handle'+i]) + // this.rocordHandleObj['rocord_handle'+i] = 0 + // } + // } for (let i = 1; i <= 4; i++) { - console.log('rocord_handle', i, JSON.stringify(this.rocordHandleObj)) - if (this.rocordHandleObj['rocord_handle'+i]) { - endRecordVideo(this.rocordHandleObj['rocord_handle'+i]) - this.rocordHandleObj['rocord_handle'+i] = 0 + const handle: ESObject = this.getRecordHandle(i); + if (handle) { + endRecordVideo(handle); + this.setRecordHandle(i, 0); } } promptAction.showToast({ @@ -327,7 +338,7 @@ struct Index { .textAlign(TextAlign.Center) } - ForEach(this.lsArr, (item, index) => { + ForEach(this.lsArr, (item: CommonType, index) => { Row() { Text(item.key) .width(70 * this.ratio) @@ -345,7 +356,7 @@ struct Index { .onChange((value: string) => { this.param.ip = value }) - TextInput({ text: this.param['td'+(Number(index) + 1)], controller: this.inputController }) + TextInput({ text: this.getTdValueByIndex((Number(index) + 1)), controller: this.inputController }) .type(InputType.Normal) .borderRadius(2) .width(96 * this.ratio) @@ -354,7 +365,8 @@ struct Index { .margin({ right: 10 * this.ratio }) .fontSize(this.inputFontSize * this.ratio) .onChange((value: string) => { - this.param['td'+(Number(index) + 1)] = value + // this.param['td'+(Number(index) + 1)] = value + this.setTdValue(Number(index) + 1, value) }) TextInput({ text: this.param.userName, controller: this.inputController }) .type(InputType.Normal) @@ -578,21 +590,112 @@ struct Index { this.getVideoConfig() } - async getfilehandleCode(td) { - return new Promise(async (reslove, reject) => { - const record_handle = await startRecordVideo(this.param, td, this.context, 'lp') - this.rocordHandleObj['rocord_handle'+td] = record_handle - reslove(true) - }) + async getFileHandleCode(td: number): Promise { + return new Promise(async (resolve, reject) => { + const record_handle: ESObject = await startRecordVideo(this.param, td, this.context, 'lp'); + this.setRecordHandle(td, record_handle); + resolve(); + }); + } + getRecordHandle(index: number): ESObject { + switch (index) { + case 1: + return this.rocordHandleObj.rocord_handle1; + case 2: + return this.rocordHandleObj.rocord_handle2; + case 3: + return this.rocordHandleObj.rocord_handle3; + case 4: + return this.rocordHandleObj.rocord_handle4; + default: + return null; + } + } + + getVideoRecordValue(index: number): boolean { + switch (index) { + case 1: + return this.param.videoRecord1; + case 2: + return this.param.videoRecord2; + case 3: + return this.param.videoRecord3; + case 4: + return this.param.videoRecord4; + default: + return false; + } + } + + getTdValueByTd(td: string): string { + switch (td) { + case 'td1': + return this.param.td1; + case 'td2': + return this.param.td2; + case 'td3': + return this.param.td3; + case 'td4': + return this.param.td4; + default: + return ''; + } + } + + getTdValueByIndex(index: number): string { + switch (index) { + case 1: + return this.param.td1; + case 2: + return this.param.td2; + case 3: + return this.param.td3; + case 4: + return this.param.td4; + default: + return ''; + } + } + + setTdValue(index: number, value: string): void { + switch (index) { + case 1: + this.param.td1 = value; + break; + case 2: + this.param.td2 = value; + break; + case 3: + this.param.td3 = value; + break; + case 4: + this.param.td4 = value; + break; + } + } + + setRecordHandle(td: number, record_handle: ESObject): void { + switch (td) { + case 1: + this.rocordHandleObj.rocord_handle1 = record_handle; + break; + case 2: + this.rocordHandleObj.rocord_handle2 = record_handle; + break; + case 3: + this.rocordHandleObj.rocord_handle3 = record_handle; + break; + case 4: + this.rocordHandleObj.rocord_handle4 = record_handle; + break; + } } outClick() { this.openFlag = false } - sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)) - async onPageShow() { }