feat: 添加MediaPlayer类,封装媒体播放功能,优化视频录制和播放逻辑
This commit is contained in:
parent
d461cca1c4
commit
e7ed80acf8
@ -55,11 +55,12 @@ struct Index {
|
|||||||
TopLogo({ outFlag: $outFlag })
|
TopLogo({ outFlag: $outFlag })
|
||||||
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
|
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
|
||||||
Flex({ wrap: FlexWrap.Wrap, direction: FlexDirection.Row }) {
|
Flex({ wrap: FlexWrap.Wrap, direction: FlexDirection.Row }) {
|
||||||
ForEach(this.videoArr, (item: VideoItemType, index) => {
|
ForEach(this.videoArr, (item: VideoItemType) => {
|
||||||
Video({
|
Video({
|
||||||
src: this.openFlag ?
|
src: this.openFlag ?
|
||||||
`rtsp://${this.param.userName}:${this.param.pwd}@${this.param.ip}:${this.param.port}/h264/ch${this.getTdValueByTd(item.td)}/main/av_stream` :
|
// `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${Reflect.get(this.param,
|
||||||
|
'port')}/main/av_stream` : '',
|
||||||
currentProgressRate: this.curRate,
|
currentProgressRate: this.curRate,
|
||||||
controller: item.controller
|
controller: item.controller
|
||||||
})
|
})
|
||||||
@ -103,11 +104,11 @@ struct Index {
|
|||||||
this.videoStartFlag = true
|
this.videoStartFlag = true
|
||||||
// for (let i = 1; i <= 4; i++) {
|
// for (let i = 1; i <= 4; i++) {
|
||||||
// if (this.param['videoRecord'+i]) {
|
// if (this.param['videoRecord'+i]) {
|
||||||
// await this.getFileHandleCode(i)
|
// await this.getfilehandleCode(i)
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
for (let i = 1; i <= 4; i++) {
|
for (let i = 1; i <= 4; i++) {
|
||||||
if (this.getVideoRecordValue(i)) {
|
if (Reflect.get(this.param, 'videoRecord' + i)) {
|
||||||
await this.getFileHandleCode(i);
|
await this.getFileHandleCode(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,18 +125,19 @@ struct Index {
|
|||||||
.margin({ bottom: 10 * this.ratio })
|
.margin({ bottom: 10 * this.ratio })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
// for (let i = 1; i <= 4; i++) {
|
// for (let i = 1; i <= 4; i++) {
|
||||||
|
// console.log('rocord_handle', i, JSON.stringify(this.rocordHandleObj))
|
||||||
// if (this.rocordHandleObj['rocord_handle'+i]) {
|
// if (this.rocordHandleObj['rocord_handle'+i]) {
|
||||||
// endRecordVideo(this.rocordHandleObj['rocord_handle'+i])
|
// endRecordVideo(this.rocordHandleObj)
|
||||||
// this.rocordHandleObj['rocord_handle'+i] = 0
|
// this.rocordHandleObj['rocord_handle'+i] = 0
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
for (let i = 1; i <= 4; i++) {
|
for (let i = 1; i <= 4; i++) {
|
||||||
const handle: ESObject = this.getRecordHandle(i);
|
if (Reflect.get(this.rocordHandleObj, 'rocord_handle' + i)) {
|
||||||
if (handle) {
|
Reflect.set(this.rocordHandleObj, 'rocord_handle' + i, 0);
|
||||||
endRecordVideo(handle);
|
|
||||||
this.setRecordHandle(i, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
endRecordVideo(this.rocordHandleObj);
|
||||||
|
|
||||||
promptAction.showToast({
|
promptAction.showToast({
|
||||||
message: '录像结束',
|
message: '录像结束',
|
||||||
duration: 3000
|
duration: 3000
|
||||||
@ -356,7 +358,11 @@ struct Index {
|
|||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
this.param.ip = value
|
this.param.ip = value
|
||||||
})
|
})
|
||||||
TextInput({ text: this.getTdValueByIndex((Number(index) + 1)), controller: this.inputController })
|
// TextInput({ text: this.param['td'+(Number(index) + 1)], controller: this.inputController })
|
||||||
|
TextInput({
|
||||||
|
text: Reflect.get(this.param, 'td' + (Number(index) + 1)),
|
||||||
|
controller: this.inputController
|
||||||
|
})
|
||||||
.type(InputType.Normal)
|
.type(InputType.Normal)
|
||||||
.borderRadius(2)
|
.borderRadius(2)
|
||||||
.width(96 * this.ratio)
|
.width(96 * this.ratio)
|
||||||
@ -366,7 +372,7 @@ struct Index {
|
|||||||
.fontSize(this.inputFontSize * this.ratio)
|
.fontSize(this.inputFontSize * this.ratio)
|
||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
// this.param['td'+(Number(index) + 1)] = value
|
// this.param['td'+(Number(index) + 1)] = value
|
||||||
this.setTdValue(Number(index) + 1, value)
|
Reflect.set(this.param, 'td' + (Number(index) + 1), value);
|
||||||
})
|
})
|
||||||
TextInput({ text: this.param.userName, controller: this.inputController })
|
TextInput({ text: this.param.userName, controller: this.inputController })
|
||||||
.type(InputType.Normal)
|
.type(InputType.Normal)
|
||||||
@ -583,8 +589,8 @@ struct Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
aboutToAppear() {
|
aboutToAppear() {
|
||||||
const radio = AppStorage.get('ratio') as number
|
// this.ratio = globalThis.ratio
|
||||||
this.ratio = radio
|
this.ratio = AppStorage.get<number>('ratio')
|
||||||
this.openFlag = true
|
this.openFlag = true
|
||||||
const fileUtil = new FileUtil(this.context)
|
const fileUtil = new FileUtil(this.context)
|
||||||
this.fileUtil = fileUtil
|
this.fileUtil = fileUtil
|
||||||
@ -592,105 +598,13 @@ struct Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFileHandleCode(td: number): Promise<void> {
|
async getFileHandleCode(td: number): Promise<void> {
|
||||||
return new Promise<void>(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const record_handle: ESObject = await startRecordVideo(this.param, td, this.context, 'lp');
|
const record_handle = await startRecordVideo(this.param, td, this.context, 'lp')
|
||||||
this.setRecordHandle(td, record_handle);
|
// this.rocordHandleObj['rocord_handle'+td] = record_handle
|
||||||
resolve();
|
Reflect.set(this.rocordHandleObj, 'rocord_handle' + 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() {
|
outClick() {
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import JudgeTask from './utils/judgeTask';
|
|||||||
import { judgeConfig } from './utils/judgeConfig';
|
import { judgeConfig } from './utils/judgeConfig';
|
||||||
import UsbService from '../../service/usbService';
|
import UsbService from '../../service/usbService';
|
||||||
import { KF, LANE } from '../judgeSDK/api/judgeSDK.d';
|
import { KF, LANE } from '../judgeSDK/api/judgeSDK.d';
|
||||||
import { endRecordVideo, saveStartRecordVideo } from '../../service/videoService';
|
|
||||||
import {
|
import {
|
||||||
Array2Byte,
|
Array2Byte,
|
||||||
convertGpsCoord2,
|
convertGpsCoord2,
|
||||||
@ -53,6 +52,7 @@ import {
|
|||||||
examJudgeVersion
|
examJudgeVersion
|
||||||
} from './api/index';
|
} from './api/index';
|
||||||
import { writeObjectOut } from '../../api/judge';
|
import { writeObjectOut } from '../../api/judge';
|
||||||
|
import { saveStartRecordVideo } from '../../utils/Video';
|
||||||
|
|
||||||
const judgeTag = 'SURENJUN_JUDGE'
|
const judgeTag = 'SURENJUN_JUDGE'
|
||||||
|
|
||||||
@ -260,40 +260,6 @@ export default class Judge {
|
|||||||
private isExamEnd: boolean
|
private isExamEnd: boolean
|
||||||
// 是否发送udp
|
// 是否发送udp
|
||||||
private isUdpEnd: boolean = false
|
private isUdpEnd: boolean = false
|
||||||
// 处理udp plc信号
|
|
||||||
handleUdp = async (msg) => {
|
|
||||||
console.info('plc信号', msg)
|
|
||||||
// const { fileLog, getPlcData, usbService, isUdpEnd, isExamEnd, judgeUI } = this
|
|
||||||
const stachArr = msg.split(',')
|
|
||||||
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const plcData = await this.getPlcData(msg);
|
|
||||||
// 4.过程数据
|
|
||||||
await this.fileLog.setExamJudgeData(plcData)
|
|
||||||
//检测到有无锡所设备接入,需要发送特定的数据,供检测
|
|
||||||
if (this.usbService.isWXUSBDevice) {
|
|
||||||
const str = await senorToWXDataStr(msg);
|
|
||||||
this.usbService.sendUSB(str)
|
|
||||||
}
|
|
||||||
const param350 = this.judgeUI.judgeConfigObj['350']
|
|
||||||
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
|
|
||||||
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
|
|
||||||
//TODO 暂时关闭差分检测异常
|
|
||||||
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
|
|
||||||
if (!this.isExamEnd) {
|
|
||||||
await examJudgeRealExam(plcData)
|
|
||||||
}
|
|
||||||
let udpIndex = AppStorage.get('udpIndex') as number;
|
|
||||||
let [prevJd, preWd] = [0, 0]
|
|
||||||
if (udpIndex % 5 === 0 && !this.isUdpEnd) {
|
|
||||||
// TODO UPD缺失
|
|
||||||
// const judgeUdp = globalThis.judgeUdp
|
|
||||||
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
|
|
||||||
// judgeUdp.send(bytes)
|
|
||||||
}
|
|
||||||
AppStorage.setOrCreate('udpIndex', udpIndex++)
|
|
||||||
}
|
|
||||||
//是否手动结束考试
|
//是否手动结束考试
|
||||||
private isManual: boolean
|
private isManual: boolean
|
||||||
//UDP服务序列号
|
//UDP服务序列号
|
||||||
@ -480,6 +446,40 @@ export default class Judge {
|
|||||||
|
|
||||||
return tempData
|
return tempData
|
||||||
}
|
}
|
||||||
|
// 处理udp plc信号
|
||||||
|
handleUdp = async (msg) => {
|
||||||
|
console.info('plc信号', msg)
|
||||||
|
// const { fileLog, getPlcData, usbService, isUdpEnd, isExamEnd, judgeUI } = this
|
||||||
|
const stachArr = msg.split(',')
|
||||||
|
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const plcData = await this.getPlcData(msg);
|
||||||
|
// 4.过程数据
|
||||||
|
await this.fileLog.setExamJudgeData(plcData)
|
||||||
|
//检测到有无锡所设备接入,需要发送特定的数据,供检测
|
||||||
|
if (this.usbService.isWXUSBDevice) {
|
||||||
|
const str = await senorToWXDataStr(msg);
|
||||||
|
this.usbService.sendUSB(str)
|
||||||
|
}
|
||||||
|
const param350 = this.judgeUI.judgeConfigObj['350']
|
||||||
|
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
|
||||||
|
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
|
||||||
|
//TODO 暂时关闭差分检测异常
|
||||||
|
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
|
||||||
|
if (!this.isExamEnd) {
|
||||||
|
await examJudgeRealExam(plcData)
|
||||||
|
}
|
||||||
|
let udpIndex = AppStorage.get('udpIndex') as number;
|
||||||
|
let [prevJd, preWd] = [0, 0]
|
||||||
|
if (udpIndex % 5 === 0 && !this.isUdpEnd) {
|
||||||
|
// TODO UPD缺失
|
||||||
|
// const judgeUdp = globalThis.judgeUdp
|
||||||
|
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
|
||||||
|
// judgeUdp.send(bytes)
|
||||||
|
}
|
||||||
|
AppStorage.setOrCreate('udpIndex', udpIndex++)
|
||||||
|
}
|
||||||
// 处理轨迹plc信号
|
// 处理轨迹plc信号
|
||||||
handleTrajectoryUdp = async (strArr) => {
|
handleTrajectoryUdp = async (strArr) => {
|
||||||
// const { fileLog, setJudgeItem, setJudgeMark, endExam } = this;
|
// const { fileLog, setJudgeItem, setJudgeMark, endExam } = this;
|
||||||
@ -523,67 +523,6 @@ export default class Judge {
|
|||||||
private isTrajectoryOpen: boolean;
|
private isTrajectoryOpen: boolean;
|
||||||
// 调代理接口是否断网了
|
// 调代理接口是否断网了
|
||||||
private isJudgeDisConnect: boolean;
|
private isJudgeDisConnect: boolean;
|
||||||
// 考试过程照片
|
|
||||||
uploadProgressPhoto = async (ksxm) => {
|
|
||||||
const time = await getCurrentTime();
|
|
||||||
const { judgeUI, plcData, getPhoto, fileLog, filePath } = this;
|
|
||||||
const photoBase64 = await getPhoto();
|
|
||||||
const carInfo = AppStorage.get('carInfo');
|
|
||||||
const { examSubject, plateNo, carNo } = carInfo;
|
|
||||||
const { lsh, idCard, serialNumber, projectsObj, ksdd, judgeConfigObj } = judgeUI;
|
|
||||||
const { sensor, gps } = plcData
|
|
||||||
const project = projectsObj[ksxm]
|
|
||||||
|
|
||||||
const data = {
|
|
||||||
xtlb: '17',
|
|
||||||
jkxlh: serialNumber,
|
|
||||||
jkid: '17C54',
|
|
||||||
drvexam: {
|
|
||||||
lsh,
|
|
||||||
kskm: examSubject,
|
|
||||||
ksxm: project.projectCodeCenter,
|
|
||||||
sfzmhm: idCard,
|
|
||||||
kchp: encodeURI(plateNo),
|
|
||||||
zpsj: time,
|
|
||||||
zp: photoBase64,
|
|
||||||
cs: Math.floor((judgeConfigObj['350'] == 0 ? gps.sd : sensor.cs) * 1.852),
|
|
||||||
ksdd: encodeURI(ksdd)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const { code } = await this.sendWriteObjectOut(data, filePath);
|
|
||||||
if (code === 2300007) {
|
|
||||||
this.isJudgeDisConnect = true
|
|
||||||
}
|
|
||||||
promptWxCode('17C54', code)
|
|
||||||
console.info(judgeTag, '上传照片 end')
|
|
||||||
}
|
|
||||||
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
|
|
||||||
private lane: LANE = {
|
|
||||||
road: '', num: 0, count: 0
|
|
||||||
}
|
|
||||||
private videoData: any
|
|
||||||
private disConnectNum: number = 0;
|
|
||||||
//调用监管接口
|
|
||||||
sendWriteObjectOut = async (data, filePath) => {
|
|
||||||
const temp = await writeObjectOut(data, filePath);
|
|
||||||
console.log("wzj", JSON.stringify(temp))
|
|
||||||
//断网&网络超时次数计算
|
|
||||||
if (temp.code == 2300007 || temp.code == 2300028) {
|
|
||||||
this.disConnectNum += 1;
|
|
||||||
if (this.disConnectNum < 5) {
|
|
||||||
return await this.sendWriteObjectOut(data, filePath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.disConnectNum >= 5) {
|
|
||||||
console.info('surenjun', '123')
|
|
||||||
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
|
|
||||||
this.judgeUI.disConnectErrorOpen = true
|
|
||||||
}
|
|
||||||
|
|
||||||
this.disConnectNum = 0
|
|
||||||
return temp
|
|
||||||
}
|
|
||||||
// 项目开始接口同步
|
// 项目开始接口同步
|
||||||
beginProject = async (ksxm) => {
|
beginProject = async (ksxm) => {
|
||||||
const carInfo = AppStorage.get('carInfo');
|
const carInfo = AppStorage.get('carInfo');
|
||||||
@ -656,6 +595,67 @@ export default class Judge {
|
|||||||
console.info(judgeTag, '项目结束 end')
|
console.info(judgeTag, '项目结束 end')
|
||||||
promptWxCode('17C55', code)
|
promptWxCode('17C55', code)
|
||||||
}
|
}
|
||||||
|
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
|
||||||
|
private lane: LANE = {
|
||||||
|
road: '', num: 0, count: 0
|
||||||
|
}
|
||||||
|
private videoData: any
|
||||||
|
private disConnectNum: number = 0;
|
||||||
|
//调用监管接口
|
||||||
|
sendWriteObjectOut = async (data, filePath) => {
|
||||||
|
const temp = await writeObjectOut(data, filePath);
|
||||||
|
console.log("wzj", JSON.stringify(temp))
|
||||||
|
//断网&网络超时次数计算
|
||||||
|
if (temp.code == 2300007 || temp.code == 2300028) {
|
||||||
|
this.disConnectNum += 1;
|
||||||
|
if (this.disConnectNum < 5) {
|
||||||
|
return await this.sendWriteObjectOut(data, filePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.disConnectNum >= 5) {
|
||||||
|
console.info('surenjun', '123')
|
||||||
|
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
|
||||||
|
this.judgeUI.disConnectErrorOpen = true
|
||||||
|
}
|
||||||
|
|
||||||
|
this.disConnectNum = 0
|
||||||
|
return temp
|
||||||
|
}
|
||||||
|
// 考试过程照片
|
||||||
|
uploadProgressPhoto = async (ksxm) => {
|
||||||
|
const time = await getCurrentTime();
|
||||||
|
const { judgeUI, plcData, getPhoto, fileLog, filePath } = this;
|
||||||
|
const photoBase64 = await getPhoto();
|
||||||
|
const carInfo = AppStorage.get('carInfo');
|
||||||
|
const { examSubject, plateNo, carNo } = carInfo;
|
||||||
|
const { lsh, idCard, serialNumber, projectsObj, ksdd, judgeConfigObj } = judgeUI;
|
||||||
|
const { sensor, gps } = plcData
|
||||||
|
const project = projectsObj[ksxm]
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
xtlb: '17',
|
||||||
|
jkxlh: serialNumber,
|
||||||
|
jkid: '17C54',
|
||||||
|
drvexam: {
|
||||||
|
lsh,
|
||||||
|
kskm: examSubject,
|
||||||
|
ksxm: project.projectCodeCenter,
|
||||||
|
sfzmhm: idCard,
|
||||||
|
kchp: encodeURI(plateNo),
|
||||||
|
zpsj: time,
|
||||||
|
zp: photoBase64,
|
||||||
|
cs: Math.floor((judgeConfigObj['350'] == 0 ? gps.sd : sensor.cs) * 1.852),
|
||||||
|
ksdd: encodeURI(ksdd)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const { code } = await this.sendWriteObjectOut(data, filePath);
|
||||||
|
if (code === 2300007) {
|
||||||
|
this.isJudgeDisConnect = true
|
||||||
|
}
|
||||||
|
promptWxCode('17C54', code)
|
||||||
|
console.info(judgeTag, '上传照片 end')
|
||||||
|
}
|
||||||
|
|
||||||
constructor(judgeUI) {
|
constructor(judgeUI) {
|
||||||
this.serialIndex = 1;
|
this.serialIndex = 1;
|
||||||
@ -1252,7 +1252,6 @@ export default class Judge {
|
|||||||
const bytes = await this.getMessageHeartbeat(true);
|
const bytes = await this.getMessageHeartbeat(true);
|
||||||
globalThis.judgeUdp.send(bytes)
|
globalThis.judgeUdp.send(bytes)
|
||||||
}
|
}
|
||||||
await endExam()
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info(judgeTag, JSON.stringify(e))
|
console.info(judgeTag, JSON.stringify(e))
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
@ -1260,6 +1259,7 @@ export default class Judge {
|
|||||||
// router.back();
|
// router.back();
|
||||||
// }, 3000)
|
// }, 3000)
|
||||||
}
|
}
|
||||||
|
await endExam()
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import Prompt from '@system.prompt';
|
|||||||
import url from '@ohos.url';
|
import url from '@ohos.url';
|
||||||
import fileuri from "@ohos.file.fileuri";
|
import fileuri from "@ohos.file.fileuri";
|
||||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
|
||||||
const TAG = 'VoiceAnnounce'
|
const TAG = 'VoiceAnnounce'
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ class AVPlayer {
|
|||||||
resolve()
|
resolve()
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const context = AppStorage.get('context')
|
const context: common.UIAbilityContext = AppStorage.get('context')
|
||||||
this.avPlayer.fdSrc = await context.resourceManager.getRawFd(name);
|
this.avPlayer.fdSrc = await context.resourceManager.getRawFd(name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Prompt.showToast({
|
Prompt.showToast({
|
||||||
@ -175,7 +176,6 @@ class AVPlayer {
|
|||||||
|
|
||||||
// 注册avplayer回调函数
|
// 注册avplayer回调函数
|
||||||
setAVPlayerCallback(callBack) {
|
setAVPlayerCallback(callBack) {
|
||||||
|
|
||||||
this.avPlayer.on('error', (err) => {
|
this.avPlayer.on('error', (err) => {
|
||||||
this.avPlayer && this.avPlayer.stop()
|
this.avPlayer && this.avPlayer.stop()
|
||||||
this.avPlayer && this.avPlayer.reset()
|
this.avPlayer && this.avPlayer.reset()
|
||||||
|
|||||||
291
entry/src/main/ets/utils/MediaPlayer.ets
Normal file
291
entry/src/main/ets/utils/MediaPlayer.ets
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
import media from '@ohos.multimedia.media';
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
import fs from '@ohos.file.fs';
|
||||||
|
|
||||||
|
export enum PlayStatus {
|
||||||
|
/**
|
||||||
|
* 闲置状态, Player刚被创建或者调用了reset方法之后, 进入该状态, 触发idle回调事件
|
||||||
|
*/
|
||||||
|
Idle,
|
||||||
|
/**
|
||||||
|
* 资源初始化, 调用setSource进入该状态, 触发initialized回调事件
|
||||||
|
*/
|
||||||
|
Init,
|
||||||
|
/**
|
||||||
|
* 已准备状态, 在Init状态调用prepare方法后进入该状态, 触发prepared回调事件
|
||||||
|
*/
|
||||||
|
Prepared,
|
||||||
|
/**
|
||||||
|
* 正在播放状态, Prepared/Paused/Completed状态调用play方法进入该状态, 触发playing回调事件
|
||||||
|
*/
|
||||||
|
Playing,
|
||||||
|
/**
|
||||||
|
* 暂停状态, 在Playing状态调用pause方法进入该状态, 触发paused回调事件
|
||||||
|
*/
|
||||||
|
Paused,
|
||||||
|
/**
|
||||||
|
* 播放至结尾状态, loop为false时播放到结尾进入该状态, 此时调用play会进入Playing状态和重播, 调用stop进入Stopped状态, 触发completed回调
|
||||||
|
*/
|
||||||
|
Completed,
|
||||||
|
/**
|
||||||
|
* 停止状态, Prepared/Playing/Paused/Completed状态调用stop方法进入该状态, 触发stopped回调
|
||||||
|
*/
|
||||||
|
Stopped,
|
||||||
|
/**
|
||||||
|
* 销毁状态, 调用release方法后进入该状态, 触发released回调
|
||||||
|
*/
|
||||||
|
Released,
|
||||||
|
/**
|
||||||
|
* 错误状态, 当播放引擎发生不可逆的错误进入该状态, 可以调用reset重置, 也可以调用release销毁重建, 触发error回调
|
||||||
|
*/
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlayerOption {
|
||||||
|
mode: "audio" | "video"
|
||||||
|
loop: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PlayerSourceType = "network" | "raw" | "local"
|
||||||
|
|
||||||
|
type PlayerEvent = media.AVPlayerState | "status"
|
||||||
|
|
||||||
|
interface PlayerSourceOption {
|
||||||
|
/**
|
||||||
|
* 资源类型 默认为network:网络类型, raw:app预置到resource/rawfile的文件, local:应用沙箱内文件
|
||||||
|
*/
|
||||||
|
type?: PlayerSourceType
|
||||||
|
/**
|
||||||
|
* type为network时, 传入网络url type为raw时, 传入相对路径 type为local时, 传入沙箱相对路径
|
||||||
|
*/
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MediaPlayer {
|
||||||
|
private context: common.UIAbilityContext
|
||||||
|
private player?: media.AVPlayer
|
||||||
|
private option: PlayerOption = {
|
||||||
|
mode: "video",
|
||||||
|
loop: false
|
||||||
|
}
|
||||||
|
private callback: Map<PlayerEvent, Function[]> = new Map()
|
||||||
|
|
||||||
|
constructor(context: common.UIAbilityContext, option?: Partial<PlayerOption>) {
|
||||||
|
this.context = context
|
||||||
|
this.option.mode = option?.mode || "video"
|
||||||
|
this.option.loop = option?.loop || false
|
||||||
|
}
|
||||||
|
|
||||||
|
private _status: PlayStatus = PlayStatus.Idle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前播放器状态
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
get status() {
|
||||||
|
return this._status
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取媒体资源长度
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
get duration() {
|
||||||
|
return this.player?.duration ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取媒体资源当前播放进度
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
get current() {
|
||||||
|
return this.player?.currentTime ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置avplayer输出控件id 仅播放视频需要
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
set surfaceId(id: string) {
|
||||||
|
this.player!.surfaceId = id
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置播放音量
|
||||||
|
* @param volume
|
||||||
|
*/
|
||||||
|
set volume(volume: number) {
|
||||||
|
this.player?.setVolume(volume)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置是否循环播放
|
||||||
|
* @param loop
|
||||||
|
*/
|
||||||
|
set loop(loop: boolean) {
|
||||||
|
if ([PlayStatus.Prepared, PlayStatus.Playing, PlayStatus.Paused, PlayStatus.Completed].includes(this._status)) {
|
||||||
|
this.player!.loop = loop
|
||||||
|
}
|
||||||
|
this.option.loop = loop
|
||||||
|
}
|
||||||
|
|
||||||
|
async create() {
|
||||||
|
this.player = await media.createAVPlayer()
|
||||||
|
this.registerPlayerCallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置播放资源
|
||||||
|
* @param option
|
||||||
|
*/
|
||||||
|
async setSource(option: PlayerSourceOption) {
|
||||||
|
let fdPath = 'fd://';
|
||||||
|
if (option.type === "raw") {
|
||||||
|
let fileDescriptor = await this.context.resourceManager.getRawFd(option.url)
|
||||||
|
this.player!.fdSrc = fileDescriptor
|
||||||
|
} else if (option.type === "local") {
|
||||||
|
let path = this.context.filesDir + option.url;
|
||||||
|
let file = fs.openSync(path)
|
||||||
|
this.player!.url = fdPath + file.fd
|
||||||
|
} else {
|
||||||
|
this.player!.url = option.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async prepare() {
|
||||||
|
await this.player?.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
|
async play() {
|
||||||
|
await this.player?.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
async pause() {
|
||||||
|
await this.player?.pause()
|
||||||
|
}
|
||||||
|
|
||||||
|
async stop() {
|
||||||
|
await this.player?.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
async reset() {
|
||||||
|
await this.player?.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
async release() {
|
||||||
|
await this.player?.release()
|
||||||
|
this.callback.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
seek(time: number, mode?: media.SeekMode) {
|
||||||
|
this.player?.seek(time, mode || media.SeekMode.SEEK_PREV_SYNC)
|
||||||
|
}
|
||||||
|
|
||||||
|
speed(speed: media.PlaybackSpeed) {
|
||||||
|
this.player?.setSpeed(speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
on(type: PlayerEvent, cb: Function) {
|
||||||
|
if (!this.callback.has(type)) {
|
||||||
|
this.callback.set(type, [])
|
||||||
|
}
|
||||||
|
this.callback.get(type)?.push(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
once(type: PlayerEvent, cb: Function) {
|
||||||
|
let onceFn = () => {
|
||||||
|
cb()
|
||||||
|
this.off(type, onceFn)
|
||||||
|
}
|
||||||
|
this.on(type, onceFn)
|
||||||
|
}
|
||||||
|
|
||||||
|
off(type: PlayerEvent, cb: Function) {
|
||||||
|
if (!this.callback.has(type)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let cbs = this.callback.get(type)
|
||||||
|
cbs = cbs?.filter(el => el != cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
private registerPlayerCallback() {
|
||||||
|
this.player?.on("stateChange", (state, reason) => {
|
||||||
|
switch (state) {
|
||||||
|
case "idle": {
|
||||||
|
this._status = PlayStatus.Idle
|
||||||
|
this.callback.get("idle")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "initialized": {
|
||||||
|
this._status = PlayStatus.Init
|
||||||
|
this.callback.get("initialized")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
this.prepare()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "prepared": {
|
||||||
|
this._status = PlayStatus.Prepared
|
||||||
|
this.loop = this.option.loop
|
||||||
|
this.callback.get("prepared")?.forEach(cb => {
|
||||||
|
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "playing": {
|
||||||
|
this._status = PlayStatus.Playing
|
||||||
|
this.loop = this.option.loop
|
||||||
|
this.callback.get("playing")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "paused": {
|
||||||
|
this._status = PlayStatus.Paused
|
||||||
|
this.loop = this.option.loop
|
||||||
|
this.callback.get("paused")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "completed": {
|
||||||
|
this._status = PlayStatus.Completed
|
||||||
|
this.loop = this.option.loop
|
||||||
|
this.callback.get("completed")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "stopped": {
|
||||||
|
this._status = PlayStatus.Stopped
|
||||||
|
this.callback.get("stopped")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "released": {
|
||||||
|
this._status = PlayStatus.Released
|
||||||
|
this.callback.get("released")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "error": {
|
||||||
|
this._status = PlayStatus.Error
|
||||||
|
this.callback.get("error")?.forEach(cb => {
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
this.callback.get("status")?.forEach(cb => {
|
||||||
|
cb(this._status, reason)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,13 +1,16 @@
|
|||||||
import photoAccessHelper from '@ohos.file.photoAccessHelper';
|
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
|
||||||
import dataSharePredicates from '@ohos.data.dataSharePredicates';
|
import photoAccessHelper from '@ohos.file.photoAccessHelper'
|
||||||
import { dateFormat, getCurrentTime } from '../common/utils/tools';
|
import dataSharePredicates from '@ohos.data.dataSharePredicates'
|
||||||
|
import { dateFormat, getCurrentTime, isSevenDaysAgo } from '../utils/tools'
|
||||||
|
// import rtsp_server from '@ohos.rtsprecord';
|
||||||
import record from '@ohos.rtsprecord';
|
import record from '@ohos.rtsprecord';
|
||||||
import { FileHelper } from '../common/service/FileHelper';
|
import { FileHelper } from './FileHelper';
|
||||||
import FileUtil from '../common/utils/File';
|
import FileUtil from '../utils/File';
|
||||||
import { GlobalConfig } from '../config';
|
import { GlobalConfig } from '../../config';
|
||||||
import promptAction from '@ohos.promptAction';
|
import promptAction from '@ohos.promptAction';
|
||||||
|
import { GetCurrentTime, IsDaysAgo } from './Common';
|
||||||
|
import { RecordHandleType, VideoConfig } from '../model';
|
||||||
import common from '@ohos.app.ability.common';
|
import common from '@ohos.app.ability.common';
|
||||||
import { IsDaysAgo } from './Common';
|
|
||||||
|
|
||||||
const rtsp_server = record.createServer();
|
const rtsp_server = record.createServer();
|
||||||
//开始录屏
|
//开始录屏
|
||||||
@ -25,24 +28,22 @@ const FILE_ASSET_FETCH_COLUMNS = [
|
|||||||
photoAccessHelper.PhotoKeys.ORIENTATION,
|
photoAccessHelper.PhotoKeys.ORIENTATION,
|
||||||
photoAccessHelper.PhotoKeys.FAVORITE,
|
photoAccessHelper.PhotoKeys.FAVORITE,
|
||||||
photoAccessHelper.PhotoKeys.TITLE,
|
photoAccessHelper.PhotoKeys.TITLE,
|
||||||
// photoAccessHelper.PhotoKeys.POSITION,
|
photoAccessHelper.PhotoKeys.POSITION,
|
||||||
// photoAccessHelper.PhotoKeys.DATE_TRASHED,
|
photoAccessHelper.PhotoKeys.DATE_TRASHED,
|
||||||
// photoAccessHelper.PhotoKeys.HIDDEN
|
photoAccessHelper.PhotoKeys.HIDDEN];
|
||||||
];
|
|
||||||
|
|
||||||
// const rtsp_server = record.createServer();
|
// const rtsp_server = record.createServer();
|
||||||
|
|
||||||
export async function startRecordVideo(param, td, context, dir, path?, index?) {
|
export async function startRecordVideo(param: VideoConfig, td: number, context: common.UIAbilityContext, dir: string,
|
||||||
return new Promise(async (reslove, reject) => {
|
path?: string,
|
||||||
// const date=dateFormat(new Date).split(' ')[0]
|
index?: number): Promise<number> {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
// const folderPath = await fileUtil.initFolder(`/PLC/${date}/${dir}`);
|
let video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${td}/main/av_stream`;
|
||||||
var video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${td}/main/av_stream`;
|
|
||||||
if (rtsp_server != null) {
|
if (rtsp_server != null) {
|
||||||
console.log(`Rtsprecord startRecordVideo begin,video_uri`, video_uri);
|
console.log(`Rtsprecord startRecordVideo begin,video_uri`, video_uri);
|
||||||
const num = Math.floor(Math.random() * 10000)
|
const num = Math.floor(Math.random() * 10000)
|
||||||
let fileName
|
let fileName: string
|
||||||
const time = await getCurrentTime()
|
const time = await GetCurrentTime()
|
||||||
const date = time.split(' ')[0]
|
const date = time.split(' ')[0]
|
||||||
if (!path) {
|
if (!path) {
|
||||||
fileName = `${date}_movie_record${num}.mp4`
|
fileName = `${date}_movie_record${num}.mp4`
|
||||||
@ -50,39 +51,42 @@ export async function startRecordVideo(param, td, context, dir, path?, index?) {
|
|||||||
fileName = `${date}_${path}_${index || num}.mp4`
|
fileName = `${date}_${path}_${index || num}.mp4`
|
||||||
}
|
}
|
||||||
|
|
||||||
var recordResult = rtsp_server.startRecordVideo(context, video_uri, fileName, date, dir);
|
let recordResult = rtsp_server.startRecordVideo(context, video_uri, fileName, date);
|
||||||
const handleId = recordResult.dataInt;
|
const handleId = recordResult.dataInt;
|
||||||
reslove(handleId)
|
resolve(handleId)
|
||||||
} else {
|
} else {
|
||||||
console.log(`Rtsprecord startRecordVideo rtsp_server isnull`);
|
console.log(`Rtsprecord startRecordVideo rtsp_server isnull`);
|
||||||
reslove(0)
|
resolve(0)
|
||||||
}
|
}
|
||||||
console.log(`Rtsprecord startRecordVideo end`);
|
console.log(`Rtsprecord startRecordVideo end`);
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//结束录屏
|
//结束录屏
|
||||||
export async function endRecordVideo(record_handleObj) {
|
export async function endRecordVideo(record_handleObj: RecordHandleType) {
|
||||||
for (let key in record_handleObj) {
|
const handleIds = [
|
||||||
if (rtsp_server != null && record_handleObj[key] > 0) {
|
record_handleObj.rocord_handle1,
|
||||||
console.log(`Rtsprecord endRecordVideo begin`);
|
record_handleObj.rocord_handle2,
|
||||||
var recordResult = rtsp_server.endRecordVideo(record_handleObj[key]);
|
record_handleObj.rocord_handle3,
|
||||||
console.log(`Rtsprecord endRecordVideo record_handle` + record_handleObj[key].dataInt + ` filename:` +
|
record_handleObj.rocord_handle4
|
||||||
record_handleObj[key].fileName);
|
];
|
||||||
|
|
||||||
|
for (const handleId of handleIds) {
|
||||||
|
if (rtsp_server != null && handleId > 0) {
|
||||||
|
console.log(`Rtsprecord endRecordVideo begin`);
|
||||||
|
const recordResult = rtsp_server.endRecordVideo(handleId);
|
||||||
|
console.log(`Rtsprecord endRecordVideo record_handle` + recordResult.dataInt + ` filename:` +
|
||||||
|
recordResult.fileName);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Rtsprecord endRecordVideo handleId isnull`);
|
console.log(`Rtsprecord endRecordVideo handleId isnull`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function saveStartRecordVideo(path) {
|
export async function saveStartRecordVideo(path) {
|
||||||
return new Promise(async (reslove, reject) => {
|
return new Promise(async (reslove, reject) => {
|
||||||
const context = AppStorage.get('context')
|
const fileUtil = new FileUtil(globalThis.context)
|
||||||
const fileUtil = new FileUtil(context)
|
|
||||||
const fileHelper = new FileHelper();
|
const fileHelper = new FileHelper();
|
||||||
const date = dateFormat(new Date).split(' ')[0]
|
const date = dateFormat(new Date).split(' ')[0]
|
||||||
fileHelper.createAlbum(date);
|
fileHelper.createAlbum(date);
|
||||||
@ -106,56 +110,6 @@ export async function saveStartRecordVideo(path) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getfilehandleCode(td, param, dir, path, index) {
|
|
||||||
return new Promise(async (reslove, reject) => {
|
|
||||||
console.log('pathpath1', path)
|
|
||||||
const context = AppStorage.get('context')
|
|
||||||
|
|
||||||
const record_handle = await startRecordVideo(param, td, context, dir, path, index)
|
|
||||||
// this.rocordHandleObj['rocord_handle'+td] = record_handle
|
|
||||||
reslove(record_handle)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export async function getUserAlbumItemByDisplayName(displayName: string, day?,
|
|
||||||
type?): Promise<photoAccessHelper.Album> {
|
|
||||||
let fetchResult = null
|
|
||||||
let album: photoAccessHelper.Album = null
|
|
||||||
try {
|
|
||||||
console.log('getUserAlbumItemByDisplayName');
|
|
||||||
let predicates = new dataSharePredicates.DataSharePredicates();
|
|
||||||
predicates.equalTo(photoAccessHelper.AlbumKeys.ALBUM_NAME, displayName)
|
|
||||||
let fetchOptions = {
|
|
||||||
fetchColumns: [],
|
|
||||||
predicates: predicates
|
|
||||||
};
|
|
||||||
const context = AppStorage.get('context')
|
|
||||||
const userFileMgr = photoAccessHelper.getPhotoAccessHelper(context);
|
|
||||||
|
|
||||||
fetchResult =
|
|
||||||
await userFileMgr.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC,
|
|
||||||
fetchOptions);
|
|
||||||
console.log('get getUserAlbumItemByDisplayName, count: ' + JSON.stringify(fetchResult));
|
|
||||||
if (fetchResult.getCount() > 0) {
|
|
||||||
const albums = await fetchResult.getLastObject();
|
|
||||||
console.log('get getUserAlbumItemByDisplayName album111', albums.albumName)
|
|
||||||
|
|
||||||
if (IsDaysAgo(albums.albumName, day)) {
|
|
||||||
deleteAllFileByPiC(albums.albumName, type)
|
|
||||||
}
|
|
||||||
console.log('get getUserAlbumItemByDisplayName album',)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.log('get Album getUserAlbumItemByDisplayName fetchResult failed with err: ' + err);
|
|
||||||
} finally {
|
|
||||||
if (fetchResult != null) {
|
|
||||||
fetchResult.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return album;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*拍照
|
*拍照
|
||||||
@ -181,9 +135,8 @@ interface takePhotoParam {
|
|||||||
*/
|
*/
|
||||||
const fileHelper = new FileHelper();
|
const fileHelper = new FileHelper();
|
||||||
|
|
||||||
export async function delPic(day: number, type: number) {
|
export async function delPic(day, type) {
|
||||||
const context: common.UIAbilityContext = AppStorage.get('context')
|
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(globalThis.context);
|
||||||
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
|
|
||||||
console.info('albumGetAssetsDemoCallback');
|
console.info('albumGetAssetsDemoCallback');
|
||||||
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
|
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
|
||||||
let albumFetchOptions: photoAccessHelper.FetchOptions = {
|
let albumFetchOptions: photoAccessHelper.FetchOptions = {
|
||||||
@ -210,18 +163,13 @@ export async function delPic(day: number, type: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function takePhoto(param, context, dir, flag = 1, callback?) {
|
export async function takePhoto(param, context, dir, flag = 1, callback?) {
|
||||||
var video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${param.pztd}/main/av_stream`;
|
let video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${param.pztd}/main/av_stream`;
|
||||||
// var video_uri = `rtsp://admin:openharmony1@192.168.1.66:554/Streaming/Channels/3`;
|
|
||||||
|
|
||||||
const num = Math.floor(Math.random() * 10000)
|
const num = Math.floor(Math.random() * 10000)
|
||||||
const fileName = `picture_record${num}.jpg`
|
const fileName = `picture_record${num}.jpg`
|
||||||
console.log('baoyihubaoyihu', video_uri, flag)
|
|
||||||
|
|
||||||
console.log(`baoyihu Rtsprecord baohaowen getVideoSnapshot fileName:` + fileName);
|
|
||||||
// var snapResult = rtsp_server.getVideoSnapshot(context, video_uri, '', dir);
|
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err, snapResult) => {
|
rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err, snapResult) => {
|
||||||
console.log("baohaowen_detectLoop round end size1:" + snapResult.fileSize);
|
|
||||||
callback({ fileSize: snapResult.fileSize, errorCode: snapResult.errorCode })
|
callback({ fileSize: snapResult.fileSize, errorCode: snapResult.errorCode })
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -251,12 +199,6 @@ export async function takePhoto(param, context, dir, flag = 1, callback?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteAllPicturesFn() {
|
|
||||||
fileHelper.deleteAllPictures();
|
|
||||||
const context = AppStorage.get('context')
|
|
||||||
deleteAllVideos(context, photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.VIDEO)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//type:1 是图片 2是视频
|
//type:1 是图片 2是视频
|
||||||
export async function deleteAllFileByPiC(dirName, type = 1) {
|
export async function deleteAllFileByPiC(dirName, type = 1) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user