// 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.
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 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 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);
this->Connect(wxID_NOTEBOOK, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
(wxObjectEventFunction) (wxEventFunction)
(wxNotebookEventFunction) &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);
-
+
if( !GetCurrentMediaCtrl()->Load(fd.GetPath()) )
wxMessageBox(wxT("Couldn't load file!"));
wxMessageBox(wxT("Couldn't play movie!"));
ResetStatus();
-
- GetCurrentSlider()->SetRange(0,
+
+ 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( !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);
//
// ----------------------------------------------------------------------------
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!"));
}