📄 videoplaydlg.cpp
字号:
// TODO: Add your control notification handler code here
m_bMute = TRUE;
#ifdef TESTPLAYER
m_Player.SetVolume(VOL_SILENCE);
#endif
m_btnMute.ShowWindow(SW_SHOW);
m_btnVol.ShowWindow(SW_HIDE);
}
void CVideoPlayDlg::GetVideoDuration()
{
#ifdef TESTPLAYER
m_Player.GetMediaDuration(m_dDuration);
#endif
}
void CVideoPlayDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
#ifdef TESTPLAYER
LONG lRemainingSecs;
double rate = 0.0, llCurDur= 0.0;
TCHAR chDuration[MAX_STRING];
TCHAR chCurTime[MAX_STRING];
CRect btnRect;
if((nIDEvent == TIME_VIDEO_SECID)&&(m_Player.play_state == STATE_PLAY))
{
//change this to get_curtime
m_Player.GetMediaCurrPos(llCurDur);
//calculate time
lRemainingSecs = (LONG)llCurDur;
m_nTimeHour = (int)lRemainingSecs / 3600; // 3600 seconds in the hour
lRemainingSecs = lRemainingSecs % 3600;
m_nTimeMin = (int)lRemainingSecs / 60; // 60 seconds in the minute
lRemainingSecs = lRemainingSecs % 60;
m_nTimeSec = (int)lRemainingSecs;
wsprintf(chCurTime, L"%02d:%02d:%02d", m_nTimeHour, m_nTimeMin, m_nTimeSec );
wsprintf(chDuration, L"%02d:%02d:%02d", (int)m_dDuration/3600,(int)m_dDuration/60,(int)m_dDuration%60);
DisplayTime(chDuration,chCurTime);
//calculate progress slider position
rate = llCurDur/m_dDuration;
m_sliderPro.GetClientRect(&btnRect);
//set position
m_sliderPro.SetPos((int)(rate*m_nProWidth));
m_Player.checkautostop();
}
else if((nIDEvent == TIME_VIDEO_SECID)&&(m_Player.play_state == STATE_INIT))
{
printf("video complete stop \n");
OnStop();
// OnNextFile();
}
#endif
CDialog::OnTimer(nIDEvent);
}
void CVideoPlayDlg::ResetTimeAndSlider()
{
//reset time and slider
TCHAR chDuration[MAX_STRING];
TCHAR chCurTime[MAX_STRING];
CRect btnRect;
m_nTimeHour = 0;
m_nTimeMin = 0;
m_nTimeSec = 0;
//time
wsprintf(chDuration, L"%02d:%02d:%02d",
(int)m_dDuration/3600,(int)m_dDuration/60,(int)m_dDuration%60);
wcscpy(chCurTime, L"00:00:00");
DisplayTime(chDuration,chCurTime);
//slider
m_sliderPro.SetPos(0);
}
void CVideoPlayDlg::DisplayTime(TCHAR* TotalTime,TCHAR* CurTime)
{
TCHAR TmpChar[MAX_STRING];
//display time
wcscpy(TmpChar,CurTime);
wcscat(TmpChar,L"/");
wcscat(TmpChar,TotalTime);
m_Time.SetWindowText(TmpChar);
}
void CVideoPlayDlg::DisplayTitle()
{
m_Title.SetWindowText(GetFileName(m_chFileName));
}
void CVideoPlayDlg::OnOpenFile()
{
// TODO: Add your control notification handler code here
CFileListDlg dlg(this);
//get file list dlg
m_VideoList = &dlg;
dlg.DoModal();
//get current full file name
if(m_VideoList->m_chCurFilename[0]!=0)
{
//m_chFileName is full file name
wcscpy(m_chFileName, m_VideoList->m_chCurFilename);
VideoPlay();
}
Invalidate();
}
TCHAR* CVideoPlayDlg::GetFileName(TCHAR* chFullFileName)
{
if (chFullFileName == NULL || chFullFileName[0] == 0)
return NULL;
int siLen = wcslen(chFullFileName);
for(int i = siLen - 1; i >= 0; --i)
{
if(chFullFileName[i] == '\\')
break;
}
return chFullFileName + i + 1;
}
void CVideoPlayDlg::OnNextFile()
{
// TODO: Add your control notification handler code here
CString Str;
if(m_chFileName[0])
{
if(g_nCurSelItem+1<g_StrList.GetCount())
{
g_nCurSelItem++;
Str = g_StrList.GetAt(g_StrList.FindIndex(g_nCurSelItem));
//get current full file name
wcscpy(m_chFileName,Str);
//then open it
VideoPlay();
}
}
}
void CVideoPlayDlg::OnLastFile()
{
// TODO: Add your control notification handler code here
CString Str;
if(m_chFileName[0])
{
if(g_nCurSelItem>0)
{
g_nCurSelItem--;
Str = g_StrList.GetAt(g_StrList.FindIndex(g_nCurSelItem));
//get current full file name
wcscpy(m_chFileName,Str);
//then open it
VideoPlay();
}
}
}
HBRUSH CVideoPlayDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_STATIC)
{
int ID = pWnd->GetDlgCtrlID();
pDC->SetBkMode(TRANSPARENT);
switch(ID)
{
case IDC_STATIC_TITLE:
hbr = CreateSolidBrush(COLOR_BLUE);
pDC->SetTextColor(COLOR_YELLOW);
break;
case IDC_STATIC_TIME:
hbr = CreateSolidBrush(COLOR_BLUE);
pDC->SetTextColor(COLOR_YELLOW);
break;
case IDC_VIDEO_WINDOWS:
hbr = CreateSolidBrush(COLOR_BLACK);
break;
}
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
LRESULT CVideoPlayDlg::OnBitmapSliderMoved(WPARAM wParam, LPARAM lParam)
{
double dRate = 0.0;
int nPos = 0, nLeftVol = 0, nRightVol = 0;
if(m_chFileName[0] == 0)
return 0;
if( wParam == IDC_SLIDER_VOL)
{
m_nPos = m_sliderVol.GetPos();
m_sliderVol.SetPos(m_nPos);
//only m_bMute is false
if(m_bMute == FALSE)
{
//calculate rate
dRate = (double)m_nPos/m_nVolWidth;
//delete this for OS volume
// nLeftVol = nRightVol = (int)(0xffff*dRate);
// m_nVolume = nLeftVol<<16|nRightVol;
//for change audio volume
m_nVolume = (LONG)(dRate*(VOL_FULL-VOL_SILENCE)+VOL_SILENCE);
#ifdef TESTPLAYER
m_Player.SetVolume(m_nVolume);
#endif
}
}
else if(wParam == IDC_SLIDER_PRO)
{
m_nPos = m_sliderPro.GetPos();
//set new position
m_sliderPro.SetPos(m_nPos);
//calculate rate
dRate = (double)m_nPos/m_nProWidth;
#ifdef TESTPLAYER
m_Player.SetMediaPos(m_dDuration*dRate);
#endif
}
return 0;
}
LRESULT CVideoPlayDlg::OnBitmapSliderMoving(WPARAM wParam, LPARAM lParam)
{
if( wParam == IDC_SLIDER_PRO )
{
OnBitmapSliderMoved(wParam,lParam);
}
return 0;
}
void CVideoPlayDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
#ifdef TESTPLAYER
if(m_Player.play_state != STATE_PLAY)
return;
#endif
if(PtInRect(&m_videoWindow, point))
{
SwitchFullScreen();
RECT s={0, (VIDEO_HEIGHT - 56), VIDEO_WIDTH, VIDEO_HEIGHT};
InvalidateRect(&s,true);
}
CDialog::OnLButtonDown(nFlags, point);
}
// switch full screen mode
void CVideoPlayDlg::SwitchFullScreen()
{
if (m_fullScreen)
{
m_videoWindow.left = VIDEO_PLAY_LEFT;
m_videoWindow.top = VIDEO_PLAY_TOP;
m_videoWindow.right = VIDEO_PLAY_RIGHT;
m_videoWindow.bottom = VIDEO_PLAY_BOTTOM;
DisplayAllControls(TRUE);
}
else // Full screen
{
// if not playing, full-screen mode is not allowed
#ifdef TESTPLAYER
if (m_Player.play_state != STATE_PLAY)
return;
#endif
m_videoWindow.left = VIDEO_PLAY_LEFT;
m_videoWindow.top = VIDEO_PLAY_TOP;
m_videoWindow.right = VIDEO_WIDTH;
m_videoWindow.bottom = VIDEO_HEIGHT;
DisplayAllControls(FALSE);
}
m_fullScreen = !m_fullScreen;
#ifdef TESTPLAYER
m_Player.fullscreen(m_fullScreen);
#endif
}
// make all controls visible/invisible
void CVideoPlayDlg::DisplayAllControls(BOOL flag)
{
unsigned int n_switch;
if (flag == TRUE)
n_switch = SW_SHOW;
else
n_switch = SW_HIDE;
// progress bar
m_sliderPro.ShowWindow(n_switch);
// buttons
#ifdef TESTPLAYER
if(m_Player.play_state == STATE_PLAY)
m_btnPause.ShowWindow(n_switch);
else
m_btnPlay.ShowWindow(n_switch);
#endif
m_btnClose.ShowWindow(n_switch);
m_btnBackward.ShowWindow(n_switch);
m_btnStop.ShowWindow(n_switch);
m_btnForward.ShowWindow(n_switch);
m_btnOpen.ShowWindow(n_switch);
m_Title.ShowWindow(n_switch);
m_Time.ShowWindow(n_switch);
}
//this only for OS volume
void IncreaseVolume()
{
DWORD m_curVolume=0;
waveOutGetVolume(0,(unsigned long*)&m_curVolume);
m_curVolume += VOL_SET_STEP;
if (m_curVolume > VOL_FULL) m_curVolume = VOL_FULL;
waveOutSetVolume(0, m_curVolume);
}
void DecreaseVolume()
{
DWORD m_curVolume=0;
waveOutGetVolume(0,(unsigned long*)&m_curVolume);
m_curVolume -= VOL_SET_STEP;
if (m_curVolume < VOL_SILENCE) m_curVolume = VOL_SILENCE;
waveOutSetVolume(0, m_curVolume);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -