📄 playerdlg.cpp
字号:
Hik_PlayM4_InitDDrawDevice();
Hik_PlayM4_SetDDrawDevice(PORT,0);
#endif
//Test adapter Capability;
TestCapability(0);
Hik_PlayM4_SetFileEndMsg(PORT,m_hWnd,WM_FILE_END);
Hik_PlayM4_SetEncChangeMsg(PORT,m_hWnd,WM_ENC_CHANGE);
if(m_strPlayFileName.Compare(""))
{
if(m_bStreamType)
OpenStream();
else
OpenFile();
}
UpdateData(FALSE);
m_bInitialized=TRUE;
SortControl();
return TRUE; // return TRUE unless you set the focus to a control
}
void CPlayerDlg::OnAppAbout()
{
// TODO: Add your command handler code here
CAboutDlg AboutDlg;
AboutDlg.DoModal();
}
void CPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CPlayerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
// SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
Hik_PlayM4_RefreshPlay(PORT);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPlayerDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
/////////////////////////////////////////////////////////////////////////////
//Function:Open file;
////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnFileOpen()
{
if(m_bOpen)
{
if(m_bStreamType)
CloseStream();
else
CloseFile();
}
if(!BrowseFile(&m_strPlayFileName))
return;
if(m_bStreamType)
OpenStream();
else
OpenFile();
m_bPicQuality=TRUE;
Hik_PlayM4_SetPicQuality(PORT,m_bPicQuality);
m_pMainMenu->CheckMenuItem(ID_QUALITY,MF_CHECKED );
}
void CPlayerDlg::OpenFile()
{
TRACE("Open fileNAME IS:%s",m_strPlayFileName);
Hik_PlayM4_SetFileRefCallBack(PORT,FileRefDone,(DWORD)this);
Hik_PlayM4_SetVerifyCallBack(PORT, 0, 0xffffffff, VerifyFun, (DWORD) this);// verify the whole file;
if(!Hik_PlayM4_OpenFile(PORT,m_strPlayFileName.GetBuffer(m_strPlayFileName.GetLength())))
{
m_strPlayFileName="";
CString csError;
csError.Format("Open file failed(%d)",Hik_PlayM4_GetLastError(PORT));
MessageBox(csError);
return ;
}
SetOpenState();
m_nMaxFileTime=Hik_PlayM4_GetFileTime(PORT);
if(!m_nMaxFileTime)
{
MessageBox("File seconds is zero");
return;
}
m_nTotalHour=m_nMaxFileTime/3600;
m_nTotalMinute=(m_nMaxFileTime%3600)/60;
m_nTotalSecond=m_nMaxFileTime%60;
m_nTotalFrames=Hik_PlayM4_GetFileTotalFrames(PORT);
numFrames=m_nTotalFrames;
//If you want to change the display buffer. Do hear!
//Hik_PlayM4_SetDisplayBuf(PORT,25);
Play();
SetWindowText((LPCTSTR) m_strPlayFileName);
}
void CPlayerDlg::OnDropFiles(HDROP hDropInfo)
{
// TODO: Add your message handler code here and/or call default
if(m_bOpen)
{
if(m_bStreamType)
CloseStream();
else
CloseFile();
}
DWORD nFileNameSize=DragQueryFile(hDropInfo,0,NULL,0);
char * sFileName=new char[nFileNameSize+1];
DragQueryFile(hDropInfo,0,sFileName,nFileNameSize+1);
m_strPlayFileName=sFileName;
if(m_bStreamType)
OpenStream();
else
OpenFile();
delete []sFileName;
CDialog::OnDropFiles(hDropInfo);
}
///////////////////////////////////////////////////////////////////////////////
//Funtion:Close file;
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnFileClose()
{
// TODO: Add your command handler code here
if(m_bStreamType)
CloseStream();
else
CloseFile();
m_bConvert=0;
//if(yuvBuf!=NULL)
//free(yuvBuf);
}
void CPlayerDlg::CloseFile()
{
Stop();
Hik_PlayM4_CloseFile(PORT);
SetCloseState();
m_bFileRefCreated= FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//Funtion:Play or change the play speed to normal;
///////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnPlay()
{
// TODO: Add your control notification handler code here
Play();
}
void CPlayerDlg::Play()
{
m_nSpeed=0;
OnThrow0();
//#ifdef _TEST_CALLBACK
if(m_bConvert)
Hik_PlayM4_SetDecCallBack(PORT,DecCBFun);
else
m_pMainMenu->EnableMenuItem(ID_FILE_CLOSE, FALSE);
//#endif
if(m_bPlaying)
{
Hik_PlayM4_Play(PORT,GetDlgItem(IDC_SHOW)->m_hWnd);
}
else
{
if(m_bStreamType)
{
::SetFilePointer(m_hStreamFile,m_nHeadSize,0,FILE_BEGIN);
Hik_PlayM4_ResetSourceBuffer(PORT);
SetEvent(m_hEventInput);
}
m_bPlaying = Hik_PlayM4_Play(PORT,GetDlgItem(IDC_SHOW)->m_hWnd);
m_bSound=Hik_PlayM4_PlaySound(PORT);
if(m_bPlaying)
SetTimer(PLAY_TIMER,500,NULL);
}
if(m_bPlaying)
SetPlayState();
else
{
CString csError;
csError.Format("Play the file faild.(%d)",Hik_PlayM4_GetLastError(PORT));
AfxMessageBox(csError);
}
}
//////////////////////////////////////////////////////////////////////////////
//Funtion:pause.
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnPause()
{
// TODO: Add your control notification handler code here
if(m_bPlaying)
{
m_bPause=!m_bPause;
Pause(m_bPause);
}
}
void CPlayerDlg::Pause(BOOL bPause)
{
if(m_bPaused == bPause)
return;
m_bPaused=bPause;
Hik_PlayM4_Pause(PORT,bPause);
TRACE("PAUSE %d\n",m_bPaused);
}
/////////////////////////////////////////////////////////////////////////////
//Function: Stop
/////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnStop()
{
// TODO: Add your control notification handler code here
if(m_bPlaying)
{
Stop();
}
if(m_bConvert)
{
if(outFile!=NULL)
closeWriffFiles();
if(yuvBuf!=NULL)
{
free(yuvBuf);
yuvBuf=NULL;
}
m_bConvert=0;
CSliderCtrl* pSlider;
pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDERB);
pSlider->EnableWindow(TRUE);
pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDERC);
pSlider->EnableWindow(TRUE);
pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDERS);
pSlider->EnableWindow(TRUE);
pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDERH);
pSlider->EnableWindow(TRUE);
pSlider=(CSliderCtrl*)GetDlgItem(IDC_PLAY_SLIDER);
pSlider->EnableWindow(TRUE);
}
}
void CPlayerDlg::Stop()
{
CButton *pButton;
if(!m_bPlaying)
return;
KillTimer(PLAY_TIMER);
if(Hik_PlayM4_StopSound())
{
m_bSound=FALSE;
pButton = (CButton *)GetDlgItem(IDC_SOUND);
pButton->SetIcon(m_hSoundStopIcon);
}
//continue before stop.Add by lgl at 9-19;
m_bPause=FALSE;
//stop
m_bPlaying = !Hik_PlayM4_Stop(PORT);
if(!m_bPlaying)
{
SetStopState();
if(m_bStreamType)
ResetEvent(m_hEventInput);
}
}
///////////////////////////////////////////////////////////////////////////////
//Funtion:Locate to the file head.
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnGotoStart()
{
// TODO: Add your control notification handler code here
if(m_bFileRefCreated)
Hik_PlayM4_SetCurrentFrameNum(PORT,0);
else
Hik_PlayM4_SetPlayPos(PORT,0);
}
///////////////////////////////////////////////////////////////////////////////
//Funtion:Locate to the end.
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnGotoEnd()
{
// TODO: Add your control notification handler code here
if(m_bFileRefCreated)
{
//Note: May create many WM_FILE_END message. The best way is to synchronize the option;
int nEndFrame=m_nTotalFrames;
while(!Hik_PlayM4_SetCurrentFrameNum(PORT,nEndFrame--))
{
//TRACE("FrameNum is :%d\n",nEndFrame);
if(nEndFrame==0)
break;
}
}
else
Hik_PlayM4_SetPlayPos(PORT,1);
}
//////////////////////////////////////////////////////////////////////////////
//Funtion: Fast
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnFastForward()
{
// TODO: Add your control notification handler code here
//Throw B-Frame ,improve the performance;
if(Hik_PlayM4_Fast(PORT))
{
m_nSpeed++;
if(m_nSpeed>0)
OnThrow2();
SetFastForwardState();
}
}
//////////////////////////////////////////////////////////////////////////////
//Funtion: Slow;
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnFastBackward()
{
// TODO: Add your control notification handler code here
if(Hik_PlayM4_Slow(PORT))
{
m_nSpeed--;
if(m_nSpeed<=0)
OnThrow0();
SetFastBackWardState();
}
}
//////////////////////////////////////////////////////////////////////////////
//Function:Borwse the file to play.
//////////////////////////////////////////////////////////////////////////////
BOOL CPlayerDlg::BrowseFile(CString *strFileName)
{
CFileDialog dlg(TRUE,
"mpg",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Hikvision文件(*.mp4;*.264)|*.mp4;*.264|所有文件(*.*)|*.*||", this);
if(dlg.DoModal() == IDCANCEL)
{
return FALSE;
}
*strFileName = dlg.GetPathName();
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//Funtion:change the video size to full-screen or normal.
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnViewFullscreen()
{
// TODO: Add your command handler code here
CButton *pButton;
m_bFullScreen = !m_bFullScreen;
CStatic* pStatic;
//HWND hAppBar;
if(m_bFullScreen)
{
//hAppBar = FindWindowEx(0,0,"Shell_TrayWnd","");
//::ShowWindow(hAppBar,SW_HIDE);
//Save the pre info;
GetWindowPlacement(&m_OldWndpl);
//Remove WS_SIZEBOX windows style. or not the window can't be full-creen.
ModifyStyle(WS_SIZEBOX,0,0);
CRect WindowRect, ClientRect;
RECT m_FullScreenRect;
//ReDraw the window. Get the correct edge value.
GetWindowRect(&WindowRect);
WindowRect.left+=1;
WindowRect.right+=1;
MoveWindow(CRect(0,0,352,288),TRUE);
GetWindowRect(&WindowRect);
GetClientRect(&ClientRect);
ClientToScreen(&ClientRect);
//get the dest window rect.
m_FullScreenRect.left = WindowRect.left - ClientRect.left;
m_FullScreenRect.top = WindowRect.top - ClientRect.top;
m_FullScreenRect.right = WindowRect.right - ClientRect.right + m_nScreenWidth;
m_FullScreenRect.bottom = WindowRect.bottom - ClientRect.bottom + m_nScreenHeight;
//Move the main window to the dest rect.
WINDOWPLACEMENT wndpl;
wndpl.length = sizeof(WINDOWPLACEMENT);
wndpl.flags = 0;
wndpl.showCmd = SW_SHOWNORMAL;
wndpl.rcNormalPosition = m_FullScreenRect;
SetWindowPlacement(&wndpl);
//Move the view winow to full-screen.
RECT rc;
GetClientRect(&rc);
GetDlgItem(IDC_SHOW)->MoveWindow(&rc,TRUE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -