+
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ if(currentpage->m_nLastFileId != -1)
+ currentpage->m_playlist->SetItemState(currentpage->m_nLastFileId,
+ 0, wxLIST_STATE_SELECTED);
+
+ wxListItem newlistitem;
+ newlistitem.SetAlign(wxLIST_FORMAT_LEFT);
+
+ int nID;
+
+ newlistitem.SetId(nID = currentpage->m_playlist->GetItemCount());
+ newlistitem.SetMask(wxLIST_MASK_DATA | wxLIST_MASK_STATE);
+ newlistitem.SetState(wxLIST_STATE_SELECTED);
+ newlistitem.SetData(new wxString(path));
+
+ currentpage->m_playlist->InsertItem(newlistitem);
+ currentpage->m_playlist->SetItem(nID, 0, wxT("*"));
+ currentpage->m_playlist->SetItem(nID, 1, wxFileName(path).GetName());
+
+ if (nID % 2)
+ {
+ newlistitem.SetBackgroundColour(wxColour(192,192,192));
+ currentpage->m_playlist->SetItem(newlistitem);
+ }
+
+ DoPlayFile(path);
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::DoPlayFile
+//
+// Pauses the file if its the currently playing file,
+// otherwise it plays the file
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::DoPlayFile(const wxString& path)
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ wxListItem listitem;
+ currentpage->m_playlist->GetSelectedItem(listitem);
+
+ if( ( listitem.GetData() &&
+ currentpage->m_nLastFileId == listitem.GetId() &&
+ currentpage->m_szFile.compare(path) == 0 ) ||
+ ( !listitem.GetData() &&
+ currentpage->m_nLastFileId != -1 &&
+ currentpage->m_szFile.compare(path) == 0)
+ )
+ {
+ if(currentpage->m_mediactrl->GetState() == wxMEDIASTATE_PLAYING)
+ {
+ if( !currentpage->m_mediactrl->Pause() )
+ wxMessageBox(wxT("Couldn't pause movie!"));
+ }
+ else
+ {
+ if( !currentpage->m_mediactrl->Play() )
+ wxMessageBox(wxT("Couldn't play movie!"));
+ }
+ }
+ else
+ {
+ int nNewId = listitem.GetData() ? listitem.GetId() :
+ currentpage->m_playlist->GetItemCount()-1;
+ m_notebook->SetPageText(m_notebook->GetSelection(),
+ wxFileName(path).GetName());
+
+ if(currentpage->m_nLastFileId != -1)
+ currentpage->m_playlist->SetItem(
+ currentpage->m_nLastFileId, 0, wxT("*"));
+
+ wxURI uripath(path);
+ if( uripath.IsReference() )
+ {
+ if( !currentpage->m_mediactrl->Load(path) )
+ {
+ wxMessageBox(wxT("Couldn't load file!"));
+ currentpage->m_playlist->SetItem(nNewId, 0, wxT("E"));
+ }
+ else
+ {
+ currentpage->m_playlist->SetItem(nNewId, 0, wxT("O"));
+ }
+ }
+ else
+ {
+ if( !currentpage->m_mediactrl->Load(uripath) )
+ {
+ wxMessageBox(wxT("Couldn't load URL!"));
+ currentpage->m_playlist->SetItem(nNewId, 0, wxT("E"));
+ }
+ else
+ {
+ currentpage->m_playlist->SetItem(nNewId, 0, wxT("O"));
+ }
+ }
+
+ currentpage->m_nLastFileId = nNewId;
+ currentpage->m_szFile = path;
+ currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
+ 1, wxFileName(path).GetName());
+ currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
+ 2, wxT(""));
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnMediaLoaded
+//
+// Called when the media is ready to be played - and does
+// so, also gets the length of media and shows that in the list control
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnMediaLoaded(wxMediaEvent& WXUNUSED(evt))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ if( !currentpage->m_mediactrl->Play() )
+ {
+ wxMessageBox(wxT("Couldn't play movie!"));
+ currentpage->m_playlist->SetItem(currentpage->m_nLastFileId, 0, wxT("E"));
+ }
+ else
+ {
+ currentpage->m_playlist->SetItem(currentpage->m_nLastFileId, 0, wxT(">"));
+ }
+
+}
+
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnSelectBackend
+//
+// Little debugging routine - enter the class name of a backend and it
+// will use that instead of letting wxMediaCtrl search the wxMediaBackend
+// RTTI class list.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnSelectBackend(wxCommandEvent& WXUNUSED(evt))
+{
+ wxString sBackend = wxGetTextFromUser(wxT("Enter backend to use"));
+
+ if(sBackend.empty() == false) //could have been cancelled by the user
+ {
+ int sel = m_notebook->GetSelection();
+
+ if (sel != wxNOT_FOUND)
+ {
+ m_notebook->DeletePage(sel);
+ }
+
+ m_notebook->AddPage(new wxMediaPlayerNotebookPage(this, m_notebook,
+ sBackend
+ ), wxT(""), true);
+
+ DoOpenFile(
+ ((wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage())->m_szFile,
+ false);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnOpenURLSamePage
+//
+// Called from file->openurl.
+// Opens and plays a media file from a URL in the current notebook page
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
+{
+ OpenURL(false);
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnOpenURLNewPage
+//
+// Called from file->openurlinnewpage.
+// Opens and plays a media file from a URL in a new notebook page
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnOpenURLNewPage(wxCommandEvent& WXUNUSED(event))
+{
+ OpenURL(true);
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OpenURL
+//
+// Just calls DoOpenFile with the url path - which calls DoPlayFile
+// which handles the real dirty work
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OpenURL(bool bNewPage)
+{
+ wxString sUrl = wxGetTextFromUser(
+ wxT("Enter the URL that has the movie to play")
+ );
+
+ if(sUrl.empty() == false) //could have been cancelled by user
+ {
+ DoOpenFile(sUrl, bNewPage);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnCloseCurrentPage
+//
+// Called when the user wants to close the current notebook page
+//
+// 1) Get the current page number (wxControl::GetSelection)
+// 2) If there is no current page, break out
+// 3) Delete the current page
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnCloseCurrentPage(wxCommandEvent& WXUNUSED(event))
+{
+ if( m_notebook->GetPageCount() > 1 )
+ {
+ int sel = m_notebook->GetSelection();
+
+ if (sel != wxNOT_FOUND)
+ {
+ m_notebook->DeletePage(sel);
+ }
+ }
+ else
+ {
+ wxMessageBox(wxT("Cannot close main page"));
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnPlay
+//
+// Called from file->play.
+// Resumes the media if it is paused or stopped.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ wxListItem listitem;
+ currentpage->m_playlist->GetSelectedItem(listitem);
+ if ( !listitem.GetData() )
+ {
+ int nLast = -1;
+ if ((nLast = currentpage->m_playlist->GetNextItem(nLast,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_DONTCARE)) == -1)
+ {
+ //no items in list
+ wxMessageBox(wxT("No items in playlist!"));
+ }
+ else
+ {
+ listitem.SetId(nLast);
+ currentpage->m_playlist->GetItem(listitem);
+ listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
+ listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
+ currentpage->m_playlist->SetItem(listitem);
+ wxASSERT(listitem.GetData());
+ DoPlayFile((*((wxString*) listitem.GetData())));
+ }
+ }
+ else
+ {
+ wxASSERT(listitem.GetData());
+ DoPlayFile((*((wxString*) listitem.GetData())));
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnKeyDown
+//
+// Deletes all selected files from the playlist if the backspace key is pressed
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnKeyDown(wxKeyEvent& event)
+{
+ if(event.GetKeyCode() == WXK_BACK/*DELETE*/)
+ {
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+ //delete all selected items
+ while(true)
+ {
+ wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(
+ -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (nSelectedItem == -1)
+ break;
+
+ wxListItem listitem;
+ listitem.SetId(nSelectedItem);
+ currentpage->m_playlist->GetItem(listitem);
+ delete (wxString*) listitem.GetData();
+
+ currentpage->m_playlist->DeleteItem(nSelectedItem);
+ }
+ }
+
+ //Could be wxGetTextFromUser or something else important
+ if(event.GetEventObject() != this)
+ event.Skip();
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnStop
+//
+// Called from file->stop.
+// Where it stops depends on whether you can seek in the
+// media control or not - if you can it stops and seeks to the beginning,
+// otherwise it will appear to be at the end - but it will start over again
+// when Play() is called
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnStop(wxCommandEvent& WXUNUSED(evt))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ if( !currentpage->m_mediactrl->Stop() )
+ wxMessageBox(wxT("Couldn't stop movie!"));
+ else
+ currentpage->m_playlist->SetItem(
+ currentpage->m_nLastFileId, 0, wxT("[]"));
+}
+
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnChangeSong
+//
+// Routine that plays the currently selected file in the playlist.
+// Called when the user actives the song from the playlist,
+// and from other various places in the sample
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnChangeSong(wxListEvent& WXUNUSED(evt))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ wxListItem listitem;
+ currentpage->m_playlist->GetSelectedItem(listitem);
+ if(listitem.GetData())
+ DoPlayFile((*((wxString*) listitem.GetData())));
+ else
+ wxMessageBox(wxT("No selected item!"));
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnPrev
+//
+// Tedious wxListCtrl stuff. Goes to prevous song in list, or if at the
+// beginning goes to the last in the list.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnPrev(wxCommandEvent& WXUNUSED(event))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ if (currentpage->m_playlist->GetItemCount() == 0)
+ return;
+
+ wxInt32 nLastSelectedItem = -1;
+ while(true)
+ {
+ wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(nLastSelectedItem,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (nSelectedItem == -1)
+ break;
+ nLastSelectedItem = nSelectedItem;
+ currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
+ }
+
+ if (nLastSelectedItem == -1)
+ {
+ //nothing selected, default to the file before the currently playing one
+ if(currentpage->m_nLastFileId == 0)
+ nLastSelectedItem = currentpage->m_playlist->GetItemCount() - 1;
+ else
+ nLastSelectedItem = currentpage->m_nLastFileId - 1;
+ }
+ else if (nLastSelectedItem == 0)
+ nLastSelectedItem = currentpage->m_playlist->GetItemCount() - 1;
+ else
+ nLastSelectedItem -= 1;
+
+ if(nLastSelectedItem == currentpage->m_nLastFileId)
+ return; //already playing... nothing to do
+
+ wxListItem listitem;
+ listitem.SetId(nLastSelectedItem);
+ listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
+ currentpage->m_playlist->GetItem(listitem);
+ listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
+ listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
+ currentpage->m_playlist->SetItem(listitem);
+
+ wxASSERT(listitem.GetData());
+ DoPlayFile((*((wxString*) listitem.GetData())));
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnNext
+//
+// Tedious wxListCtrl stuff. Goes to next song in list, or if at the
+// end goes to the first in the list.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnNext(wxCommandEvent& WXUNUSED(event))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ if (currentpage->m_playlist->GetItemCount() == 0)
+ return;
+
+ wxInt32 nLastSelectedItem = -1;
+ while(true)
+ {
+ wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(nLastSelectedItem,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (nSelectedItem == -1)
+ break;
+ nLastSelectedItem = nSelectedItem;
+ currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
+ }
+
+ if (nLastSelectedItem == -1)
+ {
+ if(currentpage->m_nLastFileId == currentpage->m_playlist->GetItemCount() - 1)
+ nLastSelectedItem = 0;
+ else
+ nLastSelectedItem = currentpage->m_nLastFileId + 1;
+ }
+ else if (nLastSelectedItem == currentpage->m_playlist->GetItemCount() - 1)
+ nLastSelectedItem = 0;
+ else
+ nLastSelectedItem += 1;
+
+ if(nLastSelectedItem == currentpage->m_nLastFileId)
+ return; //already playing... nothing to do
+
+ wxListItem listitem;
+ listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
+ listitem.SetId(nLastSelectedItem);
+ currentpage->m_playlist->GetItem(listitem);
+ listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
+ listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
+ currentpage->m_playlist->SetItem(listitem);
+
+ wxASSERT(listitem.GetData());
+ DoPlayFile((*((wxString*) listitem.GetData())));
+}
+
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnVolumeDown
+//
+// Lowers the volume of the media control by 5%
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnVolumeDown(wxCommandEvent& WXUNUSED(event))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ double dVolume = currentpage->m_mediactrl->GetVolume();
+ currentpage->m_mediactrl->SetVolume(dVolume < 0.05 ? 0.0 : dVolume - .05);
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnVolumeUp
+//
+// Increases the volume of the media control by 5%
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnVolumeUp(wxCommandEvent& WXUNUSED(event))
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
+
+ double dVolume = currentpage->m_mediactrl->GetVolume();
+ currentpage->m_mediactrl->SetVolume(dVolume > 0.95 ? 1.0 : dVolume + .05);
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//
+// wxMediaPlayerTimer
+//
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerTimer::Notify
+//
+// 1) Updates media information on the status bar
+// 2) Sets the max/min length of the slider and guage
+//
+// Note that the reason we continually do this and don't cache it is because
+// some backends such as GStreamer are dynamic change values all the time
+// and often don't have things like duration or video size available
+// until the media is actually being played
+// ----------------------------------------------------------------------------
+void wxMediaPlayerTimer::Notify()
+{
+ wxMediaPlayerNotebookPage* currentpage =
+ (wxMediaPlayerNotebookPage*) m_frame->m_notebook->GetCurrentPage();
+ wxMediaCtrl* currentMediaCtrl = currentpage->m_mediactrl;
+
+ // Number of minutes/seconds total
+ wxLongLong llLength = currentpage->m_mediactrl->Length();
+ int nMinutes = (int) (llLength / 60000).GetValue();
+ int nSeconds = (int) ((llLength % 60000)/1000).GetValue();
+
+ // Duration string (i.e. MM:SS)
+ wxString sDuration;
+ sDuration.Printf(wxT("%2i:%02i"), nMinutes, nSeconds);
+
+
+ // Number of minutes/seconds total
+ wxLongLong llTell = currentpage->m_mediactrl->Tell();
+ nMinutes = (int) (llTell / 60000).GetValue();
+ nSeconds = (int) ((llTell % 60000)/1000).GetValue();
+
+ // Position string (i.e. MM:SS)
+ wxString sPosition;
+ sPosition.Printf(wxT("%2i:%02i"), nMinutes, nSeconds);
+
+
+ // Set the third item in the listctrl entry to the duration string
+ if(currentpage->m_nLastFileId >= 0)
+ currentpage->m_playlist->SetItem(
+ currentpage->m_nLastFileId, 2, sDuration);
+
+ // Setup the slider and gauge min/max values
+ currentpage->m_slider->SetRange(0, (int)(llLength / 1000).GetValue());
+ currentpage->m_gauge->SetRange(100);
+
+
+ // if the slider is not being dragged then update it with the song position
+ if(currentpage->IsBeingDragged() == false)
+ currentpage->m_slider->SetValue((long)(llTell / 1000).GetValue());
+
+
+ // Update the gauge with the download progress
+ wxLongLong llDownloadProgress =
+ currentpage->m_mediactrl->GetDownloadProgress();
+ wxLongLong llDownloadTotal =
+ currentpage->m_mediactrl->GetDownloadTotal();
+
+ if(llDownloadTotal.GetValue() != 0)
+ {
+ currentpage->m_gauge->SetValue(
+ (int) ((llDownloadProgress * 100) / llDownloadTotal).GetValue()
+ );
+ }
+
+ // GetBestSize holds the original video size
+ wxSize videoSize = currentMediaCtrl->GetBestSize();
+
+ // Now the big part - set the status bar text to
+ // hold various metadata about the media
+#if wxUSE_STATUSBAR
+ m_frame->SetStatusText(wxString::Format(
+ wxT("Size(x,y):%i,%i ")
+ wxT("Position:%s/%s Speed:%1.1fx ")
+ wxT("State:%s Loops:%i D/T:[%i]/[%i] V:%i%%"),
+ videoSize.x,
+ videoSize.y,
+ sPosition.c_str(),
+ sDuration.c_str(),
+ currentMediaCtrl->GetPlaybackRate(),
+ wxGetMediaStateText(currentpage->m_mediactrl->GetState()),
+ currentpage->m_nLoops,
+ (int)llDownloadProgress.GetValue(),
+ (int)llDownloadTotal.GetValue(),
+ (int)(currentpage->m_mediactrl->GetVolume() * 100)));
+#endif // wxUSE_STATUSBAR
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//
+// wxMediaPlayerNotebookPage
+//
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage Constructor
+//
+// Creates a media control and slider and adds it to this panel,
+// along with some sizers for positioning
+// ----------------------------------------------------------------------------
+wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentFrame,
+ wxNotebook* theBook,
+ const wxString& szBackend)
+ : wxPanel(theBook, wxID_ANY),
+ m_nLastFileId(-1),
+ m_nLoops(0),
+ m_bLoop(false),
+ m_bIsBeingDragged(false),
+ m_parentFrame(parentFrame)
+{
+ //
+ // Layout
+ //
+ // [wxMediaCtrl]
+ // [playlist]
+ // [5 control buttons]
+ // [slider]
+ // [gauge]
+ //
+
+ //
+ // Create and attach a 2-column grid sizer
+ //
+ wxFlexGridSizer* sizer = new wxFlexGridSizer(2);
+ sizer->AddGrowableCol(0);
+ this->SetSizer(sizer);
+
+ //
+ // 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);
+
+ // Now that we have all our rows make some of them growable
+ sizer->AddGrowableRow(0);
+
+ //
+ // 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 )
+ wxMessageBox(wxT("Couldn't seek in movie!"));
+
+ m_bIsBeingDragged = false;
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::IsBeingDragged
+//
+// Returns true if the user is dragging the slider
+// ----------------------------------------------------------------------------
+bool wxMediaPlayerNotebookPage::IsBeingDragged()
+{
+ return m_bIsBeingDragged;
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::OnVolChange
+//
+// Called when the user is done dragging the volume-changing slider
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnVolChange(wxScrollEvent& WXUNUSED(event))
+{
+ if( m_mediactrl->SetVolume(
+ m_volSlider->GetValue() / 100.0
+ ) == false )
+ wxMessageBox(wxT("Couldn't set volume!"));
+
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::OnPBChange
+//
+// Called when the user is done dragging the speed-changing slider
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnPBChange(wxScrollEvent& WXUNUSED(event))
+{
+ if( m_mediactrl->SetPlaybackRate(
+ m_pbSlider->GetValue() * .25
+ ) == false )
+ wxMessageBox(wxT("Couldn't set playbackrate!"));
+
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::OnMediaPlay
+//
+// Called when the media plays.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnMediaPlay(wxMediaEvent& WXUNUSED(event))
+{
+ m_playlist->SetItem(m_nLastFileId, 0, wxT(">"));
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::OnMediaPause
+//
+// Called when the media is paused.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnMediaPause(wxMediaEvent& WXUNUSED(event))
+{
+ m_playlist->SetItem(m_nLastFileId, 0, wxT("||"));
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::OnMediaStop
+//
+// Called when the media stops.
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnMediaStop(wxMediaEvent& WXUNUSED(event))
+{
+ m_playlist->SetItem(m_nLastFileId, 0, wxT("[]"));
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerNotebookPage::OnMediaFinished
+//
+// Called when the media finishes playing.
+// Here we loop it if the user wants to (has been selected from file menu)
+// ----------------------------------------------------------------------------
+void wxMediaPlayerNotebookPage::OnMediaFinished(wxMediaEvent& WXUNUSED(event))
+{
+ if(m_bLoop)
+ {
+ if ( !m_mediactrl->Play() )
+ {
+ wxMessageBox(wxT("Couldn't loop movie!"));
+ m_playlist->SetItem(m_nLastFileId, 0, wxT("E"));
+ }
+ else
+ ++m_nLoops;
+ }
+ else
+ {
+ m_playlist->SetItem(m_nLastFileId, 0, wxT("[]"));
+ }
+}
+
+//
+// End of MediaPlayer sample
+//