2004-11-14 23:26:55 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-11-11 14:14:12 +00:00
|
|
|
// Name: mediaplayer.cpp
|
2004-11-11 05:40:58 +00: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 23:26:55 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
// MediaPlayer
|
|
|
|
//
|
2004-11-16 13:49:27 +00:00
|
|
|
// This is a simple example of how to use all the funtionality of
|
2004-11-14 23:26:55 +00:00
|
|
|
// the wxMediaCtrl class in wxWidgets.
|
|
|
|
//
|
|
|
|
// To use this sample, simply select Open File from the file menu,
|
2005-03-03 20:21:34 +00:00
|
|
|
// select the file you want to play - and MediaPlayer will play the file in a
|
2005-02-04 19:04:58 +00:00
|
|
|
// new notebook page, showing video if neccessary.
|
2004-11-14 23:26:55 +00:00
|
|
|
//
|
|
|
|
// You can select one of the menu options, or move the slider around
|
|
|
|
// to manipulate what is playing.
|
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
// Known bugs with wxMediaCtrl:
|
2005-03-03 20:21:34 +00:00
|
|
|
//
|
2005-02-12 02:32:29 +00:00
|
|
|
// 1) Certain backends can't play the same media file at the same time (MCI,
|
|
|
|
// Cocoa NSMovieView-Quicktime).
|
2005-03-03 20:21:34 +00:00
|
|
|
// 2) Positioning on Mac Carbon is messed up if put in a sub-control like a
|
2005-02-12 02:32:29 +00:00
|
|
|
// Notebook (like this sample does) on OS versions < 10.2.
|
2005-02-04 19:04:58 +00:00
|
|
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2004-11-11 05:40:58 +00:00
|
|
|
// ============================================================================
|
2004-11-14 23:26:55 +00:00
|
|
|
// Definitions
|
2004-11-11 05:40:58 +00:00
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 23:26:55 +00:00
|
|
|
// Pre-compiled header stuff
|
2004-11-11 05:40:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 23:26:55 +00:00
|
|
|
// Headers
|
2004-11-11 05:40:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-11 09:56:45 +00: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
|
|
|
|
#include "wx/textdlg.h" //for getting user text from OpenURL
|
2005-02-04 07:49:40 +00:00
|
|
|
#include "wx/notebook.h" //for wxNotebook and putting movies in pages
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// Use some stuff that's not part of the current API, such as loading
|
|
|
|
// media from a URL, etc.
|
|
|
|
#define wxUSE_UNOFFICIALSTUFF 0
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-16 13:49:27 +00:00
|
|
|
// Bail out if the user doesn't want one of the
|
2004-11-14 23:26:55 +00:00
|
|
|
// things we need
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
#if !wxUSE_GUI
|
|
|
|
#error "This is a GUI sample"
|
2004-11-11 05:40:58 +00:00
|
|
|
#endif
|
|
|
|
|
2005-02-04 07:49:40 +00:00
|
|
|
#if !wxUSE_MEDIACTRL || !wxUSE_MENUS || !wxUSE_SLIDER || !wxUSE_TIMER || !wxUSE_NOTEBOOK
|
|
|
|
#error "menus, slider, mediactrl, notebook, and timers must all be enabled for this sample!"
|
2004-11-14 23:26:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// ============================================================================
|
2004-11-11 09:56:45 +00:00
|
|
|
// Declarations
|
2004-11-14 23:26:55 +00:00
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Enumurations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// menu items
|
|
|
|
wxID_LOOP = 1,
|
2005-02-04 19:04:58 +00:00
|
|
|
wxID_OPENFILESAMEPAGE,
|
|
|
|
wxID_OPENFILENEWPAGE,
|
|
|
|
wxID_OPENURLSAMEPAGE,
|
|
|
|
wxID_OPENURLNEWPAGE,
|
|
|
|
wxID_CLOSECURRENTPAGE,
|
2004-11-14 23:26:55 +00:00
|
|
|
wxID_PLAY,
|
|
|
|
wxID_PAUSE,
|
|
|
|
// wxID_STOP, [built-in to wxWidgets]
|
|
|
|
// wxID_ABOUT, [built-in to wxWidgets]
|
|
|
|
// wxID_EXIT, [built-in to wxWidgets]
|
2005-03-18 11:50:18 +00:00
|
|
|
wxID_SLIDER, // event id for our slider
|
|
|
|
wxID_NOTEBOOK, // event id for our notebook
|
|
|
|
wxID_MEDIACTRL // event id for our wxMediaCtrl
|
2004-11-14 23:26:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
2004-11-11 05:40:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-11 05:40:58 +00:00
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2004-11-14 23:26:55 +00:00
|
|
|
// Ctor/Dtor
|
2004-11-11 05:40:58 +00:00
|
|
|
MyFrame(const wxString& title);
|
|
|
|
~MyFrame();
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// Menu event handlers
|
2004-11-11 05:40:58 +00:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnLoop(wxCommandEvent& event);
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
void OnOpenFileSamePage(wxCommandEvent& event);
|
|
|
|
void OnOpenFileNewPage(wxCommandEvent& event);
|
|
|
|
void OnOpenURLSamePage(wxCommandEvent& event);
|
|
|
|
void OnOpenURLNewPage(wxCommandEvent& event);
|
|
|
|
void OnCloseCurrentPage(wxCommandEvent& event);
|
2004-11-11 05:40:58 +00:00
|
|
|
|
|
|
|
void OnPlay(wxCommandEvent& event);
|
|
|
|
void OnPause(wxCommandEvent& event);
|
|
|
|
void OnStop(wxCommandEvent& event);
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// Notebook event handlers
|
2005-02-04 07:49:40 +00:00
|
|
|
void OnPageChange(wxNotebookEvent& event);
|
2004-11-11 05:40:58 +00:00
|
|
|
|
|
|
|
private:
|
2004-11-14 23:26:55 +00:00
|
|
|
// Rebuild base status string (see Implementation)
|
2004-11-11 09:56:45 +00:00
|
|
|
void ResetStatus();
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// Common open file code
|
|
|
|
void OpenFile(bool bNewPage);
|
|
|
|
void OpenURL(bool bNewPage);
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// Get the media control and slider of current notebook page
|
|
|
|
wxMediaCtrl* GetCurrentMediaCtrl();
|
|
|
|
wxSlider* GetCurrentSlider();
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
class MyTimer* m_timer; //Timer to write info to status bar
|
|
|
|
wxString m_basestatus; //Base status string (see ResetStatus())
|
2005-03-18 11:50:18 +00:00
|
|
|
wxNotebook* m_notebook; //Notebook containing our pages
|
2004-11-14 23:26:55 +00:00
|
|
|
|
|
|
|
// So that mytimer can access MyFrame's members
|
2004-11-11 05:40:58 +00:00
|
|
|
friend class MyTimer;
|
2004-11-14 23:26:55 +00:00
|
|
|
};
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyNotebookPage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-02-04 07:49:40 +00:00
|
|
|
class MyNotebookPage : public wxPanel
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
MyNotebookPage(wxNotebook* book);
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// Slider event handlers
|
|
|
|
void OnSeek(wxCommandEvent& event);
|
|
|
|
|
|
|
|
// Media event handlers
|
2005-02-12 02:32:29 +00:00
|
|
|
void OnMediaFinished(wxMediaEvent& event);
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2005-02-04 07:49:40 +00:00
|
|
|
public:
|
2005-02-04 19:04:58 +00:00
|
|
|
friend class MyFrame; //make MyFrame able to access private members
|
2005-02-04 07:49:40 +00:00
|
|
|
wxMediaCtrl* m_mediactrl; //Our media control
|
|
|
|
wxSlider* m_slider; //The slider below our media control
|
2005-02-04 19:04:58 +00:00
|
|
|
int m_nLoops; //Number of times media has looped
|
2005-02-12 02:32:29 +00:00
|
|
|
bool m_bLoop; //Whether we are looping or not
|
2005-02-04 07:49:40 +00:00
|
|
|
};
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyTimer
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyTimer : public wxTimer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//Ctor
|
|
|
|
MyTimer(MyFrame* frame) {m_frame = frame;}
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
//Called each time the timer's timeout expires
|
|
|
|
void Notify();
|
|
|
|
|
|
|
|
MyFrame* m_frame; //The MyFrame
|
2004-11-11 05:40:58 +00:00
|
|
|
};
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ============================================================================
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Implementation
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// ============================================================================
|
2004-11-11 09:56:45 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
|
|
|
// [Functions]
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxGetMediaStateText
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Converts a wxMediaCtrl state into something useful that we can display
|
|
|
|
// to the user
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00: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 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
|
|
|
// MyApp
|
|
|
|
//
|
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2004-11-11 05:40:58 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 23:26:55 +00: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 13:49:27 +00:00
|
|
|
// routine, such as main or WinMain(). Use IMPLEMENT_APP_NO_MAIN if you do
|
2004-11-14 23:26:55 +00:00
|
|
|
// not desire this behavior.
|
2004-11-11 05:40:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-14 23:26:55 +00:00
|
|
|
// MyApp::OnInit
|
|
|
|
//
|
|
|
|
// Where execution starts - akin to a main or WinMain.
|
|
|
|
// 1) Create the frame and show it to the user
|
|
|
|
// 2) return true specifying that we want execution to continue past OnInit
|
2004-11-11 05:40:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2004-11-14 23:26:55 +00:00
|
|
|
MyFrame *frame = new MyFrame(_T("MediaPlayer wxWidgets Sample"));
|
2004-11-11 05:40:58 +00:00
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
|
|
|
// MyFrame
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame Constructor
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// 1) Create our menus
|
2005-02-04 19:04:58 +00:00
|
|
|
// 2) Create our notebook control and add it to the frame
|
2004-11-14 23:26:55 +00:00
|
|
|
// 3) Create our status bar
|
|
|
|
// 4) Connect our events
|
|
|
|
// 5) Start our timer
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-12-17 16:07:21 +00:00
|
|
|
|
2004-11-11 05:40:58 +00:00
|
|
|
MyFrame::MyFrame(const wxString& title)
|
2004-11-14 23:26:55 +00:00
|
|
|
: wxFrame(NULL, wxID_ANY, title)
|
2004-11-11 05:40:58 +00:00
|
|
|
{
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
|
|
|
// Create Menus
|
|
|
|
//
|
2004-11-11 05:40:58 +00:00
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
2004-11-16 13:49:27 +00:00
|
|
|
helpMenu->Append(wxID_ABOUT,
|
|
|
|
_T("&About...\tF1"),
|
2004-11-14 23:26:55 +00:00
|
|
|
_T("Show about dialog"));
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2005-03-03 20:21:34 +00:00
|
|
|
menuFile->Append(wxID_OPENFILESAMEPAGE, _T("&Open File"),
|
2005-02-04 19:04:58 +00:00
|
|
|
_T("Open a File in the current notebook page"));
|
2005-03-03 20:21:34 +00:00
|
|
|
menuFile->Append(wxID_OPENFILENEWPAGE, _T("&Open File in a new page"),
|
2005-02-04 19:04:58 +00:00
|
|
|
_T("Open a File in a new notebook page"));
|
|
|
|
#if wxUSE_UNOFFICIALSTUFF
|
2005-03-03 20:21:34 +00:00
|
|
|
menuFile->Append(wxID_OPENURLSAMEPAGE, _T("&Open URL"),
|
2005-02-04 19:04:58 +00:00
|
|
|
_T("Open a URL in the current notebook page"));
|
2005-03-03 20:21:34 +00:00
|
|
|
menuFile->Append(wxID_OPENURLNEWPAGE, _T("&Open URL in a new page"),
|
2005-02-04 19:04:58 +00:00
|
|
|
_T("Open a URL in a new notebook page"));
|
|
|
|
#endif
|
|
|
|
menuFile->AppendSeparator();
|
2005-03-03 20:21:34 +00:00
|
|
|
menuFile->Append(wxID_CLOSECURRENTPAGE, _T("&Close Current Page"),
|
2005-02-04 19:04:58 +00:00
|
|
|
_T("Close current notebook page"));
|
2004-11-11 05:40:58 +00:00
|
|
|
menuFile->AppendSeparator();
|
2004-11-14 23:26:55 +00:00
|
|
|
menuFile->Append(wxID_PLAY, _T("&Play"), _T("Resume playback"));
|
|
|
|
menuFile->Append(wxID_PAUSE, _T("P&ause"), _T("Pause playback"));
|
|
|
|
menuFile->Append(wxID_STOP, _T("&Stop"), _T("Stop playback"));
|
2004-11-11 05:40:58 +00:00
|
|
|
menuFile->AppendSeparator();
|
2004-11-16 13:49:27 +00:00
|
|
|
menuFile->AppendCheckItem(wxID_LOOP,
|
|
|
|
_T("&Loop"),
|
2004-11-14 23:26:55 +00:00
|
|
|
_T("Loop Selected Media"));
|
2004-11-11 05:40:58 +00:00
|
|
|
menuFile->AppendSeparator();
|
2004-11-16 13:49:27 +00:00
|
|
|
menuFile->Append(wxID_EXIT,
|
|
|
|
_T("E&xit\tAlt-X"),
|
2004-11-14 23:26:55 +00:00
|
|
|
_T("Quit this program"));
|
2004-11-11 05:40:58 +00:00
|
|
|
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
|
|
|
menuBar->Append(menuFile, _T("&File"));
|
|
|
|
menuBar->Append(helpMenu, _T("&Help"));
|
|
|
|
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
//
|
2005-03-03 20:21:34 +00:00
|
|
|
// Create our notebook - using wxNotebook is luckily pretty
|
2005-02-04 19:04:58 +00:00
|
|
|
// simple and self-explanatory in most cases
|
|
|
|
//
|
2005-02-04 07:49:40 +00:00
|
|
|
m_notebook = new wxNotebook(this, wxID_NOTEBOOK);
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
|
|
|
// Create our status bar
|
|
|
|
//
|
2004-11-11 05:40:58 +00: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 13:49:27 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
//
|
|
|
|
// Connect events.
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00: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
|
|
|
|
// class you want to use for events, such as MyFrame.
|
|
|
|
//
|
|
|
|
// Then after your class declaration you put
|
|
|
|
// BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
// EVT_XXX(XXX)...
|
|
|
|
// END_EVENT_TABLE()
|
|
|
|
//
|
|
|
|
// Where MyFrame is the class with the DECLARE_MESSAGE_MAP
|
2004-11-16 13:49:27 +00:00
|
|
|
// in it. EVT_XXX(XXX) are each of your handlers, such
|
2004-11-14 23:26:55 +00: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 13:49:27 +00:00
|
|
|
// type, then to a wxEventFunction, then to a
|
2004-11-14 23:26:55 +00:00
|
|
|
// wxObjectEventFunction - I.E.
|
|
|
|
// (wxObjectEventFunction)(wxEventFunction)
|
|
|
|
// (wxCommandEventFunction) &MyFrame::MyHandler
|
|
|
|
//
|
2005-03-18 11:50:18 +00:00
|
|
|
// Or, you can use the new (2.5.5+) event handler
|
|
|
|
// conversion macros - for instance the above could
|
|
|
|
// be done as
|
|
|
|
// wxCommandEventHandler(MyFrame::MyHandler)
|
|
|
|
// pretty simple, eh?
|
|
|
|
//
|
2004-11-16 13:49:27 +00:00
|
|
|
// The fourth is an optional userdata param -
|
2004-11-14 23:26:55 +00:00
|
|
|
// this is of historical relevance only and is
|
2005-02-16 19:25:35 +00:00
|
|
|
// there only for backwards compatibility.
|
2004-11-14 23:26:55 +00: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 13:49:27 +00:00
|
|
|
// if you were to call "this->MyFunc()"
|
2004-11-14 23:26:55 +00: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 09:56:45 +00:00
|
|
|
|
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Menu events
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-16 13:49:27 +00:00
|
|
|
this->Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnQuit));
|
2004-11-16 13:49:27 +00:00
|
|
|
|
|
|
|
this->Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnAbout));
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2004-11-16 13:49:27 +00:00
|
|
|
this->Connect(wxID_LOOP, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnLoop));
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
this->Connect(wxID_OPENFILENEWPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnOpenFileNewPage));
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
this->Connect(wxID_OPENFILESAMEPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnOpenFileSamePage));
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
this->Connect(wxID_OPENURLNEWPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnOpenURLNewPage));
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
this->Connect(wxID_OPENURLSAMEPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnOpenURLSamePage));
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
this->Connect(wxID_CLOSECURRENTPAGE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnCloseCurrentPage));
|
2004-11-11 09:56:45 +00:00
|
|
|
|
2004-11-16 13:49:27 +00:00
|
|
|
this->Connect(wxID_PLAY, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnPlay));
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2004-11-16 13:49:27 +00:00
|
|
|
this->Connect(wxID_PAUSE, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnPause));
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2004-11-16 13:49:27 +00:00
|
|
|
this->Connect(wxID_STOP, wxEVT_COMMAND_MENU_SELECTED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyFrame::OnStop));
|
2004-11-14 23:26:55 +00:00
|
|
|
|
|
|
|
//
|
2005-02-04 19:04:58 +00:00
|
|
|
// Notebook events
|
2004-11-14 23:26:55 +00:00
|
|
|
//
|
2005-02-04 07:49:40 +00:00
|
|
|
this->Connect(wxID_NOTEBOOK, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxNotebookEventHandler(MyFrame::OnPageChange));
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
//
|
|
|
|
// End of Events
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a timer to update our status bar
|
|
|
|
//
|
2004-11-11 09:56:45 +00:00
|
|
|
m_timer = new MyTimer(this);
|
|
|
|
m_timer->Start(100);
|
2004-11-11 05:40:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame Destructor
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-16 13:49:27 +00:00
|
|
|
// 1) Deletes child objects implicitly
|
2004-11-14 23:26:55 +00:00
|
|
|
// 2) Delete our timer explicitly
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
2004-11-11 09:56:45 +00:00
|
|
|
delete m_timer;
|
2004-11-11 05:40:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::ResetStatus
|
|
|
|
//
|
2004-11-16 13:49:27 +00:00
|
|
|
// Here we just make a simple status string with some useful info about
|
2004-11-14 23:26:55 +00:00
|
|
|
// the media that we won't change later - such as the length of the media.
|
|
|
|
//
|
|
|
|
// We then append some other info that changes in MyTimer::Notify, then
|
2004-11-16 13:49:27 +00:00
|
|
|
// set the status bar to this text.
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// In real applications, you'd want to find a better way to do this,
|
|
|
|
// such as static text controls (wxStaticText).
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
|
|
|
// We display info here in seconds (wxMediaCtrl uses milliseconds - that's why
|
2004-11-14 23:26:55 +00:00
|
|
|
// we divide by 1000).
|
|
|
|
//
|
|
|
|
// We also reset our loop counter here.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::ResetStatus()
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
wxMediaCtrl* currentMediaCtrl = GetCurrentMediaCtrl();
|
2005-02-04 07:49:40 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
m_basestatus = wxString::Format(_T("Size(x,y):%i,%i ")
|
|
|
|
_T("Length(Seconds):%u Speed:%1.1fx"),
|
2005-02-04 19:04:58 +00:00
|
|
|
currentMediaCtrl->GetBestSize().x,
|
|
|
|
currentMediaCtrl->GetBestSize().y,
|
|
|
|
(unsigned)((currentMediaCtrl->Length() / 1000)),
|
|
|
|
currentMediaCtrl->GetPlaybackRate()
|
2004-11-14 23:26:55 +00:00
|
|
|
);
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::GetCurrentMediaCtrl
|
|
|
|
//
|
|
|
|
// Obtains the media control of the current page, or NULL if there are no
|
|
|
|
// pages open
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
wxMediaCtrl* MyFrame::GetCurrentMediaCtrl()
|
|
|
|
{
|
|
|
|
wxASSERT(m_notebook->GetCurrentPage() != NULL);
|
|
|
|
return ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_mediactrl;
|
|
|
|
}
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::GetCurrentSlider
|
|
|
|
//
|
|
|
|
// Obtains the slider of the current page, or NULL if there are no
|
|
|
|
// pages open
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
wxSlider* MyFrame::GetCurrentSlider()
|
|
|
|
{
|
|
|
|
wxASSERT(m_notebook->GetCurrentPage() != NULL);
|
|
|
|
return ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_slider;
|
2004-11-14 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnQuit
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Called from file->quit.
|
|
|
|
// Closes this application.
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnAbout
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Called from help->about.
|
|
|
|
// Gets some info about this application.
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _T("This is a test of wxMediaCtrl.\n")
|
|
|
|
_T("Welcome to %s"), wxVERSION_STRING);
|
|
|
|
|
|
|
|
wxMessageBox(msg, _T("About wxMediaCtrl test"), wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnLoop
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Called from file->loop.
|
|
|
|
// Changes the state of whether we want to loop or not.
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
if(!m_notebook->GetCurrentPage())
|
|
|
|
{
|
|
|
|
wxMessageBox(wxT("No files are currently open!"));
|
|
|
|
return;
|
|
|
|
}
|
2005-02-12 02:32:29 +00:00
|
|
|
|
2005-03-03 20:21:34 +00:00
|
|
|
((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop =
|
2005-02-12 02:32:29 +00:00
|
|
|
!((MyNotebookPage*)m_notebook->GetCurrentPage())->m_bLoop;
|
2004-11-11 05:40:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-02-04 19:04:58 +00:00
|
|
|
// MyFrame::OnOpenFileSamePage
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Called from file->openfile.
|
2005-02-04 19:04:58 +00:00
|
|
|
// Opens and plays a media file in the current notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OnOpenFileSamePage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 20:21:34 +00:00
|
|
|
{
|
|
|
|
OpenFile(false);
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnOpenFileNewPage
|
|
|
|
//
|
|
|
|
// Called from file->openfileinnewpage.
|
|
|
|
// Opens and plays a media file in a new notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OnOpenFileNewPage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 20:21:34 +00:00
|
|
|
{
|
|
|
|
OpenFile(true);
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-02-04 19:04:58 +00:00
|
|
|
// MyFrame::OpenFile
|
|
|
|
//
|
|
|
|
// Code to actually open the media file
|
|
|
|
//
|
|
|
|
// 1) Create file dialog and ask the user for input file
|
|
|
|
// 2) If the user didn't want anything, break out
|
|
|
|
// 3) Create a new page if the user wanted one or there isn't a current page
|
|
|
|
// 4) Load the media
|
|
|
|
// 5) Play the media
|
|
|
|
// 6) Reset the text on the status bar
|
|
|
|
// 7) Set the slider of the current page to accurately reflect media length
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OpenFile(bool bNewPage)
|
2004-11-11 05:40:58 +00:00
|
|
|
{
|
|
|
|
wxFileDialog fd(this);
|
|
|
|
|
|
|
|
if(fd.ShowModal() == wxID_OK)
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
if(bNewPage || !m_notebook->GetCurrentPage())
|
|
|
|
m_notebook->AddPage(new MyNotebookPage(m_notebook), fd.GetPath(), true);
|
2005-03-18 11:50:18 +00:00
|
|
|
else //don't forget to update notebook page title
|
|
|
|
m_notebook->SetPageText(m_notebook->GetSelection(), fd.GetPath());
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
if( !GetCurrentMediaCtrl()->Load(fd.GetPath()) )
|
2004-11-11 05:40:58 +00:00
|
|
|
wxMessageBox(wxT("Couldn't load file!"));
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
if( !GetCurrentMediaCtrl()->Play() )
|
2004-11-12 14:23:02 +00:00
|
|
|
wxMessageBox(wxT("Couldn't play movie!"));
|
|
|
|
|
2004-11-11 05:40:58 +00:00
|
|
|
ResetStatus();
|
2005-03-03 20:21:34 +00:00
|
|
|
|
|
|
|
GetCurrentSlider()->SetRange(0,
|
2005-02-04 19:04:58 +00:00
|
|
|
(int)(GetCurrentMediaCtrl()->Length() / 1000));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnOpenURLSamePage
|
|
|
|
//
|
|
|
|
// Called from file->openurl.
|
|
|
|
// Opens and plays a media file from a URL in the current notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 20:21:34 +00:00
|
|
|
{
|
|
|
|
OpenURL(false);
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnOpenURLNewPage
|
|
|
|
//
|
|
|
|
// Called from file->openurlinnewpage.
|
|
|
|
// Opens and plays a media file from a URL in a new notebook page
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OnOpenURLNewPage(wxCommandEvent& WXUNUSED(event))
|
2005-03-03 20:21:34 +00:00
|
|
|
{
|
|
|
|
OpenURL(true);
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OpenURL
|
|
|
|
//
|
|
|
|
// Code to actually open the media file from a URL
|
|
|
|
//
|
|
|
|
// 1) Create text input dialog and ask the user for an input URL
|
|
|
|
// 2) If the user didn't want anything, break out
|
|
|
|
// 3) Create a new page if the user wanted one or there isn't a current page
|
|
|
|
// 4) Load the media
|
|
|
|
// 5) Play the media
|
|
|
|
// 6) Reset the text on the status bar
|
|
|
|
// 7) Set the slider of the current page to accurately reflect media length
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OpenURL(bool bNewPage)
|
|
|
|
{
|
|
|
|
wxString theURL = wxGetTextFromUser(wxT("Enter the URL that has the movie to play"));
|
|
|
|
|
|
|
|
if(!theURL.empty())
|
|
|
|
{
|
|
|
|
if(bNewPage || !m_notebook->GetCurrentPage())
|
|
|
|
m_notebook->AddPage(new MyNotebookPage(m_notebook), theURL, true);
|
2005-03-18 11:50:18 +00:00
|
|
|
else //don't forget to update notebook page title
|
|
|
|
m_notebook->SetPageText(m_notebook->GetSelection(), theURL);
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
if( !GetCurrentMediaCtrl()->Load(wxURI(theURL)) )
|
|
|
|
wxMessageBox(wxT("Couldn't load URL!"));
|
|
|
|
|
|
|
|
if( !GetCurrentMediaCtrl()->Play() )
|
|
|
|
wxMessageBox(wxT("Couldn't play movie!"));
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
ResetStatus();
|
|
|
|
|
2005-03-03 20:21:34 +00:00
|
|
|
GetCurrentSlider()->SetRange(0,
|
2005-02-04 19:04:58 +00:00
|
|
|
(int)(GetCurrentMediaCtrl()->Length() / 1000));
|
2004-11-11 05:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnCloseCurrentPage
|
|
|
|
//
|
|
|
|
// Called when the user wants to close the current notebook page
|
|
|
|
//
|
|
|
|
// 1) Get the current page number (wxControl::GetSelection)
|
|
|
|
// 2) If there is no current page, break out
|
|
|
|
// 3) Delete the current page
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyFrame::OnCloseCurrentPage(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
int sel = m_notebook->GetSelection();
|
|
|
|
|
|
|
|
if (sel != wxNOT_FOUND)
|
|
|
|
{
|
|
|
|
m_notebook->DeletePage(sel);
|
2005-03-03 20:21:34 +00:00
|
|
|
}
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnPlay
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Called from file->play.
|
|
|
|
// Resumes the media if it is paused or stopped.
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
if(!m_notebook->GetCurrentPage())
|
|
|
|
{
|
|
|
|
wxMessageBox(wxT("No files are currently open!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !GetCurrentMediaCtrl()->Play() )
|
2004-11-11 05:40:58 +00:00
|
|
|
wxMessageBox(wxT("Couldn't play movie!"));
|
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnPause
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// Called from file->pause.
|
|
|
|
// Pauses the media in-place.
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
void MyFrame::OnPause(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
if(!m_notebook->GetCurrentPage())
|
|
|
|
{
|
|
|
|
wxMessageBox(wxT("No files are currently open!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !GetCurrentMediaCtrl()->Pause() )
|
2004-11-11 05:40:58 +00:00
|
|
|
wxMessageBox(wxT("Couldn't pause movie!"));
|
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame::OnStop
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00: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
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-11 05:40:58 +00:00
|
|
|
void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
if(!m_notebook->GetCurrentPage())
|
|
|
|
{
|
|
|
|
wxMessageBox(wxT("No files are currently open!"));
|
|
|
|
return;
|
|
|
|
}
|
2004-11-11 05:40:58 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
if( !GetCurrentMediaCtrl()->Stop() )
|
|
|
|
wxMessageBox(wxT("Couldn't stop movie!"));
|
2004-11-11 05:40:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-02-04 19:04:58 +00:00
|
|
|
// MyFrame::OnCloseCurrentPage
|
2004-11-16 13:49:27 +00:00
|
|
|
//
|
2005-02-04 19:04:58 +00:00
|
|
|
// Called when the user wants to closes the current notebook page
|
2004-11-14 23:26:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-02-04 07:49:40 +00:00
|
|
|
|
|
|
|
void MyFrame::OnPageChange(wxNotebookEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
ResetStatus();
|
|
|
|
}
|
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// MyTimer
|
2004-11-11 09:56:45 +00:00
|
|
|
//
|
2004-11-14 23:26:55 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyTimer::Notify
|
|
|
|
//
|
|
|
|
// 1) Update our slider with the position were are in in the media
|
|
|
|
// 2) Update our status bar with the base text from MyFrame::ResetStatus,
|
2004-11-16 13:49:27 +00:00
|
|
|
// append some non-static (changing) info to it, then set the
|
2004-11-14 23:26:55 +00:00
|
|
|
// status bar text to that result
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyTimer::Notify()
|
2004-11-11 05:40:58 +00:00
|
|
|
{
|
2005-02-04 19:04:58 +00:00
|
|
|
if (!m_frame->m_notebook->GetCurrentPage()) return;
|
2005-03-03 20:21:34 +00:00
|
|
|
wxMediaCtrl* m_mediactrl = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_mediactrl;
|
|
|
|
wxSlider* m_slider = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_slider;
|
2005-02-04 07:49:40 +00:00
|
|
|
if (!m_mediactrl) return;
|
|
|
|
|
|
|
|
long lPosition = (long)( m_mediactrl->Tell() / 1000 );
|
|
|
|
m_slider->SetValue(lPosition);
|
2004-11-14 23:26:55 +00:00
|
|
|
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
m_frame->SetStatusText(wxString::Format(
|
2005-02-04 19:04:58 +00:00
|
|
|
_T("%s Pos:%u State:%s Loops:%i"),
|
2004-11-14 23:26:55 +00:00
|
|
|
m_frame->m_basestatus.c_str(),
|
|
|
|
(unsigned int)lPosition,
|
2005-02-04 19:04:58 +00:00
|
|
|
wxGetMediaStateText(m_mediactrl->GetState()),
|
|
|
|
((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_nLoops
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
#endif
|
2005-02-04 07:49:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
//
|
|
|
|
// MyNotebookPage
|
|
|
|
//
|
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyNotebookPage Constructor
|
|
|
|
//
|
|
|
|
// Creates a media control and slider and adds it to this panel,
|
|
|
|
// along with some sizers for positioning
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-02-04 07:49:40 +00:00
|
|
|
MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
|
2005-02-12 02:32:29 +00:00
|
|
|
wxPanel(theBook, wxID_ANY), m_nLoops(0), m_bLoop(false)
|
2005-02-04 07:49:40 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Create and attach the first/main sizer
|
|
|
|
//
|
|
|
|
wxBoxSizer* vertsizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
this->SetSizer(vertsizer);
|
|
|
|
this->SetAutoLayout(true);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create our media control
|
|
|
|
//
|
2005-02-12 19:32:26 +00:00
|
|
|
m_mediactrl = new wxMediaCtrl();
|
2005-03-03 20:21:34 +00:00
|
|
|
|
2005-02-12 19:32:26 +00:00
|
|
|
// Make sure creation was successful
|
|
|
|
bool bOK = m_mediactrl->Create(this, wxID_MEDIACTRL);
|
|
|
|
wxASSERT_MSG(bOK, wxT("Could not create media control!"));
|
2005-03-03 20:21:34 +00:00
|
|
|
wxUnusedVar(bOK);
|
|
|
|
|
2005-02-04 07:49:40 +00:00
|
|
|
vertsizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create our slider
|
|
|
|
//
|
|
|
|
m_slider = new wxSlider(this, wxID_SLIDER, 0, //init
|
|
|
|
0, //start
|
|
|
|
0, //end
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxSL_HORIZONTAL );
|
|
|
|
vertsizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create the second sizer which will position things
|
|
|
|
// vertically -
|
|
|
|
//
|
|
|
|
// -------Menu----------
|
|
|
|
// [m_mediactrl]
|
|
|
|
//
|
|
|
|
// [m_slider]
|
|
|
|
//
|
|
|
|
wxBoxSizer* horzsizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
vertsizer->Add(horzsizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
|
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
//
|
|
|
|
// Slider events
|
|
|
|
//
|
|
|
|
this->Connect(wxID_SLIDER, wxEVT_COMMAND_SLIDER_UPDATED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxCommandEventHandler(MyNotebookPage::OnSeek));
|
2005-02-04 19:04:58 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Media Control events
|
|
|
|
//
|
2005-02-12 02:32:29 +00:00
|
|
|
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED,
|
2005-03-18 11:50:18 +00:00
|
|
|
wxMediaEventHandler(MyNotebookPage::OnMediaFinished));
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyNotebook::OnSeek
|
|
|
|
//
|
|
|
|
// Called from file->seek.
|
|
|
|
// Called when the user moves the slider -
|
|
|
|
// seeks to a position within the media
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void MyNotebookPage::OnSeek(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-03-03 20:21:34 +00:00
|
|
|
if( m_mediactrl->Seek(
|
|
|
|
m_slider->GetValue() * 1000
|
2005-02-04 19:04:58 +00:00
|
|
|
) == wxInvalidOffset )
|
|
|
|
wxMessageBox(wxT("Couldn't seek in movie!"));
|
2004-11-12 14:23:02 +00:00
|
|
|
}
|
2004-11-14 23:26:55 +00:00
|
|
|
|
2005-02-04 19:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-02-12 02:32:29 +00:00
|
|
|
// OnMediaFinished
|
2005-02-04 19:04:58 +00:00
|
|
|
//
|
2005-02-12 02:32:29 +00:00
|
|
|
// Called when the media stops playing.
|
|
|
|
// Here we loop it if the user wants to (has been selected from file menu)
|
2005-02-04 19:04:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-02-12 02:32:29 +00:00
|
|
|
void MyNotebookPage::OnMediaFinished(wxMediaEvent& WXUNUSED(event))
|
2005-02-04 19:04:58 +00:00
|
|
|
{
|
2005-02-12 02:32:29 +00:00
|
|
|
if(m_bLoop)
|
|
|
|
{
|
|
|
|
if ( !m_mediactrl->Play() )
|
|
|
|
wxMessageBox(wxT("Couldn't loop movie!"));
|
|
|
|
else
|
|
|
|
++m_nLoops;
|
|
|
|
}
|
2005-02-04 19:04:58 +00:00
|
|
|
}
|
2005-02-04 07:49:40 +00:00
|
|
|
|
2004-11-14 23:26:55 +00:00
|
|
|
//
|
|
|
|
// End of MediaPlayer sample
|
|
|
|
//
|