remotefileplay.cpp

来自「监控开发资料,提供二次开发源码和使用说明书」· C++ 代码 · 共 1,188 行 · 第 1/3 页

CPP
1,188
字号
		if(nCurrentTime >= m_nFileTime)
		{
			nCurrentTime = m_nFileTime;
		}
		nHour=(nCurrentTime/3600)%24;
		nMinute=(nCurrentTime%3600)/60;
		nSecond=nCurrentTime%60;
		NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYGETFRAME, 0, &nCurrentFrame);
		if(nCurrentFrame>m_nTotalFrames)
			nCurrentFrame = m_nTotalFrames;
		csText.Format("%d/%d  %02d:%02d:%02d/%02d:%02d:%02d  %s",nCurrentFrame,m_nTotalFrames,nHour,nMinute,nSecond,m_nTotalHour,m_nTotalMinute,m_nTotalSecond,filename);
		GetDlgItem(IDC_PLAYSTATUS)->SetWindowText(csText);
		 
		NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYGETPOS, 0, &nPos1);
		if(nPos1 > 100)		//由于网络原因或DVR忙,回放异常终止
		{
			F_StopPlay();
			AfxMessageBox("由于网络原因或DVR忙,回放异常终止!");
		}
		else
		{
			m_ctlProgress.SetPos(nPos1);
			if(nPos1 == 100)
			{
				F_StopPlay();
				TRACE("回放文件结束!");
			}
		}	
		
		if(NET_DVR_GetPlayBackOsdTime(m_nPlayHandle, &OsdTime))
		{
			//TRACE("OSDTime: %04d%02d%02d%02d%02d%02d", OsdTime.dwYear, OsdTime.dwMonth,OsdTime.dwDay,OsdTime.dwHour,OsdTime.dwMinute,OsdTime.dwSecond);
		}
		break;
	default:
		break;
	}
	CDialog::OnTimer(nIDEvent);
}

void CRemoteFilePlay::OnSearchlist() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	if(!m_bSearchDown)
	{
		NET_DVR_TIME StartTime;
		NET_DVR_TIME StopTime;

		iSelServer = m_ServerCtrl.GetCurSel()-1;
		m_iChannel = m_ChannelCtrl.GetCurSel()+m_lStartChan;
		iFileType = m_FileType.GetCurSel();
		StartTime.dwYear = (WORD)m_ctDateStart.GetYear();
		StartTime.dwMonth = (WORD)m_ctDateStart.GetMonth();
		StartTime.dwDay = (WORD)m_ctDateStart.GetDay();
		StartTime.dwHour = (char)m_ctTimeStart.GetHour();
		StartTime.dwMinute = (char)m_ctTimeStart.GetMinute();
		StartTime.dwSecond = (char)m_ctTimeStart.GetSecond();
		StopTime.dwYear = (WORD)m_ctDateStop.GetYear();
		StopTime.dwMonth = (WORD)m_ctDateStop.GetMonth();
		StopTime.dwDay = (WORD)m_ctDateStop.GetDay();
		StopTime.dwHour = (char)m_ctTimeStop.GetHour();
		StopTime.dwMinute = (char)m_ctTimeStop.GetMinute();
		StopTime.dwSecond = (char)m_ctTimeStop.GetSecond();
		
		m_lServerType = serverinfo[iSelServer].m_wServerType;
		if(m_lServerType == 2) //ATM DVR
		{
			BYTE cTemp[CARDNUM_LEN];
			memcpy(cTemp, m_sCardNum, CARDNUM_LEN);
			if(iFileType == 0)
			{
				iFileType = 0xFF;
			}
			else
			{
				iFileType -= 1;
			}
			m_lFileHandle = NET_DVR_FindFileByCard(m_lServerID,m_iChannel,iFileType, FALSE, cTemp, &StartTime, &StopTime);
		}
		if(m_lServerType == 1)  //DVR
		{
			if(iFileType == 0)
			{
				iFileType = 0xFF;
			}
			else
			{
				iFileType -= 1;
			}
			m_lFileHandle = NET_DVR_FindFile(m_lServerID,m_iChannel,iFileType, &StartTime, &StopTime);
		}
		
		if(m_lFileHandle < 0)
		{
			AfxMessageBox("获取文件列表失败!");
			CString sTemp;
			sTemp.Format("ERROR: NET_DVR_FindFile = %d",NET_DVR_GetLastError());
			TRACE(sTemp);
			return;
		}
		m_Filelist.DeleteAllItems();
		m_bFindFile = TRUE;
		DWORD dwThreadId;
		if(m_hFileThread == NULL)
			m_hFileThread = CreateThread(NULL,0,LPTHREAD_START_ROUTINE(GetFileThread),this,0,&dwThreadId);		
		if(m_hFileThread == NULL)
		{
			AfxMessageBox("打开线程失败!");
			return;
		}
		GetDlgItem(IDC_SEARCHLIST)->SetWindowText("停止查找");
		m_bSearchDown = TRUE;
		GetDlgItem(IDC_STATICSTATE)->ShowWindow(SW_SHOW);
	}
	else
	{
		if(m_hFileThread)
		{
			TerminateThread(m_hFileThread, 0);
		}
		CloseHandle(m_hFileThread);
		m_hFileThread = NULL;
		NET_DVR_FindClose(m_lFileHandle);
		
		GetDlgItem(IDC_SEARCHLIST)->SetWindowText("查找");
		m_bSearchDown = FALSE;
		GetDlgItem(IDC_STATICSTATE)->ShowWindow(SW_HIDE);
		m_iFileNum = 0;
	}

}

void CRemoteFilePlay::OnDownload()  
{
	// TODO: Add your control notification handler code here
	CString csFileName;
	CString csStartTime, csStopTime;
	CString csTemp,csDir;
	char nFileName[256];
	POSITION  pos;
	int fileselpos = 0;
//	VERIFYINFO strVerifyInfo;
	int m_nVerifyret = -1;
	
	UpdateData(TRUE);
	if(!m_bDown)
	{
		pos = m_Filelist.GetFirstSelectedItemPosition();
		if(pos == NULL)
		{
			AfxMessageBox("请选择要下载的文件!");
			return;
		}
		fileselpos = m_Filelist.GetNextSelectedItem(pos);
		csFileName.Format("%s",m_Filelist.GetItemText(fileselpos,0));
		if(csFileName.IsEmpty())
			return;
		csStartTime.Format("%s",m_Filelist.GetItemText(fileselpos,2));
		csStopTime.Format("%s",m_Filelist.GetItemText(fileselpos,3));
		sprintf(filenamedownload,"%s",csFileName);

		csDir.Format("%s\\",hikClientParam.m_csDownLoadPath);
		sprintf(nFileName,"%s%s_%02d_D%s_%s.mp4",csDir,serverinfo[iSelServer].m_csServerIP, m_iChannel,csStartTime,csStopTime);
		TRACE("Download file name: %s \n", nFileName);

		lFileHandle = NET_DVR_GetFileByName(m_lServerID,filenamedownload,nFileName);
		if(lFileHandle >= 0)
		{
			NET_DVR_PlayBackControl(lFileHandle, NET_DVR_PLAYSTART, 0, NULL);
			GetDlgItem(IDC_DOWNLOAD)->SetWindowText("停止下载");
			m_downProgress.SetPos(0);
			m_downProgress.ShowWindow(SW_SHOW);
			m_bDown=TRUE;
			m_staticdownload.Format("正在下载文件%s", filenamedownload);
			GetDlgItem(IDC_STATICSTATE2)->ShowWindow(SW_SHOW);
			SetTimer(DOWNSTATE_TIMER,200,NULL);
		}
		else
		{
			AfxMessageBox("下载文件失败!");
			CString sTemp;
			sTemp.Format("ERROR: NET_DVR_GetFileByName = %d",NET_DVR_GetLastError());
			TRACE(sTemp);
			return;
		}
	}
	else 
	{
		NET_DVR_StopGetFile(lFileHandle);
		m_bDown=FALSE;
		GetDlgItem(IDC_DOWNLOAD)->SetWindowText("下载");
		KillTimer(DOWNSTATE_TIMER);
		Invalidate(TRUE);
		m_downProgress.SetPos(0);
		m_downProgress.ShowWindow(SW_HIDE);
		m_staticdownload.Format("停止下载文件%s", filenamedownload);
		GetDlgItem(IDC_STATICSTATE2)->ShowWindow(SW_HIDE);
	}
	UpdateData(FALSE);
}

void CRemoteFilePlay::OnPlayFile() 
{
	// TODO: Add your control notification handler code here
	if(m_nPlayHandle == -1)
	{
		F_Play();
	}
	else
	{
		if(m_bPause)
		{
			if(NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYRESTART, 0, NULL))
			{
				m_bPause=FALSE;
				F_SetPlayState();
			}
		}
		else
		{
			if(m_bSetFrame)
			{
				if(NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYNORMAL, 0, NULL))
				{
					TRACE("handle:%d \n",m_nPlayHandle);
					m_bSetFrame=FALSE;
					F_SetPlayState();
				}
			}
			else
			{
				if(NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYPAUSE, 0, NULL))
				{
					TRACE("handle:%d \n",m_nPlayHandle);
					m_bPause=TRUE;
					F_SetPauseState();
				}
			}
			
		}
	}
}

void CRemoteFilePlay::OnStop() 
{
	// TODO: Add your control notification handler code here
	F_StopPlay();	
}

void CRemoteFilePlay::OnSlow() 
{
	// TODO: Add your control notification handler code here
	NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYSLOW, 0, NULL);
}

void CRemoteFilePlay::OnFast() 
{
	// TODO: Add your control notification handler code here
	NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYFAST, 0, NULL);
}

void CRemoteFilePlay::OnCappic() 
{
	// TODO: Add your control notification handler code here
	char cFilename[256];
	
	sprintf(cFilename, "%s\\%d_%d.bmp",hikClientParam.m_csPictureSavePath,m_iChannel, GetTickCount());
	if(NET_DVR_PlayBackCaptureFile(m_nPlayHandle,cFilename))
	{
		CString sTemp;	
		sTemp.Format("抓图成功 %s!",cFilename);
		AfxMessageBox(sTemp);
		return;
	}
	else
	{
		AfxMessageBox("抓图失败!");
	}
}

void CRemoteFilePlay::OnStepback() 
{
	// TODO: Add your control notification handler code here
	NET_DVR_PlayBackControl(m_nPlayHandle,NET_DVR_PLAYSETPOS, 0, NULL);
}

void CRemoteFilePlay::OnStep() 
{
	// TODO: Add your control notification handler code here
	if(NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYFRAME, 0, NULL))
	{
		CButton *pButton;	
		pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
		pButton->SetIcon(m_hPlayEnableIcon);
		pButton->EnableWindow(TRUE);
		m_bSetFrame = TRUE;
	}
}

void CRemoteFilePlay::OnSound() 
{
	// TODO: Add your control notification handler code here
	CButton *pButton;
	
	if(m_bSound)
	{
		if(NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYSTARTAUDIO, 0, NULL))
		{
			m_bSound=FALSE;
			pButton = (CButton *)GetDlgItem(IDC_SOUND);
			pButton->SetIcon(m_hSoundStopIcon);
		}
	}
	else
	{		
		if(NET_DVR_PlayBackControl(m_nPlayHandle, NET_DVR_PLAYSTARTAUDIO, 0, NULL))
		{
			pButton = (CButton *)GetDlgItem(IDC_SOUND);
			pButton->SetIcon(m_hSoundStartIcon);
			m_bSound=TRUE;
		}
	}	
}

void CRemoteFilePlay::F_InitUI()
{
	// 初始化按钮
	CButton *pButton;
	
	m_rcScreen=CRect(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
	//初始化滑动条

	pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
	pButton->SetIcon(m_hPlayDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_STOP);
	pButton->SetIcon(m_hStopDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_FAST);
	pButton->SetIcon(m_hFastDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_SLOW);
	pButton->SetIcon(m_hSlowDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_STEP);
	pButton->SetIcon(m_hStepDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_STEPBACK);
	pButton->SetIcon(m_hStepBackDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_CAPPIC);
	pButton->SetIcon(m_hCaptureIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_SOUND);
	pButton->SetIcon(m_hSoundStopIcon);
	pButton->EnableWindow(FALSE);
}

void CRemoteFilePlay::F_SetStopState()
{
	CButton *pButton;
	
	m_ctlProgress.SetPos(0);
	m_ctlProgress.EnableWindow(FALSE);
	m_ctlVolume.EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
	pButton->SetIcon(m_hPlayEnableIcon);
	pButton->EnableWindow(TRUE);
	
	pButton = (CButton *)GetDlgItem(IDC_STOP);
	pButton->SetIcon(m_hStopDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_FAST);
	pButton->SetIcon(m_hFastDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_SLOW);
	pButton->SetIcon(m_hSlowDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_STEP);
	pButton->SetIcon(m_hStepDisableIcon);
	pButton->EnableWindow(FALSE);
	
	pButton = (CButton *)GetDlgItem(IDC_STEPBACK);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?