From e4b12a53fe1c96fe3ab3b08408eb8932520ef224 Mon Sep 17 00:00:00 2001 From: Ryan Norton Date: Thu, 11 Nov 2004 15:18:18 +0000 Subject: [PATCH] tweak stopping - nicen up sample some more git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30467 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/mediaplayer/mediaplayer.cpp | 26 ++++++++++++++------------ src/msw/mediactrl.cpp | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/samples/mediaplayer/mediaplayer.cpp b/samples/mediaplayer/mediaplayer.cpp index faf3dbfc23..8a4756a222 100644 --- a/samples/mediaplayer/mediaplayer.cpp +++ b/samples/mediaplayer/mediaplayer.cpp @@ -330,7 +330,7 @@ MyFrame::MyFrame(const wxString& title) // //~MyFrame -//------- +//-------- //Deletes child objects implicitly and our timer explicitly // MyFrame::~MyFrame() @@ -340,7 +340,7 @@ MyFrame::~MyFrame() // //OnQuit -//------- +//------ //Called from file->quit. //Closes this application. // @@ -367,7 +367,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) // //OnLoop -//------- +//------ //Called from file->loop. //Changes the state of whether we want to loop or not. // @@ -378,7 +378,7 @@ void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event)) // //OnOpenFile -//------- +//---------- //Called from file->openfile. //Opens and plays a media file // @@ -400,7 +400,7 @@ void MyFrame::OnOpenFile(wxCommandEvent& WXUNUSED(event)) // //OnPlay -//------- +//------ //Called from file->play. //Resumes the media if it is paused or stopped. // @@ -424,10 +424,12 @@ void MyFrame::OnPause(wxCommandEvent& WXUNUSED(event)) // //OnStop -//------- +//------ //Called from file->stop. -//Note that where the media stops is undefined - -//it could stop at the end or beginning. +//Where it stops depends on whether you can seek in the +//media control or not - if you can it stops and seeks to the beginning, +//otherwise it will appear to be at the end - but it will start over again +//when play() is called // void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event)) { @@ -437,7 +439,7 @@ void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event)) // //OnSeek -//------- +//------ //Called from file->seek. //Called when the user moves the slider - //seeks to a position within the media @@ -450,7 +452,7 @@ void MyFrame::OnSeek(wxCommandEvent& WXUNUSED(event)) // //OnMediaFinished -//------- +//--------------- //Called when the media stops playing. //Here we loop it if the user wants to (has been selected from file menu) // @@ -458,7 +460,7 @@ void MyFrame::OnMediaFinished(wxMediaEvent& WXUNUSED(event)) { if(m_bLoop) { - if ( !m_mediactrl->SetPosition(0) || !m_mediactrl->Play() ) - wxMessageBox(wxT("Couldn't seek or play to loop movie!")); + if ( !m_mediactrl->Play() ) + wxMessageBox(wxT("Couldn't loop movie!")); } } \ No newline at end of file diff --git a/src/msw/mediactrl.cpp b/src/msw/mediactrl.cpp index 96c8361634..8362224bd9 100644 --- a/src/msw/mediactrl.cpp +++ b/src/msw/mediactrl.cpp @@ -531,7 +531,13 @@ bool wxDXMediaCtrlImpl::Pause() bool wxDXMediaCtrlImpl::Stop() { - return SUCCEEDED( m_pMC->Stop() ) && SetPosition(0); + bool bOK = SUCCEEDED( m_pMC->Stop() ); + + //We don't care if it can't get to the beginning in directshow - + //it could be a non-seeking filter (wince midi) in which case playing + //starts all over again + SetPosition(0); + return bOK; } bool wxDXMediaCtrlImpl::SetPosition(long where) @@ -613,11 +619,14 @@ bool wxDXMediaCtrlImpl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPa // If this is the end of the clip, notify handler if(EC_COMPLETE == evCode) { + //Interestingly enough, DirectShow does not actually stop + //the filters - even when it reaches the end! #ifdef __WXDEBUG__ wxASSERT( Stop() ); #else Stop(); #endif + wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED, m_ctrl->GetId()); m_ctrl->GetParent()->ProcessEvent(theEvent); } @@ -703,7 +712,8 @@ bool wxWMMEMediaCtrlImpl::Pause() bool wxWMMEMediaCtrlImpl::Stop() { - return (mciSendCommand(m_hDev, MCI_STOP, MCI_WAIT, 0) == 0); + return (mciSendCommand(m_hDev, MCI_STOP, MCI_WAIT, 0) == 0) && + SetPosition(GetDuration()); } #include "wx/log.h" -- 2.45.2