// the wxMediaCtrl class in wxWidgets.
//
// To use this sample, simply select Open File from the file menu,
-// select the file you want to play - and MediaPlayer will play the file in a
+// select the file you want to play - and MediaPlayer will play the file in a
// new notebook page, showing video if neccessary.
//
// You can select one of the menu options, or move the slider around
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Known bugs with wxMediaCtrl:
-//
+//
// 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
+// 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.
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// media from a URL, etc.
#define wxUSE_UNOFFICIALSTUFF 0
-//Libraries for MSVC with optional backends
-#ifdef _MSC_VER
- #if wxUSE_DIRECTSHOW
- #pragma comment(lib,"strmiids.lib")
- #endif
- #if wxUSE_QUICKTIME
- #pragma comment(lib,"qtmlClient.lib")
- #endif
-#endif
-
// ----------------------------------------------------------------------------
// Bail out if the user doesn't want one of the
// things we need
// wxID_STOP, [built-in to wxWidgets]
// wxID_ABOUT, [built-in to wxWidgets]
// wxID_EXIT, [built-in to wxWidgets]
-
- // event id for our slider
- wxID_SLIDER,
-
- // event id for our notebook
- wxID_NOTEBOOK,
-
- // event id for our wxMediaCtrl
- wxID_MEDIACTRL
+ wxID_SLIDER, // event id for our slider
+ wxID_NOTEBOOK, // event id for our notebook
+ wxID_MEDIACTRL // event id for our wxMediaCtrl
};
// ----------------------------------------------------------------------------
// Common open file code
void OpenFile(bool bNewPage);
void OpenURL(bool bNewPage);
-
+
// Get the media control and slider of current notebook page
wxMediaCtrl* GetCurrentMediaCtrl();
wxSlider* GetCurrentSlider();
class MyTimer* m_timer; //Timer to write info to status bar
wxString m_basestatus; //Base status string (see ResetStatus())
- wxNotebook* m_notebook;
+ wxNotebook* m_notebook; //Notebook containing our pages
// So that mytimer can access MyFrame's members
friend class MyTimer;
class MyNotebookPage : public wxPanel
{
MyNotebookPage(wxNotebook* book);
-
+
// Slider event handlers
void OnSeek(wxCommandEvent& event);
// Media event handlers
void OnMediaFinished(wxMediaEvent& event);
-
+
public:
friend class MyFrame; //make MyFrame able to access private members
wxMediaCtrl* m_mediactrl; //Our media control
_T("&About...\tF1"),
_T("Show about dialog"));
- menuFile->Append(wxID_OPENFILESAMEPAGE, _T("&Open File"),
+ menuFile->Append(wxID_OPENFILESAMEPAGE, _T("&Open File"),
_T("Open a File in the current notebook page"));
- menuFile->Append(wxID_OPENFILENEWPAGE, _T("&Open File in a new page"),
+ menuFile->Append(wxID_OPENFILENEWPAGE, _T("&Open File in a new page"),
_T("Open a File in a new notebook page"));
#if wxUSE_UNOFFICIALSTUFF
- menuFile->Append(wxID_OPENURLSAMEPAGE, _T("&Open URL"),
+ menuFile->Append(wxID_OPENURLSAMEPAGE, _T("&Open URL"),
_T("Open a URL in the current notebook page"));
- menuFile->Append(wxID_OPENURLNEWPAGE, _T("&Open URL in a new page"),
+ menuFile->Append(wxID_OPENURLNEWPAGE, _T("&Open URL in a new page"),
_T("Open a URL in a new notebook page"));
#endif
menuFile->AppendSeparator();
- menuFile->Append(wxID_CLOSECURRENTPAGE, _T("&Close Current Page"),
+ menuFile->Append(wxID_CLOSECURRENTPAGE, _T("&Close Current Page"),
_T("Close current notebook page"));
menuFile->AppendSeparator();
menuFile->Append(wxID_PLAY, _T("&Play"), _T("Resume playback"));
SetMenuBar(menuBar);
//
- // Create our notebook - using wxNotebook is luckily pretty
+ // Create our notebook - using wxNotebook is luckily pretty
// simple and self-explanatory in most cases
//
m_notebook = new wxNotebook(this, wxID_NOTEBOOK);
// (wxObjectEventFunction)(wxEventFunction)
// (wxCommandEventFunction) &MyFrame::MyHandler
//
+ // Or, you can use the new (2.5.5+) event handler
+ // conversion macros - for instance the above could
+ // be done as
+ // wxCommandEventHandler(MyFrame::MyHandler)
+ // pretty simple, eh?
+ //
// 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)
// Menu events
//
this->Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnQuit);
+ wxCommandEventHandler(MyFrame::OnQuit));
this->Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnAbout);
+ wxCommandEventHandler(MyFrame::OnAbout));
this->Connect(wxID_LOOP, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnLoop);
+ wxCommandEventHandler(MyFrame::OnLoop));
this->Connect(wxID_OPENFILENEWPAGE, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnOpenFileNewPage);
+ wxCommandEventHandler(MyFrame::OnOpenFileNewPage));
this->Connect(wxID_OPENFILESAMEPAGE, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnOpenFileSamePage);
+ wxCommandEventHandler(MyFrame::OnOpenFileSamePage));
this->Connect(wxID_OPENURLNEWPAGE, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnOpenURLNewPage);
+ wxCommandEventHandler(MyFrame::OnOpenURLNewPage));
this->Connect(wxID_OPENURLSAMEPAGE, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnOpenURLSamePage);
+ wxCommandEventHandler(MyFrame::OnOpenURLSamePage));
this->Connect(wxID_CLOSECURRENTPAGE, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnCloseCurrentPage);
+ wxCommandEventHandler(MyFrame::OnCloseCurrentPage));
this->Connect(wxID_PLAY, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnPlay);
+ wxCommandEventHandler(MyFrame::OnPlay));
this->Connect(wxID_PAUSE, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnPause);
+ wxCommandEventHandler(MyFrame::OnPause));
this->Connect(wxID_STOP, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyFrame::OnStop);
+ wxCommandEventHandler(MyFrame::OnStop));
//
// Notebook events
//
this->Connect(wxID_NOTEBOOK, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxNotebookEventFunction) &MyFrame::OnPageChange);
-
+ wxNotebookEventHandler(MyFrame::OnPageChange));
+
//
// End of Events
//
return;
}
- ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop =
+ ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop =
!((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop;
}
// Opens and plays a media file in the current notebook page
// ----------------------------------------------------------------------------
void MyFrame::OnOpenFileSamePage(wxCommandEvent& WXUNUSED(event))
-{
- OpenFile(false);
+{
+ OpenFile(false);
}
// ----------------------------------------------------------------------------
// Opens and plays a media file in a new notebook page
// ----------------------------------------------------------------------------
void MyFrame::OnOpenFileNewPage(wxCommandEvent& WXUNUSED(event))
-{
- OpenFile(true);
+{
+ OpenFile(true);
}
// ----------------------------------------------------------------------------
{
if(bNewPage || !m_notebook->GetCurrentPage())
m_notebook->AddPage(new MyNotebookPage(m_notebook), fd.GetPath(), true);
-
+ else //don't forget to update notebook page title
+ m_notebook->SetPageText(m_notebook->GetSelection(), fd.GetPath());
+
if( !GetCurrentMediaCtrl()->Load(fd.GetPath()) )
wxMessageBox(wxT("Couldn't load file!"));
wxMessageBox(wxT("Couldn't play movie!"));
ResetStatus();
-
- GetCurrentSlider()->SetRange(0,
- (int)(GetCurrentMediaCtrl()->Length() / 1000));
+ GetCurrentSlider()->SetRange(0,
+ (int)(GetCurrentMediaCtrl()->Length() / 1000));
}
}
// Opens and plays a media file from a URL in the current notebook page
// ----------------------------------------------------------------------------
void MyFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
-{
- OpenURL(false);
+{
+ OpenURL(false);
}
// ----------------------------------------------------------------------------
// Opens and plays a media file from a URL in a new notebook page
// ----------------------------------------------------------------------------
void MyFrame::OnOpenURLNewPage(wxCommandEvent& WXUNUSED(event))
-{
- OpenURL(true);
+{
+ OpenURL(true);
}
// ----------------------------------------------------------------------------
{
if(bNewPage || !m_notebook->GetCurrentPage())
m_notebook->AddPage(new MyNotebookPage(m_notebook), theURL, true);
+ else //don't forget to update notebook page title
+ m_notebook->SetPageText(m_notebook->GetSelection(), theURL);
if( !GetCurrentMediaCtrl()->Load(wxURI(theURL)) )
wxMessageBox(wxT("Couldn't load URL!"));
if( !GetCurrentMediaCtrl()->Play() )
wxMessageBox(wxT("Couldn't play movie!"));
-
+
ResetStatus();
- GetCurrentSlider()->SetRange(0,
+ GetCurrentSlider()->SetRange(0,
(int)(GetCurrentMediaCtrl()->Length() / 1000));
}
}
if (sel != wxNOT_FOUND)
{
m_notebook->DeletePage(sel);
- }
+ }
}
// ----------------------------------------------------------------------------
void MyTimer::Notify()
{
if (!m_frame->m_notebook->GetCurrentPage()) return;
- wxMediaCtrl* m_mediactrl = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_mediactrl;
- wxSlider* m_slider = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_slider;
+ wxMediaCtrl* m_mediactrl = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_mediactrl;
+ wxSlider* m_slider = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_slider;
if (!m_mediactrl) return;
long lPosition = (long)( m_mediactrl->Tell() / 1000 );
(unsigned int)lPosition,
wxGetMediaStateText(m_mediactrl->GetState()),
((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_nLoops
-
+
)
);
#endif
// Create our media control
//
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!"));
-
+ wxUnusedVar(bOK);
+
vertsizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
//
// Slider events
//
this->Connect(wxID_SLIDER, wxEVT_COMMAND_SLIDER_UPDATED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxCommandEventFunction) &MyNotebookPage::OnSeek);
+ wxCommandEventHandler(MyNotebookPage::OnSeek));
//
// Media Control events
//
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED,
- (wxObjectEventFunction) (wxEventFunction)
- (wxMediaEventFunction) &MyNotebookPage::OnMediaFinished);
+ wxMediaEventHandler(MyNotebookPage::OnMediaFinished));
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void MyNotebookPage::OnSeek(wxCommandEvent& WXUNUSED(event))
{
- if( m_mediactrl->Seek(
- m_slider->GetValue() * 1000
+ if( m_mediactrl->Seek(
+ m_slider->GetValue() * 1000
) == wxInvalidOffset )
wxMessageBox(wxT("Couldn't seek in movie!"));
}