#include "wx/filename.h" //For wxFileName::GetName()
#include "wx/config.h" //for native wxConfig
+#ifndef __WXMSW__
+ #include "../sample.xpm"
+#endif
+
// ----------------------------------------------------------------------------
// Bail out if the user doesn't want one of the
// things we need
wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600,600))
{
+ SetIcon(wxICON(sample));
+
//
// Create Menus
//
// Create an initial notebook page so the user has something
// to work with without having to go file->open every time :).
//
- wxMediaPlayerNotebookPage* page =
+ wxMediaPlayerNotebookPage* page =
new wxMediaPlayerNotebookPage(this, m_notebook);
m_notebook->AddPage(page,
wxT(""),
wxMenuItem* pSIItem = GetMenuBar()->FindItem(wxID_SHOWINTERFACE);
wxASSERT(pSIItem);
pSIItem->Check(!event.IsChecked());
-
+
if(event.IsChecked())
wxMessageBox(wxT("Could not show player controls"));
else
true);
}
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if(currentpage->m_nLastFileId != -1)
- currentpage->m_playlist->SetItemState(currentpage->m_nLastFileId,
+ currentpage->m_playlist->SetItemState(currentpage->m_nLastFileId,
0, wxLIST_STATE_SELECTED);
wxListItem newlistitem;
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::DoPlayFile(const wxString& path)
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
wxListItem listitem;
}
else
{
- int nNewId = listitem.GetData() ? listitem.GetId() :
+ int nNewId = listitem.GetData() ? listitem.GetId() :
currentpage->m_playlist->GetItemCount()-1;
m_notebook->SetPageText(m_notebook->GetSelection(),
wxFileName(path).GetName());
currentpage->m_nLastFileId = nNewId;
currentpage->m_szFile = path;
- currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
+ currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
1, wxFileName(path).GetName());
- currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
+ currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
2, wxT(""));
}
}
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnMediaLoaded(wxMediaEvent& WXUNUSED(evt))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if( !currentpage->m_mediactrl->Play() )
), wxT(""), true);
DoOpenFile(
- ((wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage())->m_szFile,
+ ((wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage())->m_szFile,
false);
}
}
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
wxListItem listitem;
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
currentpage->m_playlist->SetItem(listitem);
wxASSERT(listitem.GetData());
- DoPlayFile((*((wxString*) listitem.GetData())));
+ DoPlayFile((*((wxString*) listitem.GetData())));
}
}
else
{
if(event.GetKeyCode() == WXK_BACK/*DELETE*/)
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
//delete all selected items
while(true)
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnStop(wxCommandEvent& WXUNUSED(evt))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if( !currentpage->m_mediactrl->Stop() )
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnChangeSong(wxListEvent& WXUNUSED(evt))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
wxListItem listitem;
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnPrev(wxCommandEvent& WXUNUSED(event))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if (currentpage->m_playlist->GetItemCount() == 0)
currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
}
- if (nLastSelectedItem == -1)
+ if (nLastSelectedItem == -1)
{
//nothing selected, default to the file before the currently playing one
if(currentpage->m_nLastFileId == 0)
else
nLastSelectedItem = currentpage->m_nLastFileId - 1;
}
- else if (nLastSelectedItem == 0)
+ else if (nLastSelectedItem == 0)
nLastSelectedItem = currentpage->m_playlist->GetItemCount() - 1;
else
nLastSelectedItem -= 1;
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnNext(wxCommandEvent& WXUNUSED(event))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if (currentpage->m_playlist->GetItemCount() == 0)
if(currentpage->m_nLastFileId == currentpage->m_playlist->GetItemCount() - 1)
nLastSelectedItem = 0;
else
- nLastSelectedItem = currentpage->m_nLastFileId + 1;
+ nLastSelectedItem = currentpage->m_nLastFileId + 1;
}
else if (nLastSelectedItem == currentpage->m_playlist->GetItemCount() - 1)
nLastSelectedItem = 0;
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnVolumeDown(wxCommandEvent& WXUNUSED(event))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
double dVolume = currentpage->m_mediactrl->GetVolume();
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnVolumeUp(wxCommandEvent& WXUNUSED(event))
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
double dVolume = currentpage->m_mediactrl->GetVolume();
// ----------------------------------------------------------------------------
void wxMediaPlayerTimer::Notify()
{
- wxMediaPlayerNotebookPage* currentpage =
+ wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_frame->m_notebook->GetCurrentPage();
wxMediaCtrl* currentMediaCtrl = currentpage->m_mediactrl;
- if(currentpage)
- {
- // Number of minutes/seconds total
- wxLongLong llLength = currentpage->m_mediactrl->Length();
- int nMinutes = (int) (llLength / 60000).GetValue();
- int nSeconds = (int) ((llLength % 60000)/1000).GetValue();
+ // 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);
+ // 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();
+ // 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);
+ // 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);
+ // 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);
+ // 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());
+ // 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();
+ // 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()
- );
- }
+ if(llDownloadTotal.GetValue() != 0)
+ {
+ currentpage->m_gauge->SetValue(
+ (int) ((llDownloadProgress * 100) / llDownloadTotal).GetValue()
+ );
+ }
- // GetBestSize holds the original video size
- wxSize videoSize = currentMediaCtrl->GetBestSize();
+ // 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
+ // 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)));
+ 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
- }
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//
- // Create and attach the sizer
+ // Create and attach a 2-column grid sizer
//
- wxFlexGridSizer* sizer = new wxFlexGridSizer(2, 1, 0, 0);
- this->SetSizer(sizer);
- sizer->AddGrowableRow(0);
+ wxFlexGridSizer* sizer = new wxFlexGridSizer(2);
sizer->AddGrowableCol(0);
+ this->SetSizer(sizer);
//
// Create our media control
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
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
//