]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/mediaplayer/mediaplayer.cpp
Regenerated makefiles for runtime lib change
[wxWidgets.git] / samples / mediaplayer / mediaplayer.cpp
index 95fea002bd55c98b8e37efce551481750194615e..260a6c97cbd5b28d2b5e2b712e1067fb99bfedf5 100644 (file)
@@ -16,7 +16,7 @@
 // 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
@@ -112,15 +102,9 @@ enum
 //    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
 };
 
 // ----------------------------------------------------------------------------
@@ -169,14 +153,14 @@ private:
     // 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;
@@ -191,13 +175,13 @@ private:
 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
@@ -319,18 +303,18 @@ MyFrame::MyFrame(const wxString& title)
                      _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"));
@@ -352,7 +336,7 @@ MyFrame::MyFrame(const wxString& title)
     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);
@@ -413,9 +397,15 @@ MyFrame::MyFrame(const wxString& title)
     //  (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)
@@ -432,56 +422,44 @@ MyFrame::MyFrame(const wxString& title)
     // 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
     //
@@ -599,7 +577,7 @@ void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
         return;
     }
 
-    ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop = 
+    ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop =
             !((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop;
 }
 
@@ -610,8 +588,8 @@ void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
 // Opens and plays a media file in the current notebook page
 // ----------------------------------------------------------------------------
 void MyFrame::OnOpenFileSamePage(wxCommandEvent& WXUNUSED(event))
-{   
-    OpenFile(false); 
+{
+    OpenFile(false);
 }
 
 // ----------------------------------------------------------------------------
@@ -621,8 +599,8 @@ void MyFrame::OnOpenFileSamePage(wxCommandEvent& WXUNUSED(event))
 // Opens and plays a media file in a new notebook page
 // ----------------------------------------------------------------------------
 void MyFrame::OnOpenFileNewPage(wxCommandEvent& WXUNUSED(event))
-{   
-    OpenFile(true); 
+{
+    OpenFile(true);
 }
 
 // ----------------------------------------------------------------------------
@@ -646,7 +624,9 @@ void MyFrame::OpenFile(bool bNewPage)
     {
         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!"));
 
@@ -654,10 +634,9 @@ void MyFrame::OpenFile(bool bNewPage)
             wxMessageBox(wxT("Couldn't play movie!"));
 
         ResetStatus();
-        
-        GetCurrentSlider()->SetRange(0, 
-                        (int)(GetCurrentMediaCtrl()->Length() / 1000));
 
+        GetCurrentSlider()->SetRange(0,
+                        (int)(GetCurrentMediaCtrl()->Length() / 1000));
     }
 }
 
@@ -668,8 +647,8 @@ void MyFrame::OpenFile(bool bNewPage)
 // Opens and plays a media file from a URL in the current notebook page
 // ----------------------------------------------------------------------------
 void MyFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
-{   
-    OpenURL(false); 
+{
+    OpenURL(false);
 }
 
 // ----------------------------------------------------------------------------
@@ -679,8 +658,8 @@ void MyFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
 // Opens and plays a media file from a URL in a new notebook page
 // ----------------------------------------------------------------------------
 void MyFrame::OnOpenURLNewPage(wxCommandEvent& WXUNUSED(event))
-{   
-    OpenURL(true); 
+{
+    OpenURL(true);
 }
 
 // ----------------------------------------------------------------------------
@@ -704,16 +683,18 @@ void MyFrame::OpenURL(bool bNewPage)
     {
         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));
     }
 }
@@ -734,7 +715,7 @@ void MyFrame::OnCloseCurrentPage(wxCommandEvent& WXUNUSED(event))
     if (sel != wxNOT_FOUND)
     {
         m_notebook->DeletePage(sel);
-    }    
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -822,8 +803,8 @@ void MyFrame::OnPageChange(wxNotebookEvent& WXUNUSED(event))
 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 );
@@ -836,7 +817,7 @@ void MyTimer::Notify()
                      (unsigned int)lPosition,
                      wxGetMediaStateText(m_mediactrl->GetState()),
                     ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_nLoops
-                    
+
                                             )
                            );
 #endif
@@ -871,11 +852,12 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
     //  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);
 
     //
@@ -905,15 +887,13 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
     // 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));
 }
 
 // ----------------------------------------------------------------------------
@@ -925,8 +905,8 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
 // ----------------------------------------------------------------------------
 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!"));
 }