2024-02-22 10:40:35 +08:00
|
|
|
|
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
|
|
|
|
|
|
import onvifclient from '@ohos.onvifclient';
|
|
|
|
|
|
import fs from '@ohos.file.fs'
|
|
|
|
|
|
import util from '@ohos.util';
|
|
|
|
|
|
import configAddress from '../../common/utils/FileConfig'
|
2024-02-26 15:01:27 +08:00
|
|
|
|
import { getCurrentTime } from '../utils/tools'
|
|
|
|
|
|
import record from '@ohos.rtsprecord';
|
|
|
|
|
|
|
|
|
|
|
|
const rtsp_server = record.createServer();
|
2024-02-22 10:40:35 +08:00
|
|
|
|
//开始录屏
|
2024-02-26 15:01:27 +08:00
|
|
|
|
export async function startRecordVideo(param, td, context, dir) {
|
|
|
|
|
|
return new Promise<videoPlayRes>((reslove, reject) => {
|
2024-02-22 10:40:35 +08:00
|
|
|
|
var video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${td}/main/av_stream`;
|
2024-02-26 15:01:27 +08:00
|
|
|
|
if (rtsp_server != null) {
|
|
|
|
|
|
console.log(`Rtsprecord startRecordVideo begin`);
|
|
|
|
|
|
var recordResult = rtsp_server.startRecordVideo(context, video_uri, dir);
|
|
|
|
|
|
const handleId = recordResult.dataInt;
|
|
|
|
|
|
reslove(handleId)
|
|
|
|
|
|
console.log(`Rtsprecord startRecordVideo record_handle` + recordResult.dataInt);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
console.log(`Rtsprecord startRecordVideo rtsp_server isnull`);
|
|
|
|
|
|
reslove(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log(`Rtsprecord startRecordVideo end`);
|
2024-02-22 10:40:35 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//结束录屏
|
|
|
|
|
|
export async function endRecordVideo(record_handle) {
|
2024-02-26 15:01:27 +08:00
|
|
|
|
if (rtsp_server != null && record_handle > 0) {
|
|
|
|
|
|
console.log(`Rtsprecord endRecordVideo begin`);
|
|
|
|
|
|
var recordResult = rtsp_server.endRecordVideo(record_handle);
|
|
|
|
|
|
console.log(`Rtsprecord startRecordVideo record_handle` + recordResult.dataInt + ` filename:` + recordResult.fileName);
|
2024-02-22 10:40:35 +08:00
|
|
|
|
}
|
2024-02-26 15:01:27 +08:00
|
|
|
|
else {
|
|
|
|
|
|
console.log(`Rtsprecord endRecordVideo handleId isnull`);
|
2024-02-22 10:40:35 +08:00
|
|
|
|
}
|
2024-02-26 15:01:27 +08:00
|
|
|
|
// var result = onvifclient.endRecordVideo(record_handle);
|
|
|
|
|
|
// fs.closeSync(record_handle);
|
|
|
|
|
|
// file_asset.close(record_handle);
|
2024-02-22 10:40:35 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
*拍照
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
* @param context
|
|
|
|
|
|
* @param type=0不获取base64
|
|
|
|
|
|
*/
|
2024-02-26 15:01:27 +08:00
|
|
|
|
export async function takePhoto(param, context, type = 0, dir) {
|
|
|
|
|
|
return new Promise((reslove, reject) => {
|
2024-02-22 10:40:35 +08:00
|
|
|
|
var video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${param.pztd}/main/av_stream`;
|
2024-02-26 15:01:27 +08:00
|
|
|
|
var snapResult = rtsp_server.getVideoSnapshot(context, video_uri, dir);
|
|
|
|
|
|
console.log(`baoyihu Rtsprecord getVideoSnapshot file:` + snapResult.dataString);
|
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
|
reslove(snapResult.dataString)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
reslove('')
|
|
|
|
|
|
}
|
2024-02-22 10:40:35 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-26 15:01:27 +08:00
|
|
|
|
export async function deleteAllFile(dir,context) {
|
|
|
|
|
|
const mediaType = mediaLibrary.MediaType.IMAGE
|
|
|
|
|
|
var mymediaLib = await mediaLibrary.getMediaLibrary(context);
|
|
|
|
|
|
let fetchOp = { selections: `media_type =? `, selectionArgs: [`${mediaType}`] }
|
|
|
|
|
|
console.info(`baoyihu deleteRecordFile fetchOp:` + fetchOp);
|
|
|
|
|
|
var asset = await mymediaLib.getFileAssets(fetchOp);
|
|
|
|
|
|
if (mediaType == mediaLibrary.MediaType.IMAGE) {
|
|
|
|
|
|
var base_Dir = "/storage/media/100/local/files/Pictures/";
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
var base_Dir = "/storage/media/100/local/files/Videos/";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var my_dir = dir;
|
|
|
|
|
|
asset.getAllObject((eer, fileArray) => {
|
|
|
|
|
|
for (let onfile of fileArray) {
|
|
|
|
|
|
var delet_dir = base_Dir + my_dir + onfile.uri
|
|
|
|
|
|
console.info(`baoyihu deleteRecordFile uri:` + delet_dir);
|
|
|
|
|
|
mymediaLib.deleteAsset(delet_dir, (error, asset) => {
|
|
|
|
|
|
console.info(`baoyihu deleteRecordFile 3 error:` + error);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
console.log(`Rtsprecord getVideoSnapshot end:`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-22 10:40:35 +08:00
|
|
|
|
export interface videoPlayRes {
|
|
|
|
|
|
rocord_handle?: number;
|
|
|
|
|
|
fd?: number;
|
2024-02-26 15:01:27 +08:00
|
|
|
|
file_asset?: any
|
2024-02-22 10:40:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|