// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 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
};
// ----------------------------------------------------------------------------
//
// The fourth is an optional userdata param -
// this is of historical relevance only and is
- // there only for backwards compatability.
+ // there only for backwards compatibility.
//
// The fifth is the context in which to call the
// handler - by default (this param is optional)
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
//
// Create our media control
//
- m_mediactrl = new wxMediaCtrl(this, wxID_MEDIACTRL);
+ m_mediactrl = new wxMediaCtrl();
+
+ // Make sure creation was successful
+ bool bOK = m_mediactrl->Create(this, wxID_MEDIACTRL);
+ wxASSERT_MSG(bOK, wxT("Could not create media control!"));
+
vertsizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
//
//
// 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;
+ }
}
//