📄 simpleplayerdlg.cpp
字号:
// TODO: Add your control notification handler code here
m_FilterGraph->Pause();
CString PreFile;
CString PreName;
if(m_FilterGraph!=NULL)
{
unsigned short *pPreFile = fnFileViewer_PreviousFile();
unsigned short *pPreName = fnFileViewer_GetCurFileName();
FileName1=pPreName;
m_text.SetWindowText(FileName1);
wcscpy(PreFile.GetBuffer(128), pPreFile);
CSimplePlayerDlg::CreateGraph(PreFile);
GetDlgItem(IDC_VIDEO_WINDOW)->EnableWindow(TRUE);
DisplayFileDuration();
KillTimer(m_RollTimer);
len=FileName1.GetLength();
m_nCount=len;
if(len>=9)
{
CString pp=L" ";
pp=pp+FileName1;
FileName1=pp;
len=FileName1.GetLength();
m_RollTimer=SetTimer(ROLL_TIMER, 300, NULL);
}
else
{
m_text.SetWindowText(FileName1);
}
ButtonPlayPause.LoadBitmaps(IDB_PAUSE1,IDB_PAUSE0);
ButtonPlayPause.RedrawWindow();
m_flag1=false;
m_FilterGraph->SetAudioVol(nowshow*4369);
SaveVolume();
m_FilterGraph->Run();
if (m_SliderTimer == 0)
{
m_SliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
}
}
}
void CSimplePlayerDlg::OnButtonNext()
{
// TODO: Add your control notification handler code here
m_FilterGraph->Pause();
CString NextFile;
CString NextName;
if(m_FilterGraph!=NULL)
{
unsigned short *pNextFile = fnFileViewer_NextFile();
unsigned short *pNextName = fnFileViewer_GetCurFileName();
FileName1=pNextName;
m_text.SetWindowText(FileName1);
wcscpy(NextFile.GetBuffer(128), pNextFile);
CSimplePlayerDlg::CreateGraph(NextFile);
GetDlgItem(IDC_VIDEO_WINDOW)->EnableWindow(TRUE);
DisplayFileDuration();
KillTimer(m_RollTimer);
len=FileName1.GetLength();
m_nCount=len;
if(len>=9)
{
CString pp=L" ";
pp=pp+FileName1;
FileName1=pp;
len=FileName1.GetLength();
m_RollTimer=SetTimer(ROLL_TIMER, 300, NULL);
}
else
{
m_text.SetWindowText(FileName1);
}
ButtonPlayPause.LoadBitmaps(IDB_PAUSE1,IDB_PAUSE0);
ButtonPlayPause.RedrawWindow();
m_flag1=false;
m_FilterGraph->SetAudioVol(nowshow*4369);
SaveVolume();
m_FilterGraph->Run();
if (m_SliderTimer == 0)
{
m_SliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
}
}
}
void CSimplePlayerDlg::DestroyGraph(void)
{
if(m_FilterGraph)
{
// Stop the filter graph first
m_FilterGraph->Stop();
m_FilterGraph->SetNotifyWindow(NULL);
delete m_FilterGraph;
m_FilterGraph = NULL;
}
}
void CSimplePlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if( nIDEvent==m_RollTimer)
{
CString str=FileName1.Right(m_nCount--);
m_ptext=str;
UpdateData(false);
if(m_nCount<=0)
{
m_nCount=len;
}
}
if(m_SliderGraph.GetPos()==0&&m_FilterGraph->IsRunning())
{
GetDlgItem(IDC_VIDEO_WINDOW)->ShowWindow(SW_SHOW);
}
if(m_SliderGraph.GetPos()==1000&&m_FilterGraph->IsRunning())
{
if(m_FilterGraph->GetFullScreen()==1)
{
m_FilterGraph->SetFullScreen(FALSE);
m_FilterGraph->SetDisplayWindow(m_VideoWindow.GetSafeHwnd());
m_FilterGraph->SetNotifyWindow(this->GetSafeHwnd());
}
else
{
m_SliderGraph.SetPos(0);
m_FilterGraph->SetCurrentPosition(0);
m_SliderGraph.SetSelection(0, m_SliderGraph.GetPos());
m_SliderGraph.SetSelectionColor(RGB(85, 145, 225));
m_flag1=true;
m_FilterGraph->Pause();
ButtonPlayPause.LoadBitmaps(IDB_PLAY1,IDB_PLAY0);
ButtonPlayPause.RedrawWindow();
}
}
if(value==1)
{
if(card!=1)
{
if (nIDEvent == m_SliderTimer && m_FilterGraph)
{
double pos = 0, duration = 1.;
m_FilterGraph->GetCurrentPosition(&pos);
m_FilterGraph->GetDuration(&duration);
// Get the new position, and update the slider
int newPos = int(pos * 1000 / duration);
if (m_SliderGraph.GetPos() != newPos)
{
m_SliderGraph.SetPos(newPos);
m_SliderGraph.SetSelection(0, m_SliderGraph.GetPos());
m_SliderGraph.SetSelectionColor(RGB(85, 145, 225));
}
}
ReadMediaPosition();
}
}
else
{
if(m_FilterGraph->GetFullScreen()==1)
m_FilterGraph->SetFullScreen(FALSE);
m_FilterGraph->Pause();
GetDlgItem(IDC_VIDEO_WINDOW)->ShowWindow(SW_HIDE);
}
CDialog::OnTimer(nIDEvent);
}
void CSimplePlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if (pScrollBar->GetSafeHwnd() == m_SliderGraph.GetSafeHwnd())
{
m_SliderGraph.SetSelection(0, m_SliderGraph.GetPos());
m_SliderGraph.SetSelectionColor(RGB(85, 145, 225));
if (m_FilterGraph->IsPaused())
{
// Calculate the current seeking position
double duration = 1.;
m_FilterGraph->GetDuration(&duration);
double pos = duration * m_SliderGraph.GetPos() / 1000.;
m_FilterGraph->SetCurrentPosition(pos);
}
else
{
m_FilterGraph->Pause();
double duration = 1.;
m_FilterGraph->GetDuration(&duration);
double pos = duration * m_SliderGraph.GetPos() / 1000.;
m_FilterGraph->SetCurrentPosition(pos);
m_FilterGraph->Run();
}
}
else if(pScrollBar->GetSafeHwnd() == m_SliderVolume.GetSafeHwnd())
{
m_SliderVolume.SetSelection(0, m_SliderVolume.GetPos());
m_SliderVolume.SetSelectionColor(RGB(85, 145, 225));
int pos;
AudiuAmpFactor = 0x0;
pos=m_SliderVolume.GetPos();
nowshow=pos;
if(pos>0)
{
for(int i=0;i<pos;i++)
AudiuAmpFactor += 0x1111;
}
MMRESULT ret=waveOutSetVolume(0, AudiuAmpFactor);
SaveVolume();
}
else
{
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
}
BOOL CSimplePlayerDlg::OnEraseBkgnd(CDC* pDC)
{
// Intercept background erasing for the movie window, since the
// video renderer will keep the screen painted. Without this code,
// your video window might get painted over with gray (the default
// background brush) when it is obscured by another window and redrawn.
CRect rc;
// Get the bounding rectangle for the movie screen
m_VideoWindow.GetWindowRect(&rc);
ScreenToClient(&rc);
// Exclude the clipping region occupied by our movie screen
pDC->ExcludeClipRect(&rc);
// Erase the remainder of the dialog as usual
return CDialog::OnEraseBkgnd(pDC);
}
void CSimplePlayerDlg::OnButtonStop()
{
// TODO: Add your control notification handler code here
m_FilterGraph->Pause();
if (m_FilterGraph)
{
m_SliderGraph.SetPos(0);
m_FilterGraph->SetCurrentPosition(0);
m_SliderGraph.SetSelection(0, 0);
m_SliderGraph.SetSelection(0, m_SliderGraph.GetPos());
m_SliderGraph.SetSelectionColor(RGB(85, 145, 225));
m_FilterGraph->Stop();
// Show the first frame
m_FilterGraph->Pause();
// Stop the timer
if (m_SliderTimer)
{
KillTimer(m_SliderTimer);
m_SliderTimer = 0;
}
}
// Reset slider bar and position label back to zero
ReadMediaPosition();
m_flag1=true;
ButtonPlayPause.LoadBitmaps(IDB_PLAY1,IDB_PLAY0);
ButtonPlayPause.RedrawWindow();
}
void CSimplePlayerDlg::ScreenZoom()
{
if (m_flag&&m_FilterGraph)
{
m_flag=FALSE;
fnVolumnAdjust_SendPaintMsgInvalid();
m_FilterGraph->SetFullScreen(TRUE);
m_FilterGraph->SetDisplayWindow(m_VideoWindow.GetSafeHwnd());
m_FilterGraph->SetNotifyWindow(this->GetSafeHwnd());
}
else
{
m_flag=TRUE;
m_FilterGraph->SetFullScreen(FALSE);
fnVolumnAdjust_SendPaintMsgValid();
m_FilterGraph->SetDisplayWindow(m_VideoWindow.GetSafeHwnd());
m_FilterGraph->SetNotifyWindow(this->GetSafeHwnd());
}
}
void CSimplePlayerDlg::OnVideoWindow()
{
// TODO: Add your control notification handler code here
if(m_FilterGraph->IsPaused())
{
ScreenZoom();
}
else
{
m_FilterGraph->mMediaControl->Pause();
ScreenZoom();
m_FilterGraph->mMediaControl->Run();
}
}
BOOL CSimplePlayerDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if (m_SliderTimer)
{
KillTimer(m_SliderTimer);
m_SliderTimer = 0;
}
return CDialog::DestroyWindow();
}
HRESULT CSimplePlayerDlg::DisplayFileDuration(void)
{
HRESULT hr;
if (!m_FilterGraph->mSeeking)
return E_NOINTERFACE;
// Initialize the display in case we can't read the duration
// m_StrDuration.SetWindowText(TEXT("< /00:00>"));
// m_StrDuration.SetWindowText(TEXT("<liuzhiyuan>"));
// Is media time supported for this file?
if (S_OK != m_FilterGraph->mSeeking->IsFormatSupported(&TIME_FORMAT_MEDIA_TIME))
return E_NOINTERFACE;
// Read the time format to restore later
GUID guidOriginalFormat;
hr = m_FilterGraph->mSeeking->GetTimeFormat(&guidOriginalFormat);
if (FAILED(hr))
return hr;
// Ensure media time format for easy display
hr = m_FilterGraph->mSeeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME);
if (FAILED(hr))
return hr;
// Read the file's duration
LONGLONG llDuration=0;
hr = m_FilterGraph->mSeeking->GetDuration(&llDuration);
if (FAILED(hr))
return hr;
// Return to the original format
if (guidOriginalFormat != TIME_FORMAT_MEDIA_TIME)
{
hr = m_FilterGraph->mSeeking->SetTimeFormat(&guidOriginalFormat);
if (FAILED(hr))
return hr;
}
// Convert the LONGLONG duration into human-readable format
unsigned long nTotalMS = (unsigned long) ((float) llDuration / 10000.0); // 100ns -> ms
int nSeconds = nTotalMS / (int) 1000;
int nMinutes = nSeconds / (int) 60;
//int nHours = nMinutes / (int) 60;
nSeconds %= 60;
// Update the display
TCHAR szDuration[64];
wsprintf(szDuration, _T(" / %02d:%02d\0"),nMinutes, nSeconds);
m_StrDuration.SetWindowText(szDuration);
return hr;
}
void CSimplePlayerDlg::ReadMediaPosition()
{
HRESULT hr;
LONGLONG rtNow;
//REFERENCE_TIME;
if (!m_FilterGraph->mSeeking)
return;
// Read the current stream position
hr = m_FilterGraph->mSeeking->GetCurrentPosition(&rtNow);
if (FAILED(hr))
return;
UpdatePosition(rtNow);
}
void CSimplePlayerDlg::UpdatePosition(LONGLONG rtNow)
{
HRESULT hr;
if (!m_FilterGraph->mSeeking)
return;
// If no reference time was passed in, read the current position
if (rtNow == 0)
{
// Read the current stream position
hr = m_FilterGraph->mSeeking->GetCurrentPosition(&rtNow);
if (FAILED(hr))
return;
}
// Convert the LONGLONG duration into human-readable format
unsigned long nTotalMS = (unsigned long) ((float) rtNow / 10000.0); // 100ns -> ms
int nSeconds = nTotalMS / (int) 1000;
int nMinutes = nSeconds / (int) 60;
// int nHours = nMinutes / (int) 60;
nSeconds %= 60;
// Update the display
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -