+// ----------------------------------------------------------------------------
+// wxMediaPlayerFrame::DoOpenFile
+//
+// Adds the file to our playlist, selects it in the playlist,
+// and then calls DoPlayFile to play it
+// ----------------------------------------------------------------------------
+void wxMediaPlayerFrame::DoOpenFile(const wxString& path, bool bNewPage)
+{
+ if(bNewPage)
+ {
+ m_notebook->AddPage(
+ new wxMediaPlayerNotebookPage(this, m_notebook),
+ path,
+ true);
+ }
+
+ 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() )
+ {