+ //
+ // Layout
+ //
+ // [wxMediaCtrl]
+ // [playlist]
+ // [5 control buttons]
+ // [slider]
+ // [gauge]
+ //
+
+ //
+ // Create and attach the sizer
+ //
+ wxFlexGridSizer* sizer = new wxFlexGridSizer(2, 1, 0, 0);
+ this->SetSizer(sizer);
+ this->SetAutoLayout(true);
+ sizer->AddGrowableRow(0);
+ sizer->AddGrowableCol(0);
+
+ //
+ // Create our media control
+ //
+ m_mediactrl = new wxMediaCtrl();
+
+ // Make sure creation was successful
+ bool bOK = m_mediactrl->Create(this, wxID_MEDIACTRL, wxEmptyString,
+ wxDefaultPosition, wxDefaultSize, 0,
+//you could specify a macrod backend here like
+// wxMEDIABACKEND_WMP10);
+// wxT("wxPDFMediaBackend"));
+ szBackend);
+//you could change the cursor here like
+// m_mediactrl->SetCursor(wxCURSOR_BLANK);
+//note that this may not effect it if SetPlayerControls
+//is set to something else than wxMEDIACTRLPLAYERCONTROLS_NONE
+ wxASSERT_MSG(bOK, wxT("Could not create media control!"));
+ wxUnusedVar(bOK);
+
+ sizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
+
+ //
+ // Create the playlist/listctrl
+ //
+ m_playlist = new wxMediaPlayerListCtrl();
+ m_playlist->Create(this, wxID_LISTCTRL, wxDefaultPosition,
+ wxDefaultSize,
+ wxLC_REPORT //wxLC_LIST
+ | wxSUNKEN_BORDER);
+
+ // Set the background of our listctrl to white
+ m_playlist->SetBackgroundColour(wxColour(255,255,255));
+
+ // The layout of the headers of the listctrl are like
+ // | | File | Length
+ //
+ // Where Column one is a character representing the state the file is in:
+ // * - not the current file
+ // E - Error has occured
+ // > - Currently Playing
+ // [] - Stopped
+ // || - Paused
+ // (( - Volume Down 5%
+ // )) - Volume Up 5%
+ //
+ // Column two is the name of the file
+ //
+ // Column three is the length in seconds of the file
+ m_playlist->InsertColumn(0,_(""), wxLIST_FORMAT_CENTER, 20);
+ m_playlist->InsertColumn(1,_("File"), wxLIST_FORMAT_LEFT, /*wxLIST_AUTOSIZE_USEHEADER*/305);
+ m_playlist->InsertColumn(2,_("Length"), wxLIST_FORMAT_CENTER, 75);
+
+#if wxUSE_DRAG_AND_DROP
+ m_playlist->SetDropTarget(new wxPlayListDropTarget(*m_playlist));
+#endif
+
+ sizer->Add(m_playlist, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
+
+ //
+ // Create the control buttons
+ // TODO/FIXME/HACK: This part about sizers is really a nice hack
+ // and probably isn't proper
+ //
+ wxBoxSizer* horsizer1 = new wxBoxSizer(wxHORIZONTAL);
+ wxBoxSizer* vertsizer = new wxBoxSizer(wxHORIZONTAL);
+
+ m_prevButton = new wxButton();
+ m_playButton = new wxButton();
+ m_stopButton = new wxButton();
+ m_nextButton = new wxButton();
+ m_vdButton = new wxButton();
+ m_vuButton = new wxButton();
+
+ m_prevButton->Create(this, wxID_BUTTONPREV, wxT("|<"));
+ m_playButton->Create(this, wxID_BUTTONPLAY, wxT(">"));
+ m_stopButton->Create(this, wxID_BUTTONSTOP, wxT("[]"));
+ m_nextButton->Create(this, wxID_BUTTONNEXT, wxT(">|"));
+ m_vdButton->Create(this, wxID_BUTTONVD, wxT("(("));
+ m_vuButton->Create(this, wxID_BUTTONVU, wxT("))"));
+ vertsizer->Add(m_prevButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ vertsizer->Add(m_playButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ vertsizer->Add(m_stopButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ vertsizer->Add(m_nextButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ vertsizer->Add(m_vdButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ vertsizer->Add(m_vuButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ horsizer1->Add(vertsizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ sizer->Add(horsizer1, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
+
+
+ //
+ // Create our slider
+ //
+ m_slider = new wxSlider(this, wxID_SLIDER, 0, //init
+ 0, //start
+ 0, //end
+ wxDefaultPosition, wxDefaultSize,
+ wxSL_HORIZONTAL );
+ sizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
+
+ //
+ // Create the gauge
+ //
+ m_gauge = new wxGauge();
+ m_gauge->Create(this, wxID_GAUGE, 0, wxDefaultPosition, wxDefaultSize,
+ wxGA_HORIZONTAL | wxGA_SMOOTH);
+ sizer->Add(m_gauge, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
+
+ //
+ // Create the speed/volume sliders
+ //
+ wxBoxSizer* horsizer3 = new wxBoxSizer(wxHORIZONTAL);
+
+ m_volSlider = new wxSlider(this, wxID_VOLSLIDER, 100, // init
+ 0, // start
+ 100, // end
+ wxDefaultPosition, wxSize(250,20),
+ wxSL_HORIZONTAL );
+ horsizer3->Add(m_volSlider, 1, wxALL, 5);
+
+ m_pbSlider = new wxSlider(this, wxID_PBSLIDER, 4, // init
+ 1, // start
+ 16, // end
+ wxDefaultPosition, wxSize(250,20),
+ wxSL_HORIZONTAL );
+ horsizer3->Add(m_pbSlider, 1, wxALL, 5);
+ sizer->Add(horsizer3, 1, wxCENTRE | wxALL, 5);
+
+ //
+ // ListCtrl events
+ //
+ this->Connect( wxID_LISTCTRL, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
+ wxListEventHandler(wxMediaPlayerFrame::OnChangeSong),
+ (wxObject*)0, parentFrame);
+
+ //
+ // Slider events
+ //
+ this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBTRACK,
+ wxScrollEventHandler(wxMediaPlayerNotebookPage::OnBeginSeek));
+ this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBRELEASE,
+ wxScrollEventHandler(wxMediaPlayerNotebookPage::OnEndSeek));
+ this->Connect(wxID_PBSLIDER, wxEVT_SCROLL_THUMBRELEASE,
+ wxScrollEventHandler(wxMediaPlayerNotebookPage::OnPBChange));
+ this->Connect(wxID_VOLSLIDER, wxEVT_SCROLL_THUMBRELEASE,
+ wxScrollEventHandler(wxMediaPlayerNotebookPage::OnVolChange));
+
+ //
+ // Media Control events
+ //
+ this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_PLAY,
+ wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaPlay));
+ this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_PAUSE,
+ wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaPause));
+ this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_STOP,
+ wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaStop));
+ this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED,
+ wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaFinished));
+ this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_LOADED,
+ wxMediaEventHandler(wxMediaPlayerFrame::OnMediaLoaded),
+ (wxObject*)0, parentFrame);
+
+ //
+ // Button events
+ //
+ this->Connect( wxID_BUTTONPREV, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(wxMediaPlayerFrame::OnPrev),
+ (wxObject*)0, parentFrame);
+ this->Connect( wxID_BUTTONPLAY, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(wxMediaPlayerFrame::OnPlay),
+ (wxObject*)0, parentFrame);
+ this->Connect( wxID_BUTTONSTOP, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(wxMediaPlayerFrame::OnStop),
+ (wxObject*)0, parentFrame);
+ this->Connect( wxID_BUTTONNEXT, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(wxMediaPlayerFrame::OnNext),
+ (wxObject*)0, parentFrame);
+ this->Connect( wxID_BUTTONVD, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeDown),
+ (wxObject*)0, parentFrame);
+ this->Connect( wxID_BUTTONVU, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeUp),
+ (wxObject*)0, parentFrame);
+}
+
+// ----------------------------------------------------------------------------
+// MyNotebook::OnBeginSeek
+//
+// Sets m_bIsBeingDragged to true to stop the timer from changing the position
+// of our slider
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnBeginSeek(wxScrollEvent& WXUNUSED(event))
+{
+ m_bIsBeingDragged = true;
+}
+
+// ----------------------------------------------------------------------------
+// MyNotebook::OnEndSeek
+//
+// Called from file->seek.
+// Called when the user moves the slider -
+// seeks to a position within the media
+// then sets m_bIsBeingDragged to false to ok the timer to change the position
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnEndSeek(wxScrollEvent& WXUNUSED(event))
+{
+ if( m_mediactrl->Seek(
+ m_slider->GetValue() * 1000
+ ) == wxInvalidOffset )