+
+// ----------------------------------------------------------------------------
+// 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))
+{
+ wxMediaPlayerListCtrl* m_playlist =
+ ((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage())->m_playlist;
+
+ wxListItem listitem;
+ m_playlist->GetSelectedItem(listitem);
+ DoPlayFile((*((wxString*) listitem.GetData())));
+}
+
+// ----------------------------------------------------------------------------
+// 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))
+{
+ wxMediaPlayerListCtrl* m_playlist =
+ ((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage())->m_playlist;
+
+ if (m_playlist->GetItemCount() == 0)
+ return;
+
+ wxInt32 nLastSelectedItem = -1;
+ while(true)
+ {
+ wxInt32 nSelectedItem = m_playlist->GetNextItem(nLastSelectedItem,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (nSelectedItem == -1)
+ break;
+ nLastSelectedItem = nSelectedItem;
+ m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
+ }
+
+ if (nLastSelectedItem <= 0)
+ nLastSelectedItem = m_playlist->GetItemCount() - 1;
+ else
+ nLastSelectedItem -= 1;
+
+ wxListItem listitem;
+ listitem.SetId(nLastSelectedItem);
+ m_playlist->GetItem(listitem);
+ listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
+ listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
+ m_playlist->SetItem(listitem);
+
+ wxListEvent emptyEvent;
+ OnChangeSong(emptyEvent);
+}
+
+// ----------------------------------------------------------------------------
+// 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))
+{
+ wxMediaPlayerListCtrl* m_playlist =
+ ((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage())->m_playlist;
+
+ if (m_playlist->GetItemCount() == 0)
+ return;
+
+ wxInt32 nLastSelectedItem = -1;
+ while(true)
+ {
+ wxInt32 nSelectedItem = m_playlist->GetNextItem(nLastSelectedItem,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (nSelectedItem == -1)
+ break;
+ nLastSelectedItem = nSelectedItem;
+ m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
+ }
+
+ if (nLastSelectedItem == -1)
+ nLastSelectedItem = 0;
+ else
+ {
+ if (nLastSelectedItem == m_playlist->GetItemCount() - 1)
+ nLastSelectedItem = 0;
+ else
+ nLastSelectedItem += 1;
+ }
+
+ wxListItem listitem;
+ listitem.SetId(nLastSelectedItem);
+ m_playlist->GetItem(listitem);
+ listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
+ listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
+ m_playlist->SetItem(listitem);
+
+ wxListEvent emptyEvent;
+ OnChangeSong(emptyEvent);
+}
+
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnVolumeDown
+//
+// Lowers the volume of the media control by 10%
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnVolumeDown(wxCommandEvent& WXUNUSED(event))
+{
+ double dVolume = GetCurrentMediaCtrl()->GetVolume();
+ GetCurrentMediaCtrl()->SetVolume(dVolume < 0.1 ? 0.0 : dVolume - .1);
+}
+
+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::OnVolumeUp
+//
+// Increases the volume of the media control by 10%
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::OnVolumeUp(wxCommandEvent& WXUNUSED(event))
+{
+ double dVolume = GetCurrentMediaCtrl()->GetVolume();
+ GetCurrentMediaCtrl()->SetVolume(dVolume > 0.9 ? 1.0 : dVolume + .1);
+}
+