2004-11-14 18:26:55 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-11-11 09:14:12 -05:00
|
|
|
// Name: mediaplayer.cpp
|
2004-11-11 00:40:58 -05:00
|
|
|
// Purpose: wxMediaCtrl sample
|
|
|
|
// Author: Ryan Norton
|
|
|
|
// Modified by:
|
|
|
|
// Created: 11/10/04
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Ryan Norton
|
|
|
|
// Licence: wxWindows licence
|
2004-11-14 18:26:55 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
// MediaPlayer
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// This is a somewhat comprehensive example of how to use all the funtionality
|
|
|
|
// of the wxMediaCtrl class in wxWidgets.
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// To use this sample, simply select Open File from the file menu,
|
2005-03-03 15:21:34 -05:00
|
|
|
// select the file you want to play - and MediaPlayer will play the file in a
|
2005-07-28 19:56:57 -04:00
|
|
|
// the current notebook page, showing video if necessary.
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// You can select one of the menu options, or move the slider around
|
|
|
|
// to manipulate what is playing.
|
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
// Known bugs with wxMediaCtrl:
|
2005-03-03 15:21:34 -05:00
|
|
|
//
|
2005-02-11 21:32:29 -05:00
|
|
|
// 1) Certain backends can't play the same media file at the same time (MCI,
|
|
|
|
// Cocoa NSMovieView-Quicktime).
|
2005-03-03 15:21:34 -05:00
|
|
|
// 2) Positioning on Mac Carbon is messed up if put in a sub-control like a
|
2006-02-10 14:37:40 -05:00
|
|
|
// Notebook (like this sample does).
|
2005-02-04 14:04:58 -05:00
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2004-11-11 00:40:58 -05:00
|
|
|
// ============================================================================
|
2004-11-14 18:26:55 -05:00
|
|
|
// Definitions
|
2004-11-11 00:40:58 -05:00
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 18:26:55 -05:00
|
|
|
// Pre-compiled header stuff
|
2004-11-11 00:40:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 18:26:55 -05:00
|
|
|
// Headers
|
2004-11-11 00:40:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-11 04:56:45 -05:00
|
|
|
#include "wx/mediactrl.h" //for wxMediaCtrl
|
|
|
|
#include "wx/filedlg.h" //for opening files from OpenFile
|
|
|
|
#include "wx/slider.h" //for a slider for seeking within media
|
|
|
|
#include "wx/sizer.h" //for positioning controls/wxBoxSizer
|
|
|
|
#include "wx/timer.h" //timer for updating status bar
|
2005-07-28 19:56:57 -04:00
|
|
|
#include "wx/textdlg.h" //for getting user text from OpenURL/Debug
|
2005-02-04 02:49:40 -05:00
|
|
|
#include "wx/notebook.h" //for wxNotebook and putting movies in pages
|
2005-07-28 19:56:57 -04:00
|
|
|
#include "wx/cmdline.h" //for wxCmdLineParser (optional)
|
|
|
|
#include "wx/listctrl.h" //for wxListCtrl
|
|
|
|
#include "wx/dnd.h" //drag and drop for the playlist
|
|
|
|
#include "wx/filename.h" //For wxFileName::GetName()
|
|
|
|
#include "wx/config.h" //for native wxConfig
|
2005-02-04 14:04:58 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-16 08:49:27 -05:00
|
|
|
// Bail out if the user doesn't want one of the
|
2004-11-14 18:26:55 -05:00
|
|
|
// things we need
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-08-08 19:12:39 -04:00
|
|
|
// RN: I'm not sure why this is here - even minimal doesn't check for
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxUSE_GUI. I may have added it myself though...
|
2004-11-14 18:26:55 -05:00
|
|
|
#if !wxUSE_GUI
|
|
|
|
#error "This is a GUI sample"
|
2004-11-11 00:40:58 -05:00
|
|
|
#endif
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
#if !wxUSE_MEDIACTRL || !wxUSE_MENUS || !wxUSE_SLIDER || !wxUSE_TIMER || \
|
2006-01-25 13:15:48 -05:00
|
|
|
!wxUSE_NOTEBOOK || !wxUSE_LISTCTRL
|
2005-07-28 19:56:57 -04:00
|
|
|
#error "Not all required elements are enabled. Please modify setup.h!"
|
2004-11-14 18:26:55 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// ============================================================================
|
2004-11-11 04:56:45 -05:00
|
|
|
// Declarations
|
2004-11-14 18:26:55 -05:00
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Enumurations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
// Menu event IDs
|
2004-11-14 18:26:55 -05:00
|
|
|
wxID_LOOP = 1,
|
2005-02-04 14:04:58 -05:00
|
|
|
wxID_OPENFILESAMEPAGE,
|
|
|
|
wxID_OPENFILENEWPAGE,
|
|
|
|
wxID_OPENURLSAMEPAGE,
|
|
|
|
wxID_OPENURLNEWPAGE,
|
|
|
|
wxID_CLOSECURRENTPAGE,
|
2004-11-14 18:26:55 -05:00
|
|
|
wxID_PLAY,
|
|
|
|
wxID_PAUSE,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxID_NEXT,
|
|
|
|
wxID_PREV,
|
|
|
|
wxID_SELECTBACKEND,
|
|
|
|
wxID_SHOWINTERFACE,
|
2004-11-14 18:26:55 -05:00
|
|
|
// wxID_STOP, [built-in to wxWidgets]
|
|
|
|
// wxID_ABOUT, [built-in to wxWidgets]
|
|
|
|
// wxID_EXIT, [built-in to wxWidgets]
|
2005-07-28 19:56:57 -04:00
|
|
|
// Control event IDs
|
2005-08-08 19:12:39 -04:00
|
|
|
wxID_SLIDER,
|
2006-02-10 14:37:40 -05:00
|
|
|
wxID_PBSLIDER,
|
|
|
|
wxID_VOLSLIDER,
|
2005-08-08 19:12:39 -04:00
|
|
|
wxID_NOTEBOOK,
|
|
|
|
wxID_MEDIACTRL,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxID_BUTTONNEXT,
|
|
|
|
wxID_BUTTONPREV,
|
|
|
|
wxID_BUTTONSTOP,
|
|
|
|
wxID_BUTTONPLAY,
|
|
|
|
wxID_BUTTONVD,
|
|
|
|
wxID_BUTTONVU,
|
|
|
|
wxID_LISTCTRL,
|
|
|
|
wxID_GAUGE
|
2004-11-14 18:26:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerApp
|
2004-11-11 00:40:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxMediaPlayerApp : public wxApp
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
|
|
|
public:
|
2005-07-28 19:56:57 -04:00
|
|
|
#ifdef __WXMAC__
|
2005-08-08 19:12:39 -04:00
|
|
|
virtual void MacOpenFile(const wxString & fileName );
|
2005-07-28 19:56:57 -04:00
|
|
|
#endif
|
2005-08-08 19:12:39 -04:00
|
|
|
|
2004-11-11 00:40:58 -05:00
|
|
|
virtual bool OnInit();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
class wxMediaPlayerFrame* m_frame;
|
2004-11-11 00:40:58 -05:00
|
|
|
};
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxMediaPlayerFrame : public wxFrame
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
|
|
|
public:
|
2004-11-14 18:26:55 -05:00
|
|
|
// Ctor/Dtor
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaPlayerFrame(const wxString& title);
|
|
|
|
~wxMediaPlayerFrame();
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// Menu event handlers
|
2004-11-11 00:40:58 -05:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
void OnOpenFileSamePage(wxCommandEvent& event);
|
|
|
|
void OnOpenFileNewPage(wxCommandEvent& event);
|
|
|
|
void OnOpenURLSamePage(wxCommandEvent& event);
|
|
|
|
void OnOpenURLNewPage(wxCommandEvent& event);
|
|
|
|
void OnCloseCurrentPage(wxCommandEvent& event);
|
2004-11-11 00:40:58 -05:00
|
|
|
|
|
|
|
void OnPlay(wxCommandEvent& event);
|
|
|
|
void OnPause(wxCommandEvent& event);
|
|
|
|
void OnStop(wxCommandEvent& event);
|
2005-07-28 19:56:57 -04:00
|
|
|
void OnNext(wxCommandEvent& event);
|
|
|
|
void OnPrev(wxCommandEvent& event);
|
|
|
|
void OnVolumeDown(wxCommandEvent& event);
|
|
|
|
void OnVolumeUp(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnLoop(wxCommandEvent& event);
|
|
|
|
void OnShowInterface(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnSelectBackend(wxCommandEvent& event);
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
// Key event handlers
|
|
|
|
void OnKeyDown(wxKeyEvent& event);
|
|
|
|
|
|
|
|
// Quickie for playing from command line
|
|
|
|
void AddToPlayList(const wxString& szString);
|
|
|
|
|
|
|
|
// ListCtrl event handlers
|
|
|
|
void OnChangeSong(wxListEvent& event);
|
|
|
|
|
|
|
|
// Media event handlers
|
|
|
|
void OnMediaLoaded(wxMediaEvent& event);
|
|
|
|
|
|
|
|
// Close event handlers
|
2005-08-08 19:12:39 -04:00
|
|
|
void OnClose(wxCloseEvent& event);
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2004-11-11 00:40:58 -05:00
|
|
|
private:
|
2005-02-04 14:04:58 -05:00
|
|
|
// Common open file code
|
|
|
|
void OpenFile(bool bNewPage);
|
|
|
|
void OpenURL(bool bNewPage);
|
2005-07-28 19:56:57 -04:00
|
|
|
void DoOpenFile(const wxString& path, bool bNewPage);
|
|
|
|
void DoPlayFile(const wxString& path);
|
2005-03-03 15:21:34 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxMediaPlayerTimer* m_timer; //Timer to write info to status bar
|
2005-03-18 06:50:18 -05:00
|
|
|
wxNotebook* m_notebook; //Notebook containing our pages
|
2004-11-14 18:26:55 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
// Maybe I should use more accessors, but for simplicity
|
|
|
|
// I'll allow the other classes access to our members
|
|
|
|
friend class wxMediaPlayerApp;
|
|
|
|
friend class wxMediaPlayerNotebookPage;
|
|
|
|
friend class wxMediaPlayerTimer;
|
2004-11-14 18:26:55 -05:00
|
|
|
};
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerNotebookPage
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxMediaPlayerNotebookPage : public wxPanel
|
2005-02-04 02:49:40 -05:00
|
|
|
{
|
2005-08-08 19:12:39 -04:00
|
|
|
wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentFrame,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxNotebook* book, const wxString& be = wxEmptyString);
|
2005-03-03 15:21:34 -05:00
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
// Slider event handlers
|
2005-07-28 19:56:57 -04:00
|
|
|
void OnBeginSeek(wxScrollEvent& event);
|
|
|
|
void OnEndSeek(wxScrollEvent& event);
|
2006-02-10 14:37:40 -05:00
|
|
|
void OnPBChange(wxScrollEvent& event);
|
|
|
|
void OnVolChange(wxScrollEvent& event);
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
// Media event handlers
|
2006-02-10 14:37:40 -05:00
|
|
|
void OnMediaPlay(wxMediaEvent& event);
|
|
|
|
void OnMediaPause(wxMediaEvent& event);
|
|
|
|
void OnMediaStop(wxMediaEvent& event);
|
2005-02-11 21:32:29 -05:00
|
|
|
void OnMediaFinished(wxMediaEvent& event);
|
2005-03-03 15:21:34 -05:00
|
|
|
|
2005-02-04 02:49:40 -05:00
|
|
|
public:
|
2005-07-28 19:56:57 -04:00
|
|
|
bool IsBeingDragged(); //accessor for m_bIsBeingDragged
|
|
|
|
|
|
|
|
//make wxMediaPlayerFrame able to access the private members
|
2005-08-08 19:12:39 -04:00
|
|
|
friend class wxMediaPlayerFrame;
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
int m_nLastFileId; //List ID of played file in listctrl
|
|
|
|
wxString m_szFile; //Name of currently playing file/location
|
|
|
|
|
2005-02-04 02:49:40 -05:00
|
|
|
wxMediaCtrl* m_mediactrl; //Our media control
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxMediaPlayerListCtrl* m_playlist; //Our playlist
|
2005-02-04 02:49:40 -05:00
|
|
|
wxSlider* m_slider; //The slider below our media control
|
2006-02-10 14:37:40 -05:00
|
|
|
wxSlider* m_pbSlider; //Lower-left slider for adjusting speed
|
|
|
|
wxSlider* m_volSlider; //Lower-right slider for adjusting volume
|
2005-02-04 14:04:58 -05:00
|
|
|
int m_nLoops; //Number of times media has looped
|
2005-02-11 21:32:29 -05:00
|
|
|
bool m_bLoop; //Whether we are looping or not
|
2005-07-28 19:56:57 -04:00
|
|
|
bool m_bIsBeingDragged; //Whether the user is dragging the scroll bar
|
|
|
|
wxMediaPlayerFrame* m_parentFrame; //Main wxFrame of our sample
|
|
|
|
wxButton* m_prevButton; //Go to previous file button
|
|
|
|
wxButton* m_playButton; //Play/pause file button
|
|
|
|
wxButton* m_stopButton; //Stop playing file button
|
|
|
|
wxButton* m_nextButton; //Next file button
|
|
|
|
wxButton* m_vdButton; //Volume down button
|
|
|
|
wxButton* m_vuButton; //Volume up button
|
|
|
|
wxGauge* m_gauge; //Gauge to keep in line with slider
|
2005-02-04 02:49:40 -05:00
|
|
|
};
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerTimer
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxMediaPlayerTimer : public wxTimer
|
2004-11-14 18:26:55 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//Ctor
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaPlayerTimer(wxMediaPlayerFrame* frame) {m_frame = frame;}
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
//Called each time the timer's timeout expires
|
|
|
|
void Notify();
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaPlayerFrame* m_frame; //The wxMediaPlayerFrame
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerListCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class wxMediaPlayerListCtrl : public wxListCtrl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void AddToPlayList(const wxString& szString)
|
|
|
|
{
|
|
|
|
wxListItem kNewItem;
|
|
|
|
kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
int nID = this->GetItemCount();
|
|
|
|
kNewItem.SetId(nID);
|
2005-07-28 19:56:57 -04:00
|
|
|
kNewItem.SetMask(wxLIST_MASK_DATA);
|
|
|
|
kNewItem.SetData(new wxString(szString));
|
|
|
|
|
|
|
|
this->InsertItem(kNewItem);
|
2005-09-11 07:04:00 -04:00
|
|
|
this->SetItem(nID, 0, wxT("*"));
|
2005-07-28 19:56:57 -04:00
|
|
|
this->SetItem(nID, 1, wxFileName(szString).GetName());
|
|
|
|
|
|
|
|
if (nID % 2)
|
|
|
|
{
|
|
|
|
kNewItem.SetBackgroundColour(wxColour(192,192,192));
|
|
|
|
this->SetItem(kNewItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetSelectedItem(wxListItem& listitem)
|
|
|
|
{
|
|
|
|
listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
|
|
|
|
int nLast = -1, nLastSelected = -1;
|
|
|
|
while ((nLast = this->GetNextItem(nLast,
|
|
|
|
wxLIST_NEXT_ALL,
|
|
|
|
wxLIST_STATE_SELECTED)) != -1)
|
|
|
|
{
|
|
|
|
listitem.SetId(nLast);
|
|
|
|
this->GetItem(listitem);
|
|
|
|
if ((listitem.GetState() & wxLIST_STATE_FOCUSED) )
|
|
|
|
break;
|
|
|
|
nLastSelected = nLast;
|
|
|
|
}
|
|
|
|
if (nLast == -1 && nLastSelected == -1)
|
|
|
|
return;
|
|
|
|
listitem.SetId(nLastSelected == -1 ? nLast : nLastSelected);
|
|
|
|
this->GetItem(listitem);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxPlayListDropTarget
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
// Drop target for playlist (i.e. user drags a file from explorer unto
|
2005-07-28 19:56:57 -04:00
|
|
|
// playlist it adds the file)
|
|
|
|
// ----------------------------------------------------------------------------
|
2006-01-25 13:15:48 -05:00
|
|
|
#if wxUSE_DRAG_AND_DROP
|
2005-07-28 19:56:57 -04:00
|
|
|
class wxPlayListDropTarget : public wxFileDropTarget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxPlayListDropTarget(wxMediaPlayerListCtrl& list) : m_list(list) {}
|
|
|
|
~wxPlayListDropTarget(){}
|
|
|
|
virtual bool OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
|
|
|
const wxArrayString& files)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < files.GetCount(); ++i)
|
|
|
|
{
|
|
|
|
m_list.AddToPlayList(files[i]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
wxMediaPlayerListCtrl& m_list;
|
2004-11-11 00:40:58 -05:00
|
|
|
};
|
2006-01-25 13:15:48 -05:00
|
|
|
#endif
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ============================================================================
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Implementation
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// ============================================================================
|
2004-11-11 04:56:45 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
|
|
|
// [Functions]
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxGetMediaStateText
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Converts a wxMediaCtrl state into something useful that we can display
|
|
|
|
// to the user
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 00:40:58 -05:00
|
|
|
const wxChar* wxGetMediaStateText(int nState)
|
|
|
|
{
|
|
|
|
switch(nState)
|
|
|
|
{
|
|
|
|
case wxMEDIASTATE_PLAYING:
|
|
|
|
return wxT("Playing");
|
|
|
|
case wxMEDIASTATE_STOPPED:
|
|
|
|
return wxT("Stopped");
|
|
|
|
///case wxMEDIASTATE_PAUSED:
|
|
|
|
default:
|
|
|
|
return wxT("Paused");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerApp
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2004-11-11 00:40:58 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 18:26:55 -05:00
|
|
|
// This sets up this wxApp as the global wxApp that gui calls in wxWidgets
|
|
|
|
// use. For example, if you were to be in windows and use a file dialog,
|
|
|
|
// wxWidgets would use wxTheApp->GetHInstance() which would get the instance
|
|
|
|
// handle of the application. These routines in wx _DO NOT_ check to see if
|
|
|
|
// the wxApp exists, and thus will crash the application if you try it.
|
|
|
|
//
|
|
|
|
// IMPLEMENT_APP does this, and also implements the platform-specific entry
|
2004-11-16 08:49:27 -05:00
|
|
|
// routine, such as main or WinMain(). Use IMPLEMENT_APP_NO_MAIN if you do
|
2004-11-14 18:26:55 -05:00
|
|
|
// not desire this behavior.
|
2004-11-11 00:40:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
IMPLEMENT_APP(wxMediaPlayerApp)
|
2004-11-11 00:40:58 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerApp::OnInit
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// Where execution starts - akin to a main or WinMain.
|
|
|
|
// 1) Create the frame and show it to the user
|
2005-07-28 19:56:57 -04:00
|
|
|
// 2) Process filenames from the commandline
|
|
|
|
// 3) return true specifying that we want execution to continue past OnInit
|
2004-11-11 00:40:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
bool wxMediaPlayerApp::OnInit()
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2006-02-10 14:37:40 -05:00
|
|
|
// SetAppName() lets wxConfig and others know where to write
|
|
|
|
SetAppName(wxT("wxMediaPlayer"));
|
|
|
|
|
2005-08-08 19:12:39 -04:00
|
|
|
wxMediaPlayerFrame *frame =
|
2005-09-11 07:04:00 -04:00
|
|
|
new wxMediaPlayerFrame(wxT("MediaPlayer wxWidgets Sample"));
|
2004-11-11 00:40:58 -05:00
|
|
|
frame->Show(true);
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
#if wxUSE_CMDLINE_PARSER
|
2005-08-08 19:12:39 -04:00
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// What this does is get all the command line arguments
|
|
|
|
// and treat each one as a file to put to the initial playlist
|
|
|
|
//
|
|
|
|
wxCmdLineEntryDesc cmdLineDesc[2];
|
|
|
|
cmdLineDesc[0].kind = wxCMD_LINE_PARAM;
|
|
|
|
cmdLineDesc[0].shortName = NULL;
|
|
|
|
cmdLineDesc[0].longName = NULL;
|
|
|
|
cmdLineDesc[0].description = wxT("input files");
|
|
|
|
cmdLineDesc[0].type = wxCMD_LINE_VAL_STRING;
|
|
|
|
cmdLineDesc[0].flags = wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE;
|
|
|
|
|
|
|
|
cmdLineDesc[1].kind = wxCMD_LINE_NONE;
|
|
|
|
|
|
|
|
//gets the passed media files from cmd line
|
|
|
|
wxCmdLineParser parser (cmdLineDesc, argc, argv);
|
|
|
|
|
|
|
|
// get filenames from the commandline
|
2005-08-08 19:12:39 -04:00
|
|
|
if (parser.Parse() == 0)
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2005-08-08 19:12:39 -04:00
|
|
|
for (size_t paramNr=0; paramNr < parser.GetParamCount(); ++paramNr)
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
|
|
|
frame->AddToPlayList((parser.GetParam (paramNr)));
|
|
|
|
}
|
2006-02-10 14:37:40 -05:00
|
|
|
wxCommandEvent theEvent(wxEVT_COMMAND_MENU_SELECTED, wxID_NEXT);
|
|
|
|
frame->AddPendingEvent(theEvent);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-11-11 00:40:58 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-08-08 19:12:39 -04:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
|
|
|
|
void wxMediaPlayerApp::MacOpenFile(const wxString & fileName )
|
|
|
|
{
|
|
|
|
//Called when a user drags a file over our app
|
|
|
|
m_frame->DoOpenFile(fileName, true /* new page */);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WXMAC__
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame Constructor
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// 1) Create our menus
|
2005-02-04 14:04:58 -05:00
|
|
|
// 2) Create our notebook control and add it to the frame
|
2004-11-14 18:26:55 -05:00
|
|
|
// 3) Create our status bar
|
|
|
|
// 4) Connect our events
|
|
|
|
// 5) Start our timer
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-12-17 11:07:21 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title)
|
2005-09-11 07:04:00 -04:00
|
|
|
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600,600))
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
|
|
|
// Create Menus
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMenu *fileMenu = new wxMenu;
|
|
|
|
wxMenu *controlsMenu = new wxMenu;
|
|
|
|
wxMenu *optionsMenu = new wxMenu;
|
2004-11-11 00:40:58 -05:00
|
|
|
wxMenu *helpMenu = new wxMenu;
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMenu *debugMenu = new wxMenu;
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
fileMenu->Append(wxID_OPENFILESAMEPAGE, wxT("&Open File\tCtrl-Shift-O"),
|
|
|
|
wxT("Open a File in the current notebook page"));
|
|
|
|
fileMenu->Append(wxID_OPENFILENEWPAGE, wxT("&Open File in a new page"),
|
|
|
|
wxT("Open a File in a new notebook page"));
|
|
|
|
fileMenu->Append(wxID_OPENURLSAMEPAGE, wxT("&Open URL"),
|
|
|
|
wxT("Open a URL in the current notebook page"));
|
|
|
|
fileMenu->Append(wxID_OPENURLNEWPAGE, wxT("&Open URL in a new page"),
|
|
|
|
wxT("Open a URL in a new notebook page"));
|
2005-07-28 19:56:57 -04:00
|
|
|
fileMenu->AppendSeparator();
|
2005-09-11 07:04:00 -04:00
|
|
|
fileMenu->Append(wxID_CLOSECURRENTPAGE, wxT("&Close Current Page\tCtrl-C"),
|
|
|
|
wxT("Close current notebook page"));
|
2005-07-28 19:56:57 -04:00
|
|
|
fileMenu->AppendSeparator();
|
|
|
|
fileMenu->Append(wxID_EXIT,
|
2005-09-11 07:04:00 -04:00
|
|
|
wxT("E&xit\tAlt-X"),
|
|
|
|
wxT("Quit this program"));
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
controlsMenu->Append(wxID_PLAY, wxT("&Play/Pause\tCtrl-P"), wxT("Resume/Pause playback"));
|
|
|
|
controlsMenu->Append(wxID_STOP, wxT("&Stop\tCtrl-S"), wxT("Stop playback"));
|
2005-07-28 19:56:57 -04:00
|
|
|
controlsMenu->AppendSeparator();
|
2005-09-11 07:04:00 -04:00
|
|
|
controlsMenu->Append(wxID_PREV, wxT("&Previous\tCtrl-B"), wxT("Go to previous track"));
|
|
|
|
controlsMenu->Append(wxID_NEXT, wxT("&Next\tCtrl-N"), wxT("Skip to next track"));
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
optionsMenu->AppendCheckItem(wxID_LOOP,
|
2005-09-11 07:04:00 -04:00
|
|
|
wxT("&Loop\tCtrl-L"),
|
|
|
|
wxT("Loop Selected Media"));
|
2005-07-28 19:56:57 -04:00
|
|
|
optionsMenu->AppendCheckItem(wxID_SHOWINTERFACE,
|
2005-09-11 07:04:00 -04:00
|
|
|
wxT("&Show Interface\tCtrl-I"),
|
|
|
|
wxT("Show wxMediaCtrl native controls"));
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
debugMenu->Append(wxID_SELECTBACKEND,
|
2005-09-11 07:04:00 -04:00
|
|
|
wxT("&Select Backend...\tCtrl-D"),
|
|
|
|
wxT("Select a backend manually"));
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
helpMenu->Append(wxID_ABOUT,
|
2005-09-11 07:04:00 -04:00
|
|
|
wxT("&About...\tF1"),
|
|
|
|
wxT("Show about dialog"));
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
|
2004-11-11 00:40:58 -05:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
2005-09-11 07:04:00 -04:00
|
|
|
menuBar->Append(fileMenu, wxT("&File"));
|
|
|
|
menuBar->Append(controlsMenu, wxT("&Controls"));
|
|
|
|
menuBar->Append(optionsMenu, wxT("&Options"));
|
|
|
|
menuBar->Append(debugMenu, wxT("&Debug"));
|
|
|
|
menuBar->Append(helpMenu, wxT("&Help"));
|
2004-11-11 00:40:58 -05:00
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
2005-03-03 15:21:34 -05:00
|
|
|
// Create our notebook - using wxNotebook is luckily pretty
|
2005-02-04 14:04:58 -05:00
|
|
|
// simple and self-explanatory in most cases
|
|
|
|
//
|
2005-02-04 02:49:40 -05:00
|
|
|
m_notebook = new wxNotebook(this, wxID_NOTEBOOK);
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
|
|
|
// Create our status bar
|
|
|
|
//
|
2004-11-11 00:40:58 -05:00
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
// create a status bar just for fun (by default with 1 pane only)
|
|
|
|
CreateStatusBar(1);
|
|
|
|
#endif // wxUSE_STATUSBAR
|
2004-11-16 08:49:27 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// Connect events.
|
2004-11-16 08:49:27 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// There are two ways in wxWidgets to use events -
|
|
|
|
// Message Maps and Connections.
|
|
|
|
//
|
|
|
|
// Message Maps are implemented by putting
|
|
|
|
// DECLARE_MESSAGE_MAP in your wxEvtHandler-derived
|
2005-07-28 19:56:57 -04:00
|
|
|
// class you want to use for events, such as wxMediaPlayerFrame.
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// Then after your class declaration you put
|
2005-07-28 19:56:57 -04:00
|
|
|
// BEGIN_EVENT_TABLE(wxMediaPlayerFrame, wxFrame)
|
2004-11-14 18:26:55 -05:00
|
|
|
// EVT_XXX(XXX)...
|
|
|
|
// END_EVENT_TABLE()
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// Where wxMediaPlayerFrame is the class with the DECLARE_MESSAGE_MAP
|
2004-11-16 08:49:27 -05:00
|
|
|
// in it. EVT_XXX(XXX) are each of your handlers, such
|
2004-11-14 18:26:55 -05:00
|
|
|
// as EVT_MENU for menu events and the XXX inside
|
|
|
|
// is the parameters to the event macro - in the case
|
|
|
|
// of EVT_MENU the menu id and then the function to call.
|
|
|
|
//
|
|
|
|
// However, with wxEvtHandler::Connect you can avoid a
|
|
|
|
// global message map for your class and those annoying
|
|
|
|
// macros. You can also change the context in which
|
|
|
|
// the call the handler (more later).
|
|
|
|
//
|
|
|
|
// The downside is that due to the limitation that
|
|
|
|
// wxWidgets doesn't use templates in certain areas,
|
|
|
|
// You have to triple-cast the event function.
|
|
|
|
//
|
|
|
|
// There are five parameters to wxEvtHandler::Connect -
|
|
|
|
//
|
|
|
|
// The first is the id of the instance whose events
|
|
|
|
// you want to handle - i.e. a menu id for menus,
|
|
|
|
// a control id for controls (wxControl::GetId())
|
|
|
|
// and so on.
|
|
|
|
//
|
|
|
|
// The second is the event id. This is the same
|
|
|
|
// as the message maps (EVT_MENU) except prefixed
|
|
|
|
// with "wx" (wxEVT_MENU).
|
|
|
|
//
|
|
|
|
// The third is the function handler for the event -
|
|
|
|
// You need to cast it to the specific event handler
|
2004-11-16 08:49:27 -05:00
|
|
|
// type, then to a wxEventFunction, then to a
|
2004-11-14 18:26:55 -05:00
|
|
|
// wxObjectEventFunction - I.E.
|
|
|
|
// (wxObjectEventFunction)(wxEventFunction)
|
2005-07-28 19:56:57 -04:00
|
|
|
// (wxCommandEventFunction) &wxMediaPlayerFrame::MyHandler
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
2005-03-18 06:50:18 -05:00
|
|
|
// Or, you can use the new (2.5.5+) event handler
|
|
|
|
// conversion macros - for instance the above could
|
2005-07-22 13:56:31 -04:00
|
|
|
// be done as
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxCommandEventHandler(wxMediaPlayerFrame::MyHandler)
|
2005-03-18 06:50:18 -05:00
|
|
|
// pretty simple, eh?
|
|
|
|
//
|
2004-11-16 08:49:27 -05:00
|
|
|
// The fourth is an optional userdata param -
|
2004-11-14 18:26:55 -05:00
|
|
|
// this is of historical relevance only and is
|
2005-02-16 14:25:35 -05:00
|
|
|
// there only for backwards compatibility.
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// The fifth is the context in which to call the
|
|
|
|
// handler - by default (this param is optional)
|
|
|
|
// this. For example in your event handler
|
2004-11-16 08:49:27 -05:00
|
|
|
// if you were to call "this->MyFunc()"
|
2004-11-14 18:26:55 -05:00
|
|
|
// it would literally do this->MyFunc. However,
|
|
|
|
// if you were to pass myHandler as the fifth
|
|
|
|
// parameter, for instance, you would _really_
|
|
|
|
// be calling myHandler->MyFunc, even though
|
|
|
|
// the compiler doesn't really know it.
|
|
|
|
//
|
2004-11-11 04:56:45 -05:00
|
|
|
|
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Menu events
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-16 08:49:27 -05:00
|
|
|
this->Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnQuit));
|
2004-11-16 08:49:27 -05:00
|
|
|
|
|
|
|
this->Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnAbout));
|
2004-11-14 18:26:55 -05:00
|
|
|
|
2004-11-16 08:49:27 -05:00
|
|
|
this->Connect(wxID_LOOP, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnLoop));
|
|
|
|
|
|
|
|
this->Connect(wxID_SHOWINTERFACE, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnShowInterface));
|
2004-11-14 18:26:55 -05:00
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
this->Connect(wxID_OPENFILENEWPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenFileNewPage));
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
this->Connect(wxID_OPENFILESAMEPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenFileSamePage));
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
this->Connect(wxID_OPENURLNEWPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenURLNewPage));
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
this->Connect(wxID_OPENURLSAMEPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenURLSamePage));
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
this->Connect(wxID_CLOSECURRENTPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnCloseCurrentPage));
|
2004-11-11 04:56:45 -05:00
|
|
|
|
2004-11-16 08:49:27 -05:00
|
|
|
this->Connect(wxID_PLAY, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnPlay));
|
2004-11-14 18:26:55 -05:00
|
|
|
|
2004-11-16 08:49:27 -05:00
|
|
|
this->Connect(wxID_STOP, wxEVT_COMMAND_MENU_SELECTED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnStop));
|
|
|
|
|
|
|
|
this->Connect(wxID_NEXT, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnNext));
|
|
|
|
|
|
|
|
this->Connect(wxID_PREV, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnPrev));
|
|
|
|
|
|
|
|
this->Connect(wxID_SELECTBACKEND, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnSelectBackend));
|
2004-11-14 18:26:55 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// Key events
|
|
|
|
//
|
|
|
|
wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN,
|
|
|
|
wxKeyEventHandler(wxMediaPlayerFrame::OnKeyDown),
|
|
|
|
(wxObject*)0, this);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Close events
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCloseEventHandler(wxMediaPlayerFrame::OnClose));
|
2005-03-03 15:21:34 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// End of Events
|
|
|
|
//
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
// Create an initial notebook page so the user has something
|
2005-07-28 19:56:57 -04:00
|
|
|
// to work with without having to go file->open every time :).
|
|
|
|
//
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* page =
|
|
|
|
new wxMediaPlayerNotebookPage(this, m_notebook);
|
|
|
|
m_notebook->AddPage(page,
|
2005-08-08 19:12:39 -04:00
|
|
|
wxT(""),
|
2005-07-28 19:56:57 -04:00
|
|
|
true);
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
//
|
|
|
|
// Here we load the our configuration -
|
|
|
|
// in our case we load all the files that were left in
|
|
|
|
// the playlist the last time the user closed our application
|
|
|
|
//
|
|
|
|
// As an exercise to the reader try modifying it so that
|
|
|
|
// it properly loads the playlist for each page without
|
|
|
|
// conflicting (loading the same data) with the other ones.
|
|
|
|
//
|
2006-02-10 14:37:40 -05:00
|
|
|
wxConfig conf;
|
2005-09-11 07:04:00 -04:00
|
|
|
wxString key, outstring;
|
|
|
|
for(int i = 0; ; ++i)
|
|
|
|
{
|
|
|
|
key.clear();
|
|
|
|
key << i;
|
2006-02-10 14:37:40 -05:00
|
|
|
if(!conf.Read(key, &outstring))
|
2005-09-11 07:04:00 -04:00
|
|
|
break;
|
|
|
|
page->m_playlist->AddToPlayList(outstring);
|
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// Create a timer to update our status bar
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
m_timer = new wxMediaPlayerTimer(this);
|
2006-02-10 14:37:40 -05:00
|
|
|
m_timer->Start(500);
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame Destructor
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-16 08:49:27 -05:00
|
|
|
// 1) Deletes child objects implicitly
|
2004-11-14 18:26:55 -05:00
|
|
|
// 2) Delete our timer explicitly
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaPlayerFrame::~wxMediaPlayerFrame()
|
|
|
|
{
|
2006-02-10 14:37:40 -05:00
|
|
|
// Shut down our timer
|
|
|
|
delete m_timer;
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// Here we save our info to the registry or whatever
|
|
|
|
// mechanism the OS uses.
|
|
|
|
//
|
|
|
|
// This makes it so that when mediaplayer loads up again
|
|
|
|
// it restores the same files that were in the playlist
|
|
|
|
// this time, rather than the user manually re-adding them.
|
|
|
|
//
|
|
|
|
// We need to do conf->DeleteAll() here because by default
|
|
|
|
// the config still contains the same files as last time
|
|
|
|
// so we need to clear it before writing our new ones.
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
// TODO: Maybe you could add a menu option to the
|
2005-07-28 19:56:57 -04:00
|
|
|
// options menu to delete the configuration on exit -
|
|
|
|
// all you'd need to do is just remove everything after
|
|
|
|
// conf->DeleteAll() here
|
|
|
|
//
|
2005-09-11 07:04:00 -04:00
|
|
|
// As an exercise to the reader, try modifying this so
|
|
|
|
// that it saves the data for each notebook page
|
|
|
|
//
|
|
|
|
wxMediaPlayerListCtrl* playlist =
|
|
|
|
((wxMediaPlayerNotebookPage*)m_notebook->GetPage(0))->m_playlist;
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2006-02-10 14:37:40 -05:00
|
|
|
wxConfig conf;
|
|
|
|
conf.DeleteAll();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
for(int i = 0; i < playlist->GetItemCount(); ++i)
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxString* pData = (wxString*) playlist->GetItemData(i);
|
2005-07-28 19:56:57 -04:00
|
|
|
wxString s;
|
|
|
|
s << i;
|
2006-02-10 14:37:40 -05:00
|
|
|
conf.Write(s, *(pData));
|
2005-07-28 19:56:57 -04:00
|
|
|
delete pData;
|
|
|
|
}
|
2005-09-11 07:04:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::OnClose
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
event.Skip(); //really close the frame
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::AddToPlayList
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::AddToPlayList(const wxString& szString)
|
2005-08-08 19:12:39 -04:00
|
|
|
{
|
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
2005-07-28 19:56:57 -04:00
|
|
|
((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage());
|
2005-08-08 19:12:39 -04:00
|
|
|
|
|
|
|
currentpage->m_playlist->AddToPlayList(szString);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::OnQuit
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Called from file->quit.
|
|
|
|
// Closes this application.
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnAbout
|
2004-11-16 08:49:27 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Called from help->about.
|
|
|
|
// Gets some info about this application.
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
|
|
|
wxString msg;
|
2006-02-10 14:37:40 -05:00
|
|
|
msg.Printf( wxT("This is a test of wxMediaCtrl.\n\n")
|
|
|
|
|
|
|
|
wxT("Intructions:\n")
|
|
|
|
|
|
|
|
wxT("The top slider shows the current the current position, ")
|
|
|
|
wxT("which you can change by dragging and releasing it.\n")
|
|
|
|
|
|
|
|
wxT("The gauge (progress bar) shows the progress in ")
|
|
|
|
wxT("downloading data of the current file - it may always be ")
|
|
|
|
wxT("Empty due to lack of support from the current backend.\n")
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2006-02-10 14:37:40 -05:00
|
|
|
wxT("The lower-left slider controls the volume and the lower-")
|
|
|
|
wxT("right slider controls the playback rate/speed of the ")
|
|
|
|
wxT("media\n\n")
|
|
|
|
|
|
|
|
wxT("Currently using: %s"), wxVERSION_STRING);
|
|
|
|
|
|
|
|
wxMessageBox(msg, wxT("About wxMediaCtrl test"),
|
|
|
|
wxOK | wxICON_INFORMATION, this);
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnLoop
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Called from file->loop.
|
|
|
|
// Changes the state of whether we want to loop or not.
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage());
|
2005-02-11 21:32:29 -05:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_bLoop = !currentpage->m_bLoop;
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnLoop
|
|
|
|
//
|
|
|
|
// Called from file->loop.
|
|
|
|
// Changes the state of whether we want to loop or not.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::OnShowInterface(wxCommandEvent& event)
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage());
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->ShowPlayerControls(event.IsChecked() ?
|
2005-08-08 19:12:39 -04:00
|
|
|
wxMEDIACTRLPLAYERCONTROLS_DEFAULT :
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMEDIACTRLPLAYERCONTROLS_NONE) )
|
|
|
|
{
|
|
|
|
//error - uncheck and warn user
|
|
|
|
wxMenuItem* pSIItem = GetMenuBar()->FindItem(wxID_SHOWINTERFACE);
|
|
|
|
wxASSERT(pSIItem);
|
|
|
|
pSIItem->Check(!event.IsChecked());
|
|
|
|
|
|
|
|
if(event.IsChecked())
|
|
|
|
wxMessageBox(wxT("Could not show player controls"));
|
|
|
|
else
|
|
|
|
wxMessageBox(wxT("Could not hide player controls"));
|
|
|
|
}
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::OnOpenFileSamePage
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Called from file->openfile.
|
2005-02-04 14:04:58 -05:00
|
|
|
// Opens and plays a media file in the current notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnOpenFileSamePage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 15:21:34 -05:00
|
|
|
{
|
|
|
|
OpenFile(false);
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnOpenFileNewPage
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// Called from file->openfileinnewpage.
|
|
|
|
// Opens and plays a media file in a new notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnOpenFileNewPage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 15:21:34 -05:00
|
|
|
{
|
|
|
|
OpenFile(true);
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OpenFile
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// Opens a file dialog asking the user for a filename, then
|
|
|
|
// calls DoOpenFile which will add the file to the playlist and play it
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OpenFile(bool bNewPage)
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
|
|
|
wxFileDialog fd(this);
|
|
|
|
|
|
|
|
if(fd.ShowModal() == wxID_OK)
|
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
DoOpenFile(fd.GetPath(), bNewPage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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(
|
2005-08-08 19:12:39 -04:00
|
|
|
new wxMediaPlayerNotebookPage(this, m_notebook),
|
|
|
|
path,
|
2005-07-28 19:56:57 -04:00
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if(currentpage->m_nLastFileId != -1)
|
|
|
|
currentpage->m_playlist->SetItemState(currentpage->m_nLastFileId,
|
|
|
|
0, wxLIST_STATE_SELECTED);
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
wxListItem newlistitem;
|
|
|
|
newlistitem.SetAlign(wxLIST_FORMAT_LEFT);
|
|
|
|
|
|
|
|
int nID;
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
newlistitem.SetId(nID = currentpage->m_playlist->GetItemCount());
|
2005-07-28 19:56:57 -04:00
|
|
|
newlistitem.SetMask(wxLIST_MASK_DATA | wxLIST_MASK_STATE);
|
|
|
|
newlistitem.SetState(wxLIST_STATE_SELECTED);
|
|
|
|
newlistitem.SetData(new wxString(path));
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->InsertItem(newlistitem);
|
|
|
|
currentpage->m_playlist->SetItem(nID, 0, wxT("*"));
|
|
|
|
currentpage->m_playlist->SetItem(nID, 1, wxFileName(path).GetName());
|
2005-08-08 19:12:39 -04:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
if (nID % 2)
|
|
|
|
{
|
|
|
|
newlistitem.SetBackgroundColour(wxColour(192,192,192));
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(newlistitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
2005-03-03 15:21:34 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
DoPlayFile(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::DoPlayFile
|
|
|
|
//
|
|
|
|
// Pauses the file if its the currently playing file,
|
|
|
|
// otherwise it plays the file
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::DoPlayFile(const wxString& path)
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
wxListItem listitem;
|
2005-09-11 07:04:00 -04:00
|
|
|
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)
|
|
|
|
)
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
if(currentpage->m_mediactrl->GetState() == wxMEDIASTATE_PLAYING)
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->Pause() )
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMessageBox(wxT("Couldn't pause movie!"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->Play() )
|
|
|
|
wxMessageBox(wxT("Couldn't play movie!"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
int nNewId = listitem.GetData() ? listitem.GetId() :
|
|
|
|
currentpage->m_playlist->GetItemCount()-1;
|
2005-08-08 19:12:39 -04:00
|
|
|
m_notebook->SetPageText(m_notebook->GetSelection(),
|
2005-07-28 19:56:57 -04:00
|
|
|
wxFileName(path).GetName());
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if(currentpage->m_nLastFileId != -1)
|
|
|
|
currentpage->m_playlist->SetItem(
|
|
|
|
currentpage->m_nLastFileId, 0, wxT("*"));
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
wxURI uripath(path);
|
|
|
|
if( uripath.IsReference() )
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->Load(path) )
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
|
|
|
wxMessageBox(wxT("Couldn't load file!"));
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(nNewId, 0, wxT("E"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(nNewId, 0, wxT("O"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->Load(uripath) )
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMessageBox(wxT("Couldn't load URL!"));
|
|
|
|
currentpage->m_playlist->SetItem(nNewId, 0, wxT("E"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(nNewId, 0, wxT("O"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
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(""));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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))
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->Play() )
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2004-11-12 09:23:02 -05:00
|
|
|
wxMessageBox(wxT("Couldn't play movie!"));
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(currentpage->m_nLastFileId, 0, wxT("E"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(currentpage->m_nLastFileId, 0, wxT(">"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-02-10 14:37:40 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2005-08-08 19:12:39 -04:00
|
|
|
m_notebook->AddPage(new wxMediaPlayerNotebookPage(this, m_notebook,
|
2005-07-28 19:56:57 -04:00
|
|
|
sBackend
|
|
|
|
), wxT(""), true);
|
2005-09-11 07:04:00 -04:00
|
|
|
|
|
|
|
DoOpenFile(
|
|
|
|
((wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage())->m_szFile,
|
|
|
|
false);
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnOpenURLSamePage
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// Called from file->openurl.
|
|
|
|
// Opens and plays a media file from a URL in the current notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 15:21:34 -05:00
|
|
|
{
|
|
|
|
OpenURL(false);
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnOpenURLNewPage
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// Called from file->openurlinnewpage.
|
|
|
|
// Opens and plays a media file from a URL in a new notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnOpenURLNewPage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 15:21:34 -05:00
|
|
|
{
|
|
|
|
OpenURL(true);
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OpenURL
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// Just calls DoOpenFile with the url path - which calls DoPlayFile
|
|
|
|
// which handles the real dirty work
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OpenURL(bool bNewPage)
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
wxString sUrl = wxGetTextFromUser(
|
|
|
|
wxT("Enter the URL that has the movie to play")
|
|
|
|
);
|
2005-02-04 14:04:58 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
if(sUrl.empty() == false) //could have been cancelled by user
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
DoOpenFile(sUrl, bNewPage);
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnCloseCurrentPage
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnCloseCurrentPage(wxCommandEvent& WXUNUSED(event))
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
if( m_notebook->GetPageCount() > 1 )
|
|
|
|
{
|
2005-02-04 14:04:58 -05:00
|
|
|
int sel = m_notebook->GetSelection();
|
|
|
|
|
|
|
|
if (sel != wxNOT_FOUND)
|
|
|
|
{
|
|
|
|
m_notebook->DeletePage(sel);
|
2005-03-03 15:21:34 -05:00
|
|
|
}
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox(wxT("Cannot close main page"));
|
|
|
|
}
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnPlay
|
2004-11-16 08:49:27 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// Called from file->play.
|
|
|
|
// Resumes the media if it is paused or stopped.
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
wxListItem listitem;
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->GetSelectedItem(listitem);
|
2005-08-08 19:12:39 -04:00
|
|
|
if ( !listitem.GetData() )
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
int nLast = -1;
|
2005-09-11 07:04:00 -04:00
|
|
|
if ((nLast = currentpage->m_playlist->GetNextItem(nLast,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxLIST_NEXT_ALL,
|
|
|
|
wxLIST_STATE_DONTCARE)) == -1)
|
|
|
|
{
|
|
|
|
//no items in list
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMessageBox(wxT("No items in playlist!"));
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
2005-09-11 07:04:00 -04:00
|
|
|
else
|
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
listitem.SetId(nLast);
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->GetItem(listitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
|
|
|
|
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(listitem);
|
|
|
|
wxASSERT(listitem.GetData());
|
|
|
|
DoPlayFile((*((wxString*) listitem.GetData())));
|
|
|
|
}
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxASSERT(listitem.GetData());
|
|
|
|
DoPlayFile((*((wxString*) listitem.GetData())));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnKeyDown
|
2004-11-16 08:49:27 -05:00
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// Deletes all selected files from the playlist if the backspace key is pressed
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnKeyDown(wxKeyEvent& event)
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
if(event.GetKeyCode() == WXK_BACK/*DELETE*/)
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
//delete all selected items
|
|
|
|
while(true)
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(
|
2005-07-28 19:56:57 -04:00
|
|
|
-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
|
|
if (nSelectedItem == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
wxListItem listitem;
|
|
|
|
listitem.SetId(nSelectedItem);
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->GetItem(listitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
delete (wxString*) listitem.GetData();
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->DeleteItem(nSelectedItem);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//Could be wxGetTextFromUser or something else important
|
|
|
|
if(event.GetEventObject() != this)
|
2005-08-08 19:12:39 -04:00
|
|
|
event.Skip();
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnStop
|
2004-11-16 08:49:27 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// 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
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerFrame::OnStop(wxCommandEvent& WXUNUSED(evt))
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2004-11-11 00:40:58 -05:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if( !currentpage->m_mediactrl->Stop() )
|
2005-02-04 14:04:58 -05:00
|
|
|
wxMessageBox(wxT("Couldn't stop movie!"));
|
2005-09-11 07:04:00 -04:00
|
|
|
else
|
|
|
|
currentpage->m_playlist->SetItem(
|
|
|
|
currentpage->m_nLastFileId, 0, wxT("[]"));
|
2004-11-11 00:40:58 -05:00
|
|
|
}
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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))
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
wxListItem listitem;
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->GetSelectedItem(listitem);
|
|
|
|
if(listitem.GetData())
|
2005-07-28 19:56:57 -04:00
|
|
|
DoPlayFile((*((wxString*) listitem.GetData())));
|
2005-09-11 07:04:00 -04:00
|
|
|
else
|
|
|
|
wxMessageBox(wxT("No selected item!"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::OnPrev
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
// Tedious wxListCtrl stuff. Goes to prevous song in list, or if at the
|
2005-07-28 19:56:57 -04:00
|
|
|
// beginning goes to the last in the list.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::OnPrev(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if (currentpage->m_playlist->GetItemCount() == 0)
|
2005-07-28 19:56:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
wxInt32 nLastSelectedItem = -1;
|
|
|
|
while(true)
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(nLastSelectedItem,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
|
|
if (nSelectedItem == -1)
|
|
|
|
break;
|
|
|
|
nLastSelectedItem = nSelectedItem;
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
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;
|
2005-07-28 19:56:57 -04:00
|
|
|
else
|
|
|
|
nLastSelectedItem -= 1;
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if(nLastSelectedItem == currentpage->m_nLastFileId)
|
|
|
|
return; //already playing... nothing to do
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
wxListItem listitem;
|
|
|
|
listitem.SetId(nLastSelectedItem);
|
2005-09-11 07:04:00 -04:00
|
|
|
listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
|
|
|
|
currentpage->m_playlist->GetItem(listitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
|
|
|
|
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(listitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
wxASSERT(listitem.GetData());
|
|
|
|
DoPlayFile((*((wxString*) listitem.GetData())));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerFrame::OnNext
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
// Tedious wxListCtrl stuff. Goes to next song in list, or if at the
|
2005-07-28 19:56:57 -04:00
|
|
|
// end goes to the first in the list.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::OnNext(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if (currentpage->m_playlist->GetItemCount() == 0)
|
2005-07-28 19:56:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
wxInt32 nLastSelectedItem = -1;
|
|
|
|
while(true)
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(nLastSelectedItem,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
|
|
if (nSelectedItem == -1)
|
|
|
|
break;
|
|
|
|
nLastSelectedItem = nSelectedItem;
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nLastSelectedItem == -1)
|
2005-09-11 07:04:00 -04:00
|
|
|
{
|
|
|
|
if(currentpage->m_nLastFileId == currentpage->m_playlist->GetItemCount() - 1)
|
2005-07-28 19:56:57 -04:00
|
|
|
nLastSelectedItem = 0;
|
|
|
|
else
|
2005-09-11 07:04:00 -04:00
|
|
|
nLastSelectedItem = currentpage->m_nLastFileId + 1;
|
|
|
|
}
|
|
|
|
else if (nLastSelectedItem == currentpage->m_playlist->GetItemCount() - 1)
|
2005-07-28 19:56:57 -04:00
|
|
|
nLastSelectedItem = 0;
|
|
|
|
else
|
|
|
|
nLastSelectedItem += 1;
|
2005-09-11 07:04:00 -04:00
|
|
|
|
|
|
|
if(nLastSelectedItem == currentpage->m_nLastFileId)
|
|
|
|
return; //already playing... nothing to do
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
wxListItem listitem;
|
2005-09-11 07:04:00 -04:00
|
|
|
listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
|
2005-07-28 19:56:57 -04:00
|
|
|
listitem.SetId(nLastSelectedItem);
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->GetItem(listitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
|
|
|
|
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
|
2005-09-11 07:04:00 -04:00
|
|
|
currentpage->m_playlist->SetItem(listitem);
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
wxASSERT(listitem.GetData());
|
|
|
|
DoPlayFile((*((wxString*) listitem.GetData())));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::OnVolumeDown
|
|
|
|
//
|
2006-02-10 14:37:40 -05:00
|
|
|
// Lowers the volume of the media control by 5%
|
2005-07-28 19:56:57 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::OnVolumeDown(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
|
|
|
|
|
|
|
double dVolume = currentpage->m_mediactrl->GetVolume();
|
2006-02-10 14:37:40 -05:00
|
|
|
currentpage->m_mediactrl->SetVolume(dVolume < 0.05 ? 0.0 : dVolume - .05);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerFrame::OnVolumeUp
|
|
|
|
//
|
2006-02-10 14:37:40 -05:00
|
|
|
// Increases the volume of the media control by 5%
|
2005-07-28 19:56:57 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxMediaPlayerFrame::OnVolumeUp(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
|
|
|
|
|
|
|
|
double dVolume = currentpage->m_mediactrl->GetVolume();
|
2006-02-10 14:37:40 -05:00
|
|
|
currentpage->m_mediactrl->SetVolume(dVolume > 0.95 ? 1.0 : dVolume + .05);
|
2005-02-04 02:49:40 -05:00
|
|
|
}
|
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerTimer
|
2004-11-11 04:56:45 -05:00
|
|
|
//
|
2004-11-14 18:26:55 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerTimer::Notify
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
2006-02-10 14:37:40 -05:00
|
|
|
// 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
|
2004-11-14 18:26:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerTimer::Notify()
|
2004-11-11 00:40:58 -05:00
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
wxMediaPlayerNotebookPage* currentpage =
|
|
|
|
(wxMediaPlayerNotebookPage*) m_frame->m_notebook->GetCurrentPage();
|
2006-02-10 14:37:40 -05:00
|
|
|
wxMediaCtrl* currentMediaCtrl = currentpage->m_mediactrl;
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
if(currentpage)
|
|
|
|
{
|
2006-02-10 14:37:40 -05:00
|
|
|
// 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
|
2005-09-11 07:04:00 -04:00
|
|
|
if(currentpage->IsBeingDragged() == false)
|
2006-02-10 14:37:40 -05:00
|
|
|
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)
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2006-02-10 14:37:40 -05:00
|
|
|
currentpage->m_gauge->SetValue(
|
|
|
|
(int) ((llDownloadProgress * 100) / llDownloadTotal).GetValue()
|
|
|
|
);
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
|
|
|
|
2006-02-10 14:37:40 -05:00
|
|
|
// 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
|
2004-11-14 18:26:55 -05:00
|
|
|
#if wxUSE_STATUSBAR
|
2005-07-28 19:56:57 -04:00
|
|
|
m_frame->SetStatusText(wxString::Format(
|
2006-02-10 14:37:40 -05:00
|
|
|
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(),
|
2005-09-11 07:04:00 -04:00
|
|
|
wxGetMediaStateText(currentpage->m_mediactrl->GetState()),
|
|
|
|
currentpage->m_nLoops,
|
2006-02-10 14:37:40 -05:00
|
|
|
(int)llDownloadProgress.GetValue(),
|
|
|
|
(int)llDownloadTotal.GetValue(),
|
2005-09-11 07:04:00 -04:00
|
|
|
(int)(currentpage->m_mediactrl->GetVolume() * 100)));
|
2005-07-28 19:56:57 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
}
|
2005-02-04 02:49:40 -05:00
|
|
|
}
|
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerNotebookPage
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// wxMediaPlayerNotebookPage Constructor
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// Creates a media control and slider and adds it to this panel,
|
|
|
|
// along with some sizers for positioning
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentFrame,
|
2005-08-08 19:12:39 -04:00
|
|
|
wxNotebook* theBook,
|
|
|
|
const wxString& szBackend)
|
|
|
|
: wxPanel(theBook, wxID_ANY),
|
2005-09-11 07:04:00 -04:00
|
|
|
m_nLastFileId(-1),
|
2005-08-08 19:12:39 -04:00
|
|
|
m_nLoops(0),
|
|
|
|
m_bLoop(false),
|
|
|
|
m_bIsBeingDragged(false),
|
|
|
|
m_parentFrame(parentFrame)
|
2005-02-04 02:49:40 -05:00
|
|
|
{
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// Layout
|
|
|
|
//
|
|
|
|
// [wxMediaCtrl]
|
|
|
|
// [playlist]
|
|
|
|
// [5 control buttons]
|
|
|
|
// [slider]
|
|
|
|
// [gauge]
|
2005-08-08 19:12:39 -04:00
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
|
2005-02-04 02:49:40 -05:00
|
|
|
//
|
2005-05-31 17:12:22 -04:00
|
|
|
// Create and attach the sizer
|
2005-02-04 02:49:40 -05:00
|
|
|
//
|
2005-05-31 17:12:22 -04:00
|
|
|
wxFlexGridSizer* sizer = new wxFlexGridSizer(2, 1, 0, 0);
|
|
|
|
this->SetSizer(sizer);
|
2005-02-04 02:49:40 -05:00
|
|
|
this->SetAutoLayout(true);
|
2005-05-31 17:12:22 -04:00
|
|
|
sizer->AddGrowableRow(0);
|
|
|
|
sizer->AddGrowableCol(0);
|
2005-02-04 02:49:40 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create our media control
|
|
|
|
//
|
2005-02-12 14:32:26 -05:00
|
|
|
m_mediactrl = new wxMediaCtrl();
|
2005-03-03 15:21:34 -05:00
|
|
|
|
2005-02-12 14:32:26 -05:00
|
|
|
// Make sure creation was successful
|
2005-07-28 19:56:57 -04:00
|
|
|
bool bOK = m_mediactrl->Create(this, wxID_MEDIACTRL, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0,
|
|
|
|
//you could specify a macrod backend here like
|
2006-02-10 14:37:40 -05:00
|
|
|
// wxMEDIABACKEND_WMP10);
|
|
|
|
// wxT("wxPDFMediaBackend"));
|
2005-07-28 19:56:57 -04:00
|
|
|
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
|
2005-02-12 14:32:26 -05:00
|
|
|
wxASSERT_MSG(bOK, wxT("Could not create media control!"));
|
2005-03-03 15:21:34 -05:00
|
|
|
wxUnusedVar(bOK);
|
|
|
|
|
2005-05-31 17:12:22 -04:00
|
|
|
sizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
|
2005-02-04 02:49:40 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// Create the playlist/listctrl
|
|
|
|
//
|
|
|
|
m_playlist = new wxMediaPlayerListCtrl();
|
2005-08-08 19:12:39 -04:00
|
|
|
m_playlist->Create(this, wxID_LISTCTRL, wxDefaultPosition,
|
2005-07-28 19:56:57 -04:00
|
|
|
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
|
2005-08-08 19:12:39 -04:00
|
|
|
// E - Error has occured
|
2005-07-28 19:56:57 -04:00
|
|
|
// > - Currently Playing
|
|
|
|
// [] - Stopped
|
|
|
|
// || - Paused
|
2006-02-10 14:37:40 -05:00
|
|
|
// (( - Volume Down 5%
|
|
|
|
// )) - Volume Up 5%
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
2006-01-25 13:15:48 -05:00
|
|
|
#if wxUSE_DRAG_AND_DROP
|
2005-07-28 19:56:57 -04:00
|
|
|
m_playlist->SetDropTarget(new wxPlayListDropTarget(*m_playlist));
|
2006-01-25 13:15:48 -05:00
|
|
|
#endif
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
sizer->Add(m_playlist, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
|
|
|
|
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
// Create the control buttons
|
2005-07-28 19:56:57 -04:00
|
|
|
// 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();
|
|
|
|
|
2005-09-11 07:04:00 -04:00
|
|
|
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("))"));
|
2005-07-28 19:56:57 -04:00
|
|
|
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);
|
2006-02-10 14:37:40 -05:00
|
|
|
sizer->Add(horsizer1, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
|
2005-02-04 02:49:40 -05:00
|
|
|
//
|
|
|
|
// Create our slider
|
|
|
|
//
|
|
|
|
m_slider = new wxSlider(this, wxID_SLIDER, 0, //init
|
|
|
|
0, //start
|
|
|
|
0, //end
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxSL_HORIZONTAL );
|
2005-05-31 17:12:22 -04:00
|
|
|
sizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
|
2005-02-04 02:49:40 -05:00
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// 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);
|
2005-08-08 19:12:39 -04:00
|
|
|
|
2006-02-10 14:37:40 -05:00
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
2005-07-28 19:56:57 -04:00
|
|
|
//
|
|
|
|
// ListCtrl events
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_LISTCTRL, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxListEventHandler(wxMediaPlayerFrame::OnChangeSong),
|
|
|
|
(wxObject*)0, parentFrame);
|
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// Slider events
|
|
|
|
//
|
2005-07-28 19:56:57 -04:00
|
|
|
this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBTRACK,
|
|
|
|
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnBeginSeek));
|
|
|
|
this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBRELEASE,
|
|
|
|
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnEndSeek));
|
2006-02-10 14:37:40 -05:00
|
|
|
this->Connect(wxID_PBSLIDER, wxEVT_SCROLL_THUMBRELEASE,
|
|
|
|
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnPBChange));
|
|
|
|
this->Connect(wxID_VOLSLIDER, wxEVT_SCROLL_THUMBRELEASE,
|
|
|
|
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnVolChange));
|
2005-02-04 14:04:58 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Media Control events
|
|
|
|
//
|
2006-02-10 14:37:40 -05:00
|
|
|
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));
|
2005-02-11 21:32:29 -05:00
|
|
|
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaFinished));
|
|
|
|
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_LOADED,
|
2005-08-08 19:12:39 -04:00
|
|
|
wxMediaEventHandler(wxMediaPlayerFrame::OnMediaLoaded),
|
2005-07-28 19:56:57 -04:00
|
|
|
(wxObject*)0, parentFrame);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Button events
|
|
|
|
//
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_BUTTONPREV, wxEVT_COMMAND_BUTTON_CLICKED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnPrev),
|
|
|
|
(wxObject*)0, parentFrame);
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_BUTTONPLAY, wxEVT_COMMAND_BUTTON_CLICKED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnPlay),
|
|
|
|
(wxObject*)0, parentFrame);
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_BUTTONSTOP, wxEVT_COMMAND_BUTTON_CLICKED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnStop),
|
|
|
|
(wxObject*)0, parentFrame);
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_BUTTONNEXT, wxEVT_COMMAND_BUTTON_CLICKED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnNext),
|
|
|
|
(wxObject*)0, parentFrame);
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_BUTTONVD, wxEVT_COMMAND_BUTTON_CLICKED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeDown),
|
|
|
|
(wxObject*)0, parentFrame);
|
2005-08-08 19:12:39 -04:00
|
|
|
this->Connect( wxID_BUTTONVU, wxEVT_COMMAND_BUTTON_CLICKED,
|
2005-07-28 19:56:57 -04:00
|
|
|
wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeUp),
|
|
|
|
(wxObject*)0, parentFrame);
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
// 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
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
|
|
|
// Called from file->seek.
|
|
|
|
// Called when the user moves the slider -
|
|
|
|
// seeks to a position within the media
|
2005-07-28 19:56:57 -04:00
|
|
|
// then sets m_bIsBeingDragged to false to ok the timer to change the position
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerNotebookPage::OnEndSeek(wxScrollEvent& WXUNUSED(event))
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-03-03 15:21:34 -05:00
|
|
|
if( m_mediactrl->Seek(
|
|
|
|
m_slider->GetValue() * 1000
|
2005-02-04 14:04:58 -05:00
|
|
|
) == wxInvalidOffset )
|
|
|
|
wxMessageBox(wxT("Couldn't seek in movie!"));
|
2005-07-28 19:56:57 -04:00
|
|
|
|
|
|
|
m_bIsBeingDragged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMediaPlayerNotebookPage::IsBeingDragged
|
|
|
|
//
|
|
|
|
// Returns true if the user is dragging the slider
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool wxMediaPlayerNotebookPage::IsBeingDragged()
|
2005-08-08 19:12:39 -04:00
|
|
|
{
|
|
|
|
return m_bIsBeingDragged;
|
2004-11-12 09:23:02 -05:00
|
|
|
}
|
2004-11-14 18:26:55 -05:00
|
|
|
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2006-02-10 14:37:40 -05:00
|
|
|
// 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
|
2005-02-04 14:04:58 -05:00
|
|
|
//
|
2006-02-10 14:37:40 -05:00
|
|
|
// Called when the media finishes playing.
|
2005-02-11 21:32:29 -05:00
|
|
|
// Here we loop it if the user wants to (has been selected from file menu)
|
2005-02-04 14:04:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-07-28 19:56:57 -04:00
|
|
|
void wxMediaPlayerNotebookPage::OnMediaFinished(wxMediaEvent& WXUNUSED(event))
|
2005-02-04 14:04:58 -05:00
|
|
|
{
|
2005-02-11 21:32:29 -05:00
|
|
|
if(m_bLoop)
|
|
|
|
{
|
|
|
|
if ( !m_mediactrl->Play() )
|
2005-07-28 19:56:57 -04:00
|
|
|
{
|
2005-02-11 21:32:29 -05:00
|
|
|
wxMessageBox(wxT("Couldn't loop movie!"));
|
2005-09-11 07:04:00 -04:00
|
|
|
m_playlist->SetItem(m_nLastFileId, 0, wxT("E"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
2005-02-11 21:32:29 -05:00
|
|
|
else
|
|
|
|
++m_nLoops;
|
|
|
|
}
|
2005-07-28 19:56:57 -04:00
|
|
|
else
|
|
|
|
{
|
2005-09-11 07:04:00 -04:00
|
|
|
m_playlist->SetItem(m_nLastFileId, 0, wxT("[]"));
|
2005-07-28 19:56:57 -04:00
|
|
|
}
|
2005-02-04 14:04:58 -05:00
|
|
|
}
|
2005-02-04 02:49:40 -05:00
|
|
|
|
2004-11-14 18:26:55 -05:00
|
|
|
//
|
|
|
|
// End of MediaPlayer sample
|
|
|
|
//
|