private void procesoPlay2() { gFileInfo = nriFileInfo[lsvFiles.SelectedItems[0].Index]; pPlayBackChannelID = int.Parse(txtChannelID.Text.ToString()); fileInfo = gFileInfo; playRecordFile = DHClient.DHPlayBackByRecordFile(gLoginID, ref fileInfo, pictureBoxPlayback.Handle, null, IntPtr.Zero); if (playRecordFile == 0) { // MessageBox.Show("Ocurrió un error con al cargar la grabación", "Error"); btnCancelar_Click(null, null); playRecordFile = DHClient.DHPlayBackByRecordFile(gLoginID, ref fileInfo, pictureBoxPlayback.Handle, null, IntPtr.Zero); } if (playRecordFile > 0) { uint sizeFilecharge = fileInfo.size / 100; uint currentFrames = DHPlay.DHPlayControl(PLAY_COMMAND.GetCurrentFrameNum, 0, true); lblCurrentFrame.Text = currentFrames.ToString(); lblCurrentTime.Text = fileInfo.starttime.dwHour.ToString() + ":" + fileInfo.starttime.dwMinute.ToString() + ":" + fileInfo.starttime.dwSecond.ToString(); lblInfoVideo.Text = fileInfo.starttime.dwHour.ToString() + ":" + fileInfo.starttime.dwMinute.ToString() + ":" + fileInfo.starttime.dwSecond.ToString() + " - " + fileInfo.endtime.dwHour.ToString() + ":" + fileInfo.endtime.dwMinute.ToString() + ":" + fileInfo.endtime.dwSecond.ToString(); DateTime startTime = new DateTime(fileInfo.starttime.dwYear, fileInfo.starttime.dwMonth, fileInfo.starttime.dwDay, fileInfo.starttime.dwHour, fileInfo.starttime.dwMinute, fileInfo.starttime.dwSecond); DateTime endTime = new DateTime(fileInfo.endtime.dwYear, fileInfo.endtime.dwMonth, fileInfo.endtime.dwDay, fileInfo.endtime.dwHour, fileInfo.endtime.dwMinute, fileInfo.endtime.dwSecond); TimeSpan span = endTime.Subtract(startTime); segundosTotales = (int)span.TotalSeconds; lblTotalTime.Text = span.Hours.ToString() + ":" + span.Minutes.ToString() + ":" + span.Seconds.ToString(); trbPlayFrames.Maximum = 100;//(int) sizeFilecharge; timerGetPlayInfo.Enabled = true; btnPlay2.Tag = "||"; play2State(); gpbPlayBackControl.Enabled = true; } else { MessageBox.Show("Ocurrió un error con al cargar la grabación", "Error"); btnCancelar_Click(null, null); } }
/// <summary> /// 按时间回放按钮按下 /// </summary> /// <param name="sender">系统参数</param> /// <param name="e">系统参数</param> private void btn_PlayBackByTime_Click(object sender, EventArgs e) { if(clientInstance.Logined==true) { frm_PlayBackByTimeSet fPBSet = new frm_PlayBackByTimeSet(); NET_RECORDFILE_INFO fileInfo = new NET_RECORDFILE_INFO(); int fileCount=0; bool blnQueryRecordFile = false; fPBSet.ShowDialog(); if (fPBSet.blnOKEnter == true) { DateTime startTime = fPBSet.dtpStart.Value; DateTime endTime = fPBSet.dtpEnd.Value; if (startTime.Date>= endTime.Date) { MessageBox.Show("开始日期不在结束日期设置前,请重新设置!", MsgTitle); } else { blnQueryRecordFile = clientInstance.QueryRecordFile(int.Parse(fPBSet.txtChannelID.Text.ToString()), 0, startTime, endTime, null, out fileInfo, Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out fileCount, 5000, false); if (blnQueryRecordFile == true) { if (picRealPlay == null) { picRealPlay = picRealPlay15; } if (clientInstance.PlayBackByTime(int.Parse(fPBSet.txtChannelID.Text.ToString()), startTime, endTime, picRealPlay.Handle, null, IntPtr.Zero) == false) { MessageBox.Show("按时间回放失败!", MsgTitle); } else { btnPlay.Text = "||"; //画面按钮有效性控制 btn_PlayBackByTime.Enabled = false; tclControl.Enabled = true; btnPlay.Enabled = true; btnSlow.Enabled = true; btnStop.Enabled = true; btnFast.Enabled = true; btnNext.Enabled = true; hsbPlayBack.Enabled = true; } } } //MessageBox.Show(blnQueryRecordFile.ToString(),MsgTitle); } } }
private void lsvFiles_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (e.ItemIndex != -1) { //btnOK.Enabled = true; gFileInfo = nriFileInfo[e.ItemIndex]; } else { //btnOK.Enabled = false; } }
private void btnOK_Click(object sender, EventArgs e) { blnOKEnter = true; gFileInfo = nriFileInfo[lsvFiles.SelectedItems[0].Index]; this.Close(); }
/// <summary> /// 按文件回放按钮按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlayByRecordFile_Click(object sender, EventArgs e) { playBy = 0; frm_PlayBackByFileSet fpf = new frm_PlayBackByFileSet(); fpf.gLoginID = pLoginID; fpf.cmbChannelSelect.Items.Clear(); for (int i = 0; i < deviceInfo.byChanNum; i++) { fpf.cmbChannelSelect.Items.Add(i.ToString()); } fpf.ShowDialog(this); if (fpf.blnOKEnter == true) { if (picRealPlay == null) { picRealPlay = picRealPlay15; } pPlayBackChannelID = int.Parse(fpf.txtChannelID.Text.ToString()); fileInfo = fpf.gFileInfo; //**********按文件回放********** pPlayBackHandle[pPlayBackChannelID] = DHClient.DHPlayBackByRecordFile(pLoginID, ref fileInfo, picRealPlay.Handle, null, IntPtr.Zero); //****************************** if (pPlayBackHandle[pPlayBackChannelID] == 0) { MessageBox.Show("按时间回放失败!", pMsgTitle); } else { //**********画面控制代码********** btnPlay.Text = "||"; //画面按钮有效性控制 btnPlayBackByTime.Enabled = false; gpbPlayBackControl.Enabled = true; btnPlay.Enabled = true; btnSlow.Enabled = true; btnStop.Enabled = true; btnFast.Enabled = true; btnSetpPlayS.Enabled = true; hsbPlayBack.Enabled = true; btnPlayByRecordFile.Enabled = false; //********************************* } } }
/// <summary> /// 按时间下载按钮按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownLoad2_Click(object sender, EventArgs e) { frm_PlayBackByTimeSet fPBSet = new frm_PlayBackByTimeSet(); fPBSet.cmbChannelSelect.Items.Clear(); for (int i = 0; i < 16; i++) { fPBSet.cmbChannelSelect.Items.Add(i.ToString()); } NET_RECORDFILE_INFO fileInfo = new NET_RECORDFILE_INFO(); int fileCount = 0; bool blnQueryRecordFile = false; int pPlayBackChannelID=0; fPBSet.ShowDialog(); if (fPBSet.blnOKEnter == true) { DateTime startTime = fPBSet.dtpStart.Value; DateTime endTime = fPBSet.dtpEnd.Value; if (startTime.Date >= endTime.Date) { MessageBox.Show("开始日期不在结束日期设置前,请重新设置!", pMsgTitle); } else { blnQueryRecordFile = DHClient.DHQueryRecordFile(pLoginID, int.Parse(fPBSet.txtChannelID.Text.ToString()), RECORD_FILE_TYPE.ALLRECORDFILE, startTime, endTime, null, ref fileInfo, Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out fileCount, 5000, false);//按时间回放 if (blnQueryRecordFile == true) { //**********按文件下载********** pPlayBackChannelID = int.Parse(fPBSet.txtChannelID.Text.ToString()); if (txtDirPath2.Text.Trim().Length > 0 && txtFileName2.Text.Trim().Length > 0) { pDownloadHandleByTime = DHClient.DHDownloadByTime(pLoginID, pPlayBackChannelID, 0, startTime, endTime, txtDirPath1.Text + @"\" + txtFileName2.Text, downLoadFun, IntPtr.Zero); if (pDownloadHandleByTime != 0) { btnDownLoad2.Tag = "下载中"; pDownloadHandle = pDownloadHandleByTime; MessageBox.Show("开始下载!", pMsgTitle); } else { MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle); } } else { MessageBox.Show("请输入有效的录像保存目录和文件名!", pMsgTitle); } //******************************* } else { MessageBox.Show("这个时间段里没有录像文件供下载!", pMsgTitle); } } //MessageBox.Show(blnQueryRecordFile.ToString(),MsgTitle); } }
/// <summary> /// [设备用户注销]按钮按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUserLogout_Click(object sender, EventArgs e) { try { bool result = DHClient.DHLogout(pLoginID); if (result == false) { //报最后一次操作的错误信息 MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle); } picRealPlay0.Refresh(); picRealPlay1.Refresh(); picRealPlay2.Refresh(); picRealPlay3.Refresh(); picRealPlay4.Refresh(); picRealPlay5.Refresh(); picRealPlay6.Refresh(); picRealPlay7.Refresh(); if (picRealPlay != null) { picRealPlay.Refresh(); } //画面初期化 this.Controls.Clear(); InitializeComponent(); Utility.StringUtil.InitControlText(this); pLoginID = 0; fileInfo = new NET_RECORDFILE_INFO(); playBy = 0; pRealPlayHandle = new int[16]; pPlayBackHandle = new int[16]; pPlayBackChannelID = 0; deviceInfo = new NET_DEVICEINFO(); this.WindowState = FormWindowState.Normal; btnRealPlay.Enabled = false; btnPlayBackByTime.Enabled = false; gpbPlayBackControl.Enabled = false; btnUserLogout.Enabled = false; btnRealPlay.Text = StringUtil.ConvertString("RealPlay"); btnPlayByRecordFile.Enabled = false; gpbPlayBackControl.Enabled = false; gpbPTZControl.Enabled = false; } catch { MessageBox.Show("设备用户注销失败!", pMsgTitle); } }
/// <summary> /// 查询录像文件 /// </summary> /// <param name="lLoginID">设备用户登录句柄</param> /// <param name="nChannelId">通道ID</param> /// <param name="nRecordFileType">录像文件类型 </param> /// <param name="tmStart">录像开始时间</param> /// <param name="tmEnd">录像结束时间</param> /// <param name="pchCardid">卡号,只针对卡号查询有效,其他情况下可以填NULL</param> /// <param name="nriFileinfo">返回的录像文件信息,是一个NET_RECORDFILE_INFO结构[录像文件信息只有一条]</param> /// <param name="maxlen">nriFileinfo缓冲的最大长度;[单位字节大小为sizeof(NET_RECORDFILE_INFO)]</param> /// <param name="filecount">返回的文件个数,属于输出参数最大只能查到缓冲满为止的录像记录</param> /// <param name="waittime">等待时间</param> /// <param name="bTime">是否按时间查(目前无效)</param> /// <returns>true:成功;false:失败</returns> public static bool DHQueryRecordFile(int lLoginID, int nChannelId, RECORD_FILE_TYPE nRecordFileType, DateTime tmStart, DateTime tmEnd, string pchCardid, ref NET_RECORDFILE_INFO nriFileinfo, int maxlen, out int filecount, int waittime, bool bTime) { bool returnValue = false; filecount = 0; NET_RECORDFILE_INFO[] ntFileInfo = new NET_RECORDFILE_INFO[1]; returnValue = DHQueryRecordFile(lLoginID, nChannelId, nRecordFileType, tmStart, tmEnd, pchCardid, ref ntFileInfo, maxlen, out filecount, waittime, bTime); nriFileinfo = ntFileInfo[0]; DHThrowLastError(returnValue); return returnValue; }
private static extern int CLIENT_PlayBackByRecordFileEx(int lLoginID, ref NET_RECORDFILE_INFO lpRecordFile, IntPtr hWnd, fDownLoadPosCallBack cbDownLoadPos, IntPtr dwPosUser,fDataCallBack fDownLoadDataCallBack, IntPtr dwDataUser);
private static extern int CLIENT_DownloadByRecordFile(int lLoginID,ref NET_RECORDFILE_INFO lpRecordFile,string sSavedFileName, fDownLoadPosCallBack cbDownLoadPos, IntPtr dwUserData);
private static extern int CLIENT_PlayBackByRecordFile(int lLoginID, ref NET_RECORDFILE_INFO lpRecordFile, IntPtr hWnd, fDownLoadPosCallBack cbDownLoadPos, IntPtr dwUserData);
/// <summary> /// 按文件下载录像文件, 通过查询到的文件信息下载 /// </summary> /// <param name="lLoginID">CLIENT_Login的返回值</param> /// <param name="lpRecordFile">录像文件信息</param> /// <param name="sSavedFileName">要保存的录像文件名,全路径</param> /// <param name="cbDownLoadPos">下载进度回调函数</param> /// <param name="dwUserData">下载进度回调用户自定义数据</param> /// <returns>成功返回下载ID,失败返回0</returns> public static int DHDownloadByRecordFile(int lLoginID, NET_RECORDFILE_INFO lpRecordFile,string sSavedFileName, fDownLoadPosCallBack cbDownLoadPos, IntPtr dwUserData) { int intReturnValue = 0; intReturnValue=CLIENT_DownloadByRecordFile(lLoginID, ref lpRecordFile,sSavedFileName, cbDownLoadPos, dwUserData); DHThrowLastError(); return intReturnValue; }
/// <summary> /// 带数据回调的按录像文件回放扩展接口,每通道同一时间只能播放一则录像,不能同时播放同一通道的多条记录。窗口参数(hWnd)有效时回调数据的返回值将被忽略,窗口参数 (hWnd)为0时,需要注意回调函数的返回值,具体见回调函数说明。 /// </summary> /// <param name="lLoginID">CLIENT_Login的返回值</param> /// <param name="lpRecordFile">录像文件信息</param> /// <param name="hWnd">回放容器句柄</param> /// <param name="cbDownLoadPos">进度回调函数</param> /// <param name="dwPosUser">进度回调函数用户数据</param> /// <param name="fDownLoadDataCallBack">数据回调函数</param> /// <param name="dwDataUser">数据回调函数用户数据</param> /// <returns>成功返回网络回放ID,失败返回0</returns> public static int DHPlayBackByRecordFile(int lLoginID, ref NET_RECORDFILE_INFO lpRecordFile, IntPtr hWnd, fDownLoadPosCallBack cbDownLoadPos, IntPtr dwPosUser, fDataCallBack fDownLoadDataCallBack, IntPtr dwDataUser) { int returnValue; returnValue = CLIENT_PlayBackByRecordFileEx(lLoginID, ref lpRecordFile, hWnd, cbDownLoadPos, dwPosUser,fDownLoadDataCallBack,dwDataUser); DHThrowLastError(returnValue); return returnValue; }
//private void TimeDownLoadPosFun(int lPlayHandle, UInt32 dwTotalSize, UInt32 dwDownLoadSize, int index, NET_RECORDFILE_INFO recordfileinfo, IntPtr dwUser) //private void TimeDownLoadPosFun(int lPlayHandle, UInt32 dwTotalSize, UInt32 dwDownLoadSize, IntPtr dwUser) public void TimeDownLoadPosFun(int lPlayHandle, int dwTotalSize, int dwDownLoadSize, int index , NET_RECORDFILE_INFO recordfileinfo, IntPtr dwUser) { this.Invoke(setProgressPos, new object[] { lPlayHandle, (UInt32)dwTotalSize, (UInt32)dwDownLoadSize }); if (0xFFFFFFFF == dwDownLoadSize || 0xFFFFFFFE == dwDownLoadSize) { DHClient.DHStopDownload(lPlayHandle); } }
/// <summary> /// 按时间回放按钮按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlayBackByTime_Click(object sender, EventArgs e) { playBy = 1; frm_PlayBackByTimeSet fPBSet = new frm_PlayBackByTimeSet(); fPBSet.cmbChannelSelect.Items.Clear(); for (int i = 0; i < deviceInfo.byChanNum; i++) { fPBSet.cmbChannelSelect.Items.Add(i.ToString()); } fileInfo = new NET_RECORDFILE_INFO(); int fileCount = 0; bool blnQueryRecordFile = false; fPBSet.ShowDialog(); if (fPBSet.blnOKEnter == true) { DateTime startTime = fPBSet.dtpStart.Value; DateTime endTime = fPBSet.dtpEnd.Value; if (startTime.Date >= endTime.Date) { MessageBox.Show("开始日期不在结束日期设置前,请重新设置!", pMsgTitle); } else { blnQueryRecordFile = DHClient.DHQueryRecordFile(pLoginID, int.Parse(fPBSet.txtChannelID.Text.ToString()), RECORD_FILE_TYPE.ALLRECORDFILE, startTime, endTime, null, ref fileInfo, Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out fileCount, 5000, false);//按时间回放 if (blnQueryRecordFile == true) { if (picRealPlay == null) { picRealPlay = picRealPlay15; } pPlayBackChannelID = int.Parse(fPBSet.txtChannelID.Text.ToString()); pPlayBackHandle[pPlayBackChannelID] = DHClient.DHPlayBackByTime(pLoginID, pPlayBackChannelID, startTime, endTime, picRealPlay.Handle, null, IntPtr.Zero); if (pPlayBackHandle[pPlayBackChannelID] == 0) { MessageBox.Show("按时间回放失败!", pMsgTitle); } else { btnPlay.Text = "||"; //画面按钮有效性控制 btnPlayBackByTime.Enabled = false; gpbPlayBackControl.Enabled = true; btnPlay.Enabled = true; btnSlow.Enabled = true; btnStop.Enabled = true; btnFast.Enabled = true; btnSetpPlayS.Enabled = true; hsbPlayBack.Enabled = true; btnPlayByRecordFile.Enabled = false; } } } //MessageBox.Show(blnQueryRecordFile.ToString(),MsgTitle); } }
/// <summary> /// 按时间下载按钮按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownLoad2_Click(object sender, EventArgs e) { frm_PlayBackByTimeSet fPBSet = new frm_PlayBackByTimeSet(); NET_RECORDFILE_INFO fileInfo = new NET_RECORDFILE_INFO(); int fileCount = 0; bool blnQueryRecordFile = false; int pPlayBackChannelID=0; fPBSet.txtDevName.Text = strUserName; fPBSet.cmbChannelSelect.Items.Clear(); for (int i = 1; i <= deviceInfo.byChanNum; i++ ) { fPBSet.cmbChannelSelect.Items.Add(i); } fPBSet.ShowDialog(); if (fPBSet.blnOKEnter == true) { DateTime startTime = fPBSet.StartTime; DateTime endTime = fPBSet.EndTime; blnQueryRecordFile = DHClient.DHQueryRecordFile(pLoginID, int.Parse(fPBSet.txtChannelID.Text.ToString()), RECORD_FILE_TYPE.ALLRECORDFILE, startTime, endTime, null, ref fileInfo, Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out fileCount, 5000, false);//按时间回放 if (blnQueryRecordFile == true) { //**********按文件下载********** pPlayBackChannelID = int.Parse(fPBSet.txtChannelID.Text.ToString()); if (txtDirPath2.Text.Trim().Length > 0 && txtFileName2.Text.Trim().Length > 0) { string strFileName = txtFileName2.Text; strFileName = strFileName.ToLower(); if (!strFileName.EndsWith(".dav")) strFileName += ".dav"; // 关闭上次上次下载有关资源 if (pDownloadHandleByTime != 0) { DHClient.DHStopDownload(pDownloadHandleByTime); pDownloadHandle = 0; } pDownloadHandleByTime = DHClient.DHDownloadByTime(pLoginID, pPlayBackChannelID, 0, startTime , endTime, txtDirPath2.Text + @"\" + strFileName, timeDownLoadFun, IntPtr.Zero); if (pDownloadHandleByTime != 0) { btnDownLoad2.Tag = "下载中"; pDownloadHandle = pDownloadHandleByTime; btnDownLoad2.Enabled = false; btnDownLoad1.Enabled = false; btnStopDownLoad2.Enabled = true; MessageUtil.ShowMsgBox(StringUtil.ConvertString("开始下载!"), StringUtil.ConvertString(pMsgTitle)); } else { MessageUtil.ShowMsgBox(StringUtil.ConvertString(DHClient.LastOperationInfo.errMessage, "ErrorMessage"), StringUtil.ConvertString(pMsgTitle)); } } else { MessageUtil.ShowMsgBox(StringUtil.ConvertString("请输入有效的录像保存目录和文件名!"), StringUtil.ConvertString(pMsgTitle)); } //******************************* } else { MessageUtil.ShowMsgBox(StringUtil.ConvertString("这个时间段里没有录像文件供下载!"), StringUtil.ConvertString(pMsgTitle)); } } }
/// <summary> /// 查询录像文件 /// </summary> /// <param name="lLoginID">设备用户登录句柄</param> /// <param name="nChannelId">通道ID</param> /// <param name="nRecordFileType">录像文件类型 </param> /// <param name="tmStart">录像开始时间</param> /// <param name="tmEnd">录像结束时间</param> /// <param name="pchCardid">卡号,只针对卡号查询有效,其他情况下可以填NULL</param> /// <param name="nriFileinfo">返回的录像文件信息,是一个NET_RECORDFILE_INFO结构数组[录像文件信息为指定条]</param> /// <param name="maxlen">nriFileinfo缓冲的最大长度;[单位字节,大小为结构数组维数*sizeof(NET_RECORDFILE_INFO),数组维为大小等于1,建议小于200]</param> /// <param name="filecount">返回的文件个数,属于输出参数最大只能查到缓冲满为止的录像记录</param> /// <param name="waittime">等待时间</param> /// <param name="bTime">是否按时间查(目前无效)</param> /// <returns>true:成功;false:失败</returns> public static bool DHQueryRecordFile(int lLoginID, int nChannelId, RECORD_FILE_TYPE nRecordFileType, DateTime tmStart, DateTime tmEnd, string pchCardid, ref NET_RECORDFILE_INFO[] nriFileinfo, int maxlen, out int filecount, int waittime, bool bTime) { bool returnValue = false; filecount = 0; IntPtr pBoxInfo = IntPtr.Zero; try { NET_TIME timeStart = ToNetTime(tmStart); NET_TIME timeEnd = ToNetTime(tmEnd); pBoxInfo = Marshal.AllocHGlobal(maxlen);//分配固定的指定大小的内存空间 int fileCountMin = 0; if (pBoxInfo != IntPtr.Zero) { returnValue = CLIENT_QueryRecordFile(lLoginID, nChannelId, (int)nRecordFileType, ref timeStart, ref timeEnd, pchCardid, pBoxInfo, maxlen, out filecount, waittime, bTime); fileCountMin = (filecount <= nriFileinfo.Length ? filecount : nriFileinfo.Length); for (int dwLoop = 0; dwLoop < fileCountMin; dwLoop++) { //将指定内存空间的数据按指定格式复制到目的数组中 nriFileinfo[dwLoop] = (NET_RECORDFILE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pBoxInfo + Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)) * dwLoop), typeof(NET_RECORDFILE_INFO)); } } DHThrowLastError(returnValue); } catch (Exception e) { DHThrowLastError(e); returnValue= false; } finally { Marshal.FreeHGlobal(pBoxInfo);//释放固定内存分配 pBoxInfo = IntPtr.Zero; } return returnValue; }