你好,我想问一下,我把之前用的JFrame框架进行了修改,然后下载录像成功之后,文件的大小确为0K,不知道哪里有问题,请教一下
public class DowmLoadRecordFile {
private String m_strIp = "117.172.167.248";
private int m_nPort = 38888;
private String m_strUser = "admin";
private String m_strPassword = "YBGX1234";
// 开始时间
private NetSDKLib.NET_TIME stTimeStart = new NetSDKLib.NET_TIME();
// 结束时间
private NetSDKLib.NET_TIME stTimeEnd = new NetSDKLib.NET_TIME();
// 设备信息扩展
private NetSDKLib.NET_DEVICEINFO_Ex deviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
public static final NetSDKLib netSdk = NetSDKLib.NETSDK_INSTANCE;
// 登陆句柄
private NetSDKLib.LLong loginHandle = new NetSDKLib.LLong(0);
private NetSDKLib.LLong m_hDownLoadByTimeHandle = new NetSDKLib.LLong(0); // 按时间下载句柄
private DownLoadPosCallBackByTime m_DownLoadPosByTime = new DownLoadPosCallBackByTime(); // 录像下载进度
class DownLoadPosCallBackByTime implements NetSDKLib.fTimeDownLoadPosCallBack {
@Override
public void invoke(NetSDKLib.LLong lLoginID, final int dwTotalSize, final int dwDownLoadSize, int index, NetSDKLib.NET_RECORDFILE_INFO.ByValue recordfileinfo, Pointer dwUser) {
if(dwDownLoadSize == -1) {
DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByTimeHandle);
}
}
}
// 网络连接恢复
private static HaveReConnect haveReConnect = new HaveReConnect();
// 网络连接恢复,设备重连成功回调
// 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数
private static class HaveReConnect implements NetSDKLib.fHaveReConnect {
@Override
public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
}
}
//1.初始化
public void init() {
// netSdk.CLIENT_Init(DowmLoadRecordFile.DisConnectCallBack.getInstance(), null);
LoginModule.init(DowmLoadRecordFile.DisConnectCallBack.getInstance(), haveReConnect); // 打开工程,初始化
}
//2.登陆
public void Login() {
// 登陆设备
// int nSpecCap = NetSDKLib.EM_LOGIN_SPAC_CAP_TYPE.EM_LOGIN_SPEC_CAP_TCP; // TCP登入
// IntByReference nError = new IntByReference(0);
// loginHandle = netSdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser,
// m_strPassword, nSpecCap, null, deviceInfo, nError);
// if (loginHandle.longValue() != 0) {
// System.out.printf("Login Device[%s] Success!\n", m_strIp);
// } else {
// System.err.printf("Login Device[%s] Fail.Error[0x%x]\n", m_strIp, netSdk.CLIENT_GetLastError());
// LoginOut();
// }
if(LoginModule.login(m_strIp,
m_nPort,
m_strUser,
m_strPassword)){
DownLoadRecordModule.setStreamType(0);
System.out.printf("Login Device[%s] Success!\n", m_strIp);
}else{
System.err.printf("Login Device[%s] Fail.Error[0x%x]\n", m_strIp, netSdk.CLIENT_GetLastError());
LoginOut();
}
}
//3.执行流程
public void run(LocalDateTime startTime, LocalDateTime endTime) {
int m_streamType = 0;
int nChannelId = 0;
int nRecordFileType = 0;
stTimeStart.dwYear = startTime.getYear();
stTimeStart.dwMonth = startTime.getMonth().getValue();
stTimeStart.dwDay = startTime.getDayOfMonth();
stTimeStart.dwHour = startTime.getHour();
stTimeStart.dwMinute = startTime.getMinute();
stTimeStart.dwSecond = startTime.getSecond();
stTimeEnd.dwYear = endTime.getYear();
stTimeEnd.dwMonth = endTime.getMonth().getValue();
stTimeEnd.dwDay = endTime.getDayOfMonth();
stTimeEnd.dwHour = endTime.getHour();
stTimeEnd.dwMinute = endTime.getMinute();
stTimeEnd.dwSecond = endTime.getSecond();
//设置回放时的码流类型
DownLoadRecordModule.setStreamType(m_streamType);
NetSDKLib.LLong m_hDownLoadByFileHandle = new NetSDKLib.LLong();
//下载录像
m_hDownLoadByFileHandle = DownLoadRecordModule.downloadRecordFile(nChannelId,
nRecordFileType,
stTimeStart,//20210723171834
stTimeEnd,//20210723171934
SavePath.getSavePath().getSaveRecordFilePath(),//./RecordFile/2021-07-23/2021-07-23_17-25-14.dav
null);
//停止下载
DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByFileHandle);
if (m_hDownLoadByFileHandle.longValue() != 0) {
System.out.println("下载完成");
}
}
//登出
public void LoginOut() {
System.out.println("End Test");
if (loginHandle.longValue() != 0) {
netSdk.CLIENT_Logout(loginHandle);
}
System.out.println("See You...");
netSdk.CLIENT_Cleanup();
System.exit(0);
}
/**
* 设备断线回调
*/
private static class DisConnectCallBack implements NetSDKLib.fDisConnect {
private DisConnectCallBack() {
}
private static class CallBackHolder {
private static DowmLoadRecordFile.DisConnectCallBack instance = new DowmLoadRecordFile.DisConnectCallBack();
}
public static DowmLoadRecordFile.DisConnectCallBack getInstance() {
return DowmLoadRecordFile.DisConnectCallBack.CallBackHolder.instance;
}
@Override
public void invoke(NetSDKLib.LLong lLoginID, String pchDVRIP, int nDVRPort, Pointer dwUser) {
System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
}
}
public static void main(String[] args) {
DowmLoadRecordFile dowmLoadRecordFile = new DowmLoadRecordFile();
dowmLoadRecordFile.init();
dowmLoadRecordFile.Login();
dowmLoadRecordFile.run(LocalDateTime.of(2021, Month.JULY, 26, 9, 37, 56), LocalDateTime.of(2021, Month.JULY, 26, 9, 38, 56));
dowmLoadRecordFile.LoginOut();
}
}