Cleanup mediaplayer sample a bit - get rid of bad loop/islooped since it has internal state
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31955 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
bbe5510dcf
commit
bc03601097
@ -110,7 +110,7 @@ public:
|
||||
class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl
|
||||
{
|
||||
public:
|
||||
wxMediaCtrl() : m_imp(NULL), m_bLoaded(false), m_bLoop(false)
|
||||
wxMediaCtrl() : m_imp(NULL), m_bLoaded(false)
|
||||
{ }
|
||||
|
||||
wxMediaCtrl(wxWindow* parent, wxWindowID winid,
|
||||
@ -121,7 +121,7 @@ public:
|
||||
const wxString& szBackend = wxEmptyString,
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxT("mediaCtrl"))
|
||||
: m_imp(NULL), m_bLoaded(false), m_bLoop(false)
|
||||
: m_imp(NULL), m_bLoaded(false)
|
||||
{ Create(parent, winid, fileName, pos, size, style,
|
||||
szBackend, validator, name); }
|
||||
|
||||
@ -133,7 +133,7 @@ public:
|
||||
const wxString& szBackend = wxEmptyString,
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxT("mediaCtrl"))
|
||||
: m_imp(NULL), m_bLoop(false)
|
||||
: m_imp(NULL), m_bLoaded(false)
|
||||
{ Create(parent, winid, location, pos, size, style,
|
||||
szBackend, validator, name); }
|
||||
|
||||
@ -170,20 +170,23 @@ public:
|
||||
bool Stop();
|
||||
|
||||
bool Load(const wxString& fileName);
|
||||
bool Load(const wxURI& location); //DirectShow only
|
||||
|
||||
void Loop(bool bLoop = true);
|
||||
bool IsLooped();
|
||||
|
||||
wxMediaState GetState();
|
||||
|
||||
double GetPlaybackRate(); //All but MCI
|
||||
bool SetPlaybackRate(double dRate); //All but MCI
|
||||
|
||||
wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart);
|
||||
wxFileOffset Tell(); //FIXME: This should be const
|
||||
wxFileOffset Length(); //FIXME: This should be const
|
||||
|
||||
//
|
||||
// Unofficial parts of API
|
||||
//
|
||||
//DirectShow/GStreamer only. Quicktime too, but somewhat buggy...
|
||||
bool Load(const wxURI& location);
|
||||
|
||||
double GetPlaybackRate(); //All but MCI & GStreamer
|
||||
bool SetPlaybackRate(double dRate); //All but MCI & GStreamer
|
||||
|
||||
protected:
|
||||
static wxClassInfo* NextBackend();
|
||||
|
||||
@ -191,6 +194,8 @@ protected:
|
||||
virtual void DoMoveWindow(int x, int y, int w, int h);
|
||||
wxSize DoGetBestSize() const;
|
||||
|
||||
//FIXME: This is nasty... find a better way to work around
|
||||
//inheritance issues
|
||||
#ifdef __WXMAC__
|
||||
friend class wxQTMediaBackend;
|
||||
#endif
|
||||
@ -199,7 +204,6 @@ protected:
|
||||
#endif
|
||||
class wxMediaBackend* m_imp;
|
||||
bool m_bLoaded;
|
||||
bool m_bLoop;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
|
||||
};
|
||||
|
@ -26,11 +26,10 @@
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
// Known bugs with wxMediaCtrl:
|
||||
//
|
||||
// 1) Not available on Unix :\.
|
||||
// 2) Certain backends can't play the same media file at the same time (MCI,
|
||||
// Cocoa NSMovieView/Quicktime).
|
||||
// 3) Positioning on Mac Carbon is messed up if put in a sub-control like a
|
||||
// Notebook (like this sample does).
|
||||
// 1) Certain backends can't play the same media file at the same time (MCI,
|
||||
// Cocoa NSMovieView-Quicktime).
|
||||
// 2) Positioning on Mac Carbon is messed up if put in a sub-control like a
|
||||
// Notebook (like this sample does) on OS versions < 10.2.
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
// ============================================================================
|
||||
@ -197,13 +196,14 @@ class MyNotebookPage : public wxPanel
|
||||
void OnSeek(wxCommandEvent& event);
|
||||
|
||||
// Media event handlers
|
||||
void OnMediaStop(wxMediaEvent& event);
|
||||
void OnMediaFinished(wxMediaEvent& event);
|
||||
|
||||
public:
|
||||
friend class MyFrame; //make MyFrame able to access private members
|
||||
wxMediaCtrl* m_mediactrl; //Our media control
|
||||
wxSlider* m_slider; //The slider below our media control
|
||||
int m_nLoops; //Number of times media has looped
|
||||
bool m_bLoop; //Whether we are looping or not
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -598,7 +598,9 @@ void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
|
||||
wxMessageBox(wxT("No files are currently open!"));
|
||||
return;
|
||||
}
|
||||
GetCurrentMediaCtrl()->Loop( !GetCurrentMediaCtrl()->IsLooped() );
|
||||
|
||||
((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop =
|
||||
!((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -856,7 +858,7 @@ void MyTimer::Notify()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
|
||||
wxPanel(theBook, wxID_ANY), m_nLoops(0)
|
||||
wxPanel(theBook, wxID_ANY), m_nLoops(0), m_bLoop(false)
|
||||
{
|
||||
//
|
||||
// Create and attach the first/main sizer
|
||||
@ -904,9 +906,9 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
|
||||
//
|
||||
// Media Control events
|
||||
//
|
||||
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_STOP,
|
||||
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED,
|
||||
(wxObjectEventFunction) (wxEventFunction)
|
||||
(wxMediaEventFunction) &MyNotebookPage::OnMediaStop);
|
||||
(wxMediaEventFunction) &MyNotebookPage::OnMediaFinished);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -925,14 +927,20 @@ void MyNotebookPage::OnSeek(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyNotebookPage::OnMediaStop
|
||||
// OnMediaFinished
|
||||
//
|
||||
// Called when the media is about to stop playing.
|
||||
// Called when the media stops playing.
|
||||
// Here we loop it if the user wants to (has been selected from file menu)
|
||||
// ----------------------------------------------------------------------------
|
||||
void MyNotebookPage::OnMediaStop(wxMediaEvent& WXUNUSED(event))
|
||||
void MyNotebookPage::OnMediaFinished(wxMediaEvent& WXUNUSED(event))
|
||||
{
|
||||
if(m_mediactrl->IsLooped())
|
||||
++m_nLoops;
|
||||
if(m_bLoop)
|
||||
{
|
||||
if ( !m_mediactrl->Play() )
|
||||
wxMessageBox(wxT("Couldn't loop movie!"));
|
||||
else
|
||||
++m_nLoops;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -214,10 +214,6 @@ bool wxMediaCtrl::DoCreate(wxClassInfo* classInfo,
|
||||
if( m_imp->CreateControl(this, parent, id, pos, size,
|
||||
style, validator, name) )
|
||||
{
|
||||
this->Connect(GetId(), wxEVT_MEDIA_FINISHED,
|
||||
(wxObjectEventFunction) (wxEventFunction)
|
||||
(wxMediaEventFunction)
|
||||
&wxMediaCtrl::OnMediaFinished);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -415,28 +411,6 @@ void wxMediaCtrl::DoMoveWindow(int x, int y, int w, int h)
|
||||
m_imp->Move(x, y, w, h);
|
||||
}
|
||||
|
||||
void wxMediaCtrl::Loop(bool bLoop)
|
||||
{
|
||||
m_bLoop = bLoop;
|
||||
}
|
||||
|
||||
bool wxMediaCtrl::IsLooped()
|
||||
{
|
||||
return m_bLoop;
|
||||
}
|
||||
|
||||
void wxMediaCtrl::OnMediaFinished(wxMediaEvent& WXUNUSED(evt))
|
||||
{
|
||||
if(m_bLoop)
|
||||
{
|
||||
#ifdef __WXDEBUG__
|
||||
wxASSERT( Play() );
|
||||
#else
|
||||
Play();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//DARWIN gcc compiler badly screwed up - needs destructor impl in source
|
||||
wxMediaBackend::~wxMediaBackend()
|
||||
{ }
|
||||
|
Loading…
Reference in New Issue
Block a user