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,
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); }
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); }
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();
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
#endif
class wxMediaBackend* m_imp;
bool m_bLoaded;
- bool m_bLoop;
DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
};
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 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.
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// ============================================================================
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
};
// ----------------------------------------------------------------------------
wxMessageBox(wxT("No files are currently open!"));
return;
}
- GetCurrentMediaCtrl()->Loop( !GetCurrentMediaCtrl()->IsLooped() );
+
+ ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop =
+ !((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop;
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
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
//
// 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);
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
-// 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;
+ }
}
//
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;
}
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()
{ }