make cocoa mediactrl usable. Some touchups to carbon mediactrl code. Add notebook support to mediaplayer sample.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31744 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
2005-02-04 07:49:40 +00:00
parent 4f9cd1cb7f
commit ecd20d4a91
4 changed files with 154 additions and 185 deletions

View File

@@ -191,7 +191,7 @@ protected:
wxSize DoGetBestSize() const; wxSize DoGetBestSize() const;
#ifdef __WXMAC__ #ifdef __WXMAC__
friend class wxMediaBackend; friend class wxQTMediaBackend;
#endif #endif
#ifdef __WXCOCOA__ #ifdef __WXCOCOA__
friend class wxQTMediaBackend; friend class wxQTMediaBackend;
@@ -262,11 +262,6 @@ public:
virtual wxMediaState GetState() virtual wxMediaState GetState()
{ return wxMEDIASTATE_STOPPED; } { return wxMEDIASTATE_STOPPED; }
#ifdef __WXMAC__
wxMacControl* GetControlPeer(wxControl* ctrl)
{ return ((wxMediaCtrl*)ctrl)->m_peer; }
#endif
DECLARE_CLASS(wxMediaBackend) DECLARE_CLASS(wxMediaBackend)
}; };

View File

@@ -51,6 +51,7 @@
#include "wx/sizer.h" //for positioning controls/wxBoxSizer #include "wx/sizer.h" //for positioning controls/wxBoxSizer
#include "wx/timer.h" //timer for updating status bar #include "wx/timer.h" //timer for updating status bar
#include "wx/textdlg.h" //for getting user text from OpenURL #include "wx/textdlg.h" //for getting user text from OpenURL
#include "wx/notebook.h" //for wxNotebook and putting movies in pages
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Bail out if the user doesn't want one of the // Bail out if the user doesn't want one of the
@@ -61,10 +62,15 @@
#error "This is a GUI sample" #error "This is a GUI sample"
#endif #endif
#if !wxUSE_MEDIACTRL || !wxUSE_MENUS || !wxUSE_SLIDER || !wxUSE_TIMER #if !wxUSE_MEDIACTRL || !wxUSE_MENUS || !wxUSE_SLIDER || !wxUSE_TIMER || !wxUSE_NOTEBOOK
#error "menus, slider, mediactrl, and timers must all enabled for this sample!" #error "menus, slider, mediactrl, notebook, and timers must all be enabled for this sample!"
#endif #endif
#define MEDIASTUFF \
if (!m_notebook || !m_notebook->GetCurrentPage()) return; \
wxMediaCtrl* m_mediactrl = ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_mediactrl; \
wxSlider* m_slider = ((MyNotebookPage*)m_notebook->GetCurrentPage())->m_slider;
// ============================================================================ // ============================================================================
// Declarations // Declarations
// ============================================================================ // ============================================================================
@@ -81,6 +87,7 @@ enum
wxID_OPENFILE, wxID_OPENFILE,
wxID_PLAY, wxID_PLAY,
wxID_PAUSE, wxID_PAUSE,
// wxID_CLOSE, [built-in to wxWidgets]
// wxID_STOP, [built-in to wxWidgets] // wxID_STOP, [built-in to wxWidgets]
// wxID_ABOUT, [built-in to wxWidgets] // wxID_ABOUT, [built-in to wxWidgets]
// wxID_EXIT, [built-in to wxWidgets] // wxID_EXIT, [built-in to wxWidgets]
@@ -88,6 +95,7 @@ enum
// id for our slider // id for our slider
wxID_SLIDER, wxID_SLIDER,
wxID_NOTEBOOK,
// id for our wxMediaCtrl // id for our wxMediaCtrl
wxID_MEDIACTRL wxID_MEDIACTRL
}; };
@@ -124,27 +132,40 @@ public:
void OnPlay(wxCommandEvent& event); void OnPlay(wxCommandEvent& event);
void OnPause(wxCommandEvent& event); void OnPause(wxCommandEvent& event);
void OnStop(wxCommandEvent& event); void OnStop(wxCommandEvent& event);
void OnClose(wxCommandEvent& event);
// Slider event handlers // Slider event handlers
void OnSeek(wxCommandEvent& event); void OnSeek(wxCommandEvent& event);
// Media event handlers // Media event handlers
void OnMediaStop(wxMediaEvent& event); void OnMediaStop(wxMediaEvent& event);
void OnPageChange(wxNotebookEvent& event);
void OnClosePage(wxCommandEvent& event);
private: private:
// Rebuild base status string (see Implementation) // Rebuild base status string (see Implementation)
void ResetStatus(); void ResetStatus();
wxMediaCtrl* m_mediactrl; //Our media control
wxSlider* m_slider; //The slider below our media control
class MyTimer* m_timer; //Timer to write info to status bar class MyTimer* m_timer; //Timer to write info to status bar
wxString m_basestatus; //Base status string (see ResetStatus()) wxString m_basestatus; //Base status string (see ResetStatus())
int m_nLoops; //Counter, incremented each time media loops wxNotebook* m_notebook;
// So that mytimer can access MyFrame's members // So that mytimer can access MyFrame's members
friend class MyTimer; friend class MyTimer;
}; };
class MyNotebookPage : public wxPanel
{
MyNotebookPage(wxNotebook* boook);
public:
friend class MyFrame;
wxMediaCtrl* m_mediactrl; //Our media control
wxSlider* m_slider; //The slider below our media control
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// MyTimer // MyTimer
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -264,6 +285,8 @@ MyFrame::MyFrame(const wxString& title)
menuFile->Append(wxID_PAUSE, _T("P&ause"), _T("Pause playback")); menuFile->Append(wxID_PAUSE, _T("P&ause"), _T("Pause playback"));
menuFile->Append(wxID_STOP, _T("&Stop"), _T("Stop playback")); menuFile->Append(wxID_STOP, _T("&Stop"), _T("Stop playback"));
menuFile->AppendSeparator(); menuFile->AppendSeparator();
menuFile->Append(wxID_CLOSE, _T("&Close"), _T("Close current notebook page"));
menuFile->AppendSeparator();
menuFile->AppendCheckItem(wxID_LOOP, menuFile->AppendCheckItem(wxID_LOOP,
_T("&Loop"), _T("&Loop"),
_T("Loop Selected Media")); _T("Loop Selected Media"));
@@ -278,41 +301,7 @@ MyFrame::MyFrame(const wxString& title)
SetMenuBar(menuBar); SetMenuBar(menuBar);
// m_notebook = new wxNotebook(this, wxID_NOTEBOOK);
// Create and attach the first/main sizer
//
wxBoxSizer* vertsizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(vertsizer);
this->SetAutoLayout(true);
//
// Create our media control
//
m_mediactrl = new wxMediaCtrl(this, wxID_MEDIACTRL);
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);
// //
// Create our status bar // Create our status bar
@@ -418,6 +407,9 @@ MyFrame::MyFrame(const wxString& title)
(wxObjectEventFunction) (wxEventFunction) (wxObjectEventFunction) (wxEventFunction)
(wxCommandEventFunction) &MyFrame::OnStop); (wxCommandEventFunction) &MyFrame::OnStop);
this->Connect(wxID_CLOSE, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) (wxEventFunction)
(wxCommandEventFunction) &MyFrame::OnClosePage);
// //
// Slider events // Slider events
@@ -433,15 +425,14 @@ MyFrame::MyFrame(const wxString& title)
(wxObjectEventFunction) (wxEventFunction) (wxObjectEventFunction) (wxEventFunction)
(wxMediaEventFunction) &MyFrame::OnMediaStop); (wxMediaEventFunction) &MyFrame::OnMediaStop);
this->Connect(wxID_NOTEBOOK, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
(wxObjectEventFunction) (wxEventFunction)
(wxNotebookEventFunction) &MyFrame::OnPageChange);
// //
// End of Events // End of Events
// //
//
// Set our loop counter to 0
//
m_nLoops = 0;
// //
// Create a timer to update our status bar // Create a timer to update our status bar
// //
@@ -479,6 +470,9 @@ MyFrame::~MyFrame()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::ResetStatus() void MyFrame::ResetStatus()
{ {
MEDIASTUFF
m_basestatus = wxString::Format(_T("Size(x,y):%i,%i ") m_basestatus = wxString::Format(_T("Size(x,y):%i,%i ")
_T("Length(Seconds):%u Speed:%1.1fx"), _T("Length(Seconds):%u Speed:%1.1fx"),
m_mediactrl->GetBestSize().x, m_mediactrl->GetBestSize().x,
@@ -489,7 +483,6 @@ void MyFrame::ResetStatus()
m_slider->SetRange(0, (int)(m_mediactrl->Length() / 1000)); m_slider->SetRange(0, (int)(m_mediactrl->Length() / 1000));
m_nLoops = 0;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -527,6 +520,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
{ {
MEDIASTUFF
m_mediactrl->Loop( !m_mediactrl->IsLooped() ); m_mediactrl->Loop( !m_mediactrl->IsLooped() );
} }
@@ -542,6 +536,10 @@ void MyFrame::OnOpenFile(wxCommandEvent& WXUNUSED(event))
if(fd.ShowModal() == wxID_OK) if(fd.ShowModal() == wxID_OK)
{ {
m_notebook->AddPage(new MyNotebookPage(m_notebook), fd.GetPath(), true);
MEDIASTUFF
if( !m_mediactrl->Load(fd.GetPath()) ) if( !m_mediactrl->Load(fd.GetPath()) )
wxMessageBox(wxT("Couldn't load file!")); wxMessageBox(wxT("Couldn't load file!"));
@@ -560,6 +558,7 @@ void MyFrame::OnOpenFile(wxCommandEvent& WXUNUSED(event))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{ {
MEDIASTUFF
if( !m_mediactrl->Play() ) if( !m_mediactrl->Play() )
wxMessageBox(wxT("Couldn't play movie!")); wxMessageBox(wxT("Couldn't play movie!"));
} }
@@ -572,6 +571,7 @@ void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::OnPause(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPause(wxCommandEvent& WXUNUSED(event))
{ {
MEDIASTUFF
if( !m_mediactrl->Pause() ) if( !m_mediactrl->Pause() )
wxMessageBox(wxT("Couldn't pause movie!")); wxMessageBox(wxT("Couldn't pause movie!"));
} }
@@ -587,6 +587,7 @@ void MyFrame::OnPause(wxCommandEvent& WXUNUSED(event))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
{ {
MEDIASTUFF
if( !m_mediactrl->Stop() ) if( !m_mediactrl->Stop() )
wxMessageBox(wxT("Couldn't stop movie!")); wxMessageBox(wxT("Couldn't stop movie!"));
} }
@@ -600,6 +601,7 @@ void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::OnSeek(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSeek(wxCommandEvent& WXUNUSED(event))
{ {
MEDIASTUFF
if( m_mediactrl->Seek( m_slider->GetValue() * 1000 ) == wxInvalidOffset ) if( m_mediactrl->Seek( m_slider->GetValue() * 1000 ) == wxInvalidOffset )
wxMessageBox(wxT("Couldn't seek in movie!")); wxMessageBox(wxT("Couldn't seek in movie!"));
} }
@@ -608,11 +610,24 @@ void MyFrame::OnSeek(wxCommandEvent& WXUNUSED(event))
// MyFrame::OnMediaStop // MyFrame::OnMediaStop
// //
// Called when the media is about to stop playing. // Called when the media is about to stop playing.
// Here we just increase our loop counter
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyFrame::OnMediaStop(wxMediaEvent& WXUNUSED(event)) void MyFrame::OnMediaStop(wxMediaEvent& WXUNUSED(event))
{ {
++m_nLoops; }
void MyFrame::OnPageChange(wxNotebookEvent& WXUNUSED(event))
{
ResetStatus();
}
void MyFrame::OnClosePage(wxCommandEvent& WXUNUSED(event))
{
int sel = m_notebook->GetSelection();
if (sel != wxNOT_FOUND)
{
m_notebook->DeletePage(sel);
}
} }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -631,21 +646,72 @@ void MyFrame::OnMediaStop(wxMediaEvent& WXUNUSED(event))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyTimer::Notify() void MyTimer::Notify()
{ {
long lPosition = (long)( m_frame->m_mediactrl->Tell() / 1000 );
m_frame->m_slider->SetValue(lPosition); if (!m_frame->m_notebook || !m_frame->m_notebook->GetCurrentPage()) return;
wxMediaCtrl* m_mediactrl = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_mediactrl;
wxSlider* m_slider = ((MyNotebookPage*)m_frame->m_notebook->GetCurrentPage())->m_slider;
if (!m_mediactrl) return;
long lPosition = (long)( m_mediactrl->Tell() / 1000 );
m_slider->SetValue(lPosition);
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
m_frame->SetStatusText(wxString::Format( m_frame->SetStatusText(wxString::Format(
_T("%s Pos:%u State:%s Loops:%i"), _T("%s Pos:%u State:%s"),
m_frame->m_basestatus.c_str(), m_frame->m_basestatus.c_str(),
(unsigned int)lPosition, (unsigned int)lPosition,
wxGetMediaStateText(m_frame->m_mediactrl->GetState()), wxGetMediaStateText(m_mediactrl->GetState())
m_frame->m_nLoops
) )
); );
#endif #endif
} }
MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
wxPanel(theBook, wxID_ANY)
{
//
// Create and attach the first/main sizer
//
wxBoxSizer* vertsizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(vertsizer);
this->SetAutoLayout(true);
//
// Create our media control
//
m_mediactrl = new wxMediaCtrl(this, wxID_MEDIACTRL);
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);
}
// //
// End of MediaPlayer sample // End of MediaPlayer sample
// //

View File

@@ -51,7 +51,6 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// QT Includes // QT Includes
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "wx/timer.h"
#include <QuickTime/QuickTime.h> #include <QuickTime/QuickTime.h>
#include "wx/cocoa/autorelease.h" #include "wx/cocoa/autorelease.h"
@@ -103,7 +102,6 @@ public:
NSMovieView* m_movieview; //NSMovieView instance NSMovieView* m_movieview; //NSMovieView instance
wxControl* m_ctrl; //Parent control wxControl* m_ctrl; //Parent control
bool m_bVideo; //Whether or not we have video bool m_bVideo; //Whether or not we have video
class _wxQTTimer* m_timer; //Timer for streaming the movie
DECLARE_DYNAMIC_CLASS(wxQTMediaBackend); DECLARE_DYNAMIC_CLASS(wxQTMediaBackend);
}; };
@@ -117,74 +115,12 @@ public:
IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend); IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend);
//Time between timer calls
#define MOVIE_DELAY 100
// --------------------------------------------------------------------------
// wxQTTimer - Handle Asyncronous Playing
// --------------------------------------------------------------------------
class _wxQTTimer : public wxTimer
{
public:
_wxQTTimer(Movie movie, wxQTMediaBackend* parent) :
m_movie(movie), m_bPaused(false), m_parent(parent)
{
}
~_wxQTTimer()
{
}
bool GetPaused() {return m_bPaused;}
void SetPaused(bool bPaused) {m_bPaused = bPaused;}
//-----------------------------------------------------------------------
// _wxQTTimer::Notify
//
// 1) Checks to see if the movie is done, and if not continues
// streaming the movie
// 2) Sends the wxEVT_MEDIA_STOP event if we have reached the end of
// the movie.
//-----------------------------------------------------------------------
void Notify()
{
if (!m_bPaused)
{
if(!IsMovieDone(m_movie))
MoviesTask(m_movie, MOVIE_DELAY);
else
{
wxMediaEvent theEvent(wxEVT_MEDIA_STOP,
m_parent->m_ctrl->GetId());
m_parent->m_ctrl->ProcessEvent(theEvent);
if(theEvent.IsAllowed())
{
Stop();
m_parent->Stop();
wxASSERT(::GetMoviesError() == noErr);
//send the event to our child
wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
m_parent->m_ctrl->GetId());
m_parent->m_ctrl->ProcessEvent(theEvent);
}
}
}
}
protected:
Movie m_movie; //Our movie instance
bool m_bPaused; //Whether we are paused or not
wxQTMediaBackend* m_parent; //Backend pointer
};
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend Constructor // wxQTMediaBackend Constructor
// //
// Sets m_timer to NULL signifying we havn't loaded anything yet // Sets m_timer to NULL signifying we havn't loaded anything yet
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxQTMediaBackend::wxQTMediaBackend() : m_timer(NULL) wxQTMediaBackend::wxQTMediaBackend()
{ {
} }
@@ -199,11 +135,10 @@ wxQTMediaBackend::wxQTMediaBackend() : m_timer(NULL)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxQTMediaBackend::~wxQTMediaBackend() wxQTMediaBackend::~wxQTMediaBackend()
{ {
if(m_timer) Cleanup();
Cleanup();
//Note that ExitMovies() is not neccessary... //Note that ExitMovies() is not neccessary...
ExitMovies(); ::ExitMovies();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -225,11 +160,11 @@ bool wxQTMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent,
wxMediaCtrl* ctrl = (wxMediaCtrl*) inctrl; wxMediaCtrl* ctrl = (wxMediaCtrl*) inctrl;
//Create the control base //Create the control base
wxASSERT(ctrl->CreateBase(parent,wid,pos,size,style, validator, size)); wxASSERT(ctrl->CreateBase(parent,wid,pos,size,style, validator, name));
//Create the NSMovieView //Create the NSMovieView
ctrl->SetNSView(NULL); ctrl->SetNSView(NULL);
NSView* theView = [[NSMovieView alloc] initWithFrame: ctrl->MakeDefaultNSRect(size)]; NSMovieView* theView = [[NSMovieView alloc] initWithFrame: ctrl->MakeDefaultNSRect(size)];
ctrl->SetNSView(theView); ctrl->SetNSView(theView);
[theView release]; [theView release];
@@ -240,6 +175,7 @@ bool wxQTMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent,
ctrl->SetInitialFrameRect(pos,size); ctrl->SetInitialFrameRect(pos,size);
} }
[theView showController:false adjustingSize:true];
m_movieview = theView; m_movieview = theView;
m_ctrl = ctrl; m_ctrl = ctrl;
return true; return true;
@@ -267,8 +203,7 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Load(const wxURI& location) bool wxQTMediaBackend::Load(const wxURI& location)
{ {
if(m_timer) Cleanup();
Cleanup();
wxString theURI = location.BuildURI(); wxString theURI = location.BuildURI();
@@ -277,16 +212,6 @@ bool wxQTMediaBackend::Load(const wxURI& location)
m_movie = (Movie) [[m_movieview movie] QTMovie]; m_movie = (Movie) [[m_movieview movie] QTMovie];
//preroll movie for streaming
//TODO:Async this using threads?
TimeValue timeNow;
Fixed playRate;
timeNow = GetMovieTime(m_movie, NULL);
playRate = GetMoviePreferredRate(m_movie);
PrePrerollMovie(m_movie, timeNow, playRate, NULL, NULL);
PrerollMovie(m_movie, timeNow, playRate);
SetMovieRate(m_movie, playRate);
FinishLoad(); FinishLoad();
return ::GetMoviesError() == noErr; return ::GetMoviesError() == noErr;
@@ -294,20 +219,9 @@ bool wxQTMediaBackend::Load(const wxURI& location)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::FinishLoad // wxQTMediaBackend::FinishLoad
//
// 1) Create the movie timer
// 2) Get real size of movie for GetBestSize/sizers
// 3) See if there is video in the movie, and if so then either
// SetMovieGWorld if < 10.2 or use Native CreateMovieControl
// 4) Set the movie time scale to something usable so that seeking
// etc. will work correctly
// 5) Refresh parent window
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::FinishLoad() void wxQTMediaBackend::FinishLoad()
{ {
m_timer = new _wxQTTimer(m_movie, (wxQTMediaBackend*) this);
wxASSERT(m_timer);
//get the real size of the movie //get the real size of the movie
Rect outRect; Rect outRect;
::GetMovieNaturalBoundsRect (m_movie, &outRect); ::GetMovieNaturalBoundsRect (m_movie, &outRect);
@@ -339,9 +253,7 @@ void wxQTMediaBackend::FinishLoad()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Play() bool wxQTMediaBackend::Play()
{ {
::StartMovie(m_movie); [m_movieview start:NULL];
m_timer->SetPaused(false);
m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
return ::GetMoviesError() == noErr; return ::GetMoviesError() == noErr;
} }
@@ -353,9 +265,7 @@ bool wxQTMediaBackend::Play()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Pause() bool wxQTMediaBackend::Pause()
{ {
::StopMovie(m_movie); [m_movieview stop:NULL];
m_timer->SetPaused(true);
m_timer->Stop();
return ::GetMoviesError() == noErr; return ::GetMoviesError() == noErr;
} }
@@ -368,14 +278,8 @@ bool wxQTMediaBackend::Pause()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Stop() bool wxQTMediaBackend::Stop()
{ {
m_timer->SetPaused(false); [m_movieview stop:NULL];
m_timer->Stop(); [m_movieview gotoBeginning:NULL];
::StopMovie(m_movie);
if(::GetMoviesError() != noErr)
return false;
::GoToBeginningOfMovie(m_movie);
return ::GetMoviesError() == noErr; return ::GetMoviesError() == noErr;
} }
@@ -449,12 +353,11 @@ wxLongLong wxQTMediaBackend::GetDuration()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxMediaState wxQTMediaBackend::GetState() wxMediaState wxQTMediaBackend::GetState()
{ {
if ( !m_timer || (m_timer->IsRunning() == false && if ( [m_movieview isPlaying] )
m_timer->GetPaused() == false) )
return wxMEDIASTATE_STOPPED;
if( m_timer->IsRunning() == true )
return wxMEDIASTATE_PLAYING; return wxMEDIASTATE_PLAYING;
if( wxQTMediaBackend::GetPosition() == 0 )
return wxMEDIASTATE_STOPPED;
else else
return wxMEDIASTATE_PAUSED; return wxMEDIASTATE_PAUSED;
} }
@@ -467,11 +370,11 @@ wxMediaState wxQTMediaBackend::GetState()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::Cleanup() void wxQTMediaBackend::Cleanup()
{ {
delete m_timer; if([m_movieview movie])
m_timer = NULL; {
[[m_movieview movie] release];
[[m_movieview movie] release]; [m_movieview setMovie:NULL];
[m_movieview setMovie:NULL]; }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -257,17 +257,21 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
if ( ! if ( !
#if wxUSE_CREATEMOVIECONTROL #if wxUSE_CREATEMOVIECONTROL
ctrl->wxControl::Create(parent, id, pos, size,
m_ctrl->MacRemoveBordersFromStyle(style),
validator, name)
#else
ctrl->wxWindow::Create(parent, id, pos, size, ctrl->wxWindow::Create(parent, id, pos, size,
m_ctrl->MacRemoveBordersFromStyle(style), m_ctrl->MacRemoveBordersFromStyle(style),
name) name)
#else
ctrl->wxControl::Create(parent, id, pos, size,
m_ctrl->MacRemoveBordersFromStyle(style),
validator, name)
#endif #endif
) )
return false; return false;
#if wxUSE_VALIDATORS
ctrl->SetValidator(validator);
#endif
m_ctrl = ctrl; m_ctrl = ctrl;
return true; return true;
} }
@@ -401,6 +405,8 @@ void wxQTMediaBackend::FinishLoad()
//Native CreateMovieControl QT control (Thanks to Kevin Olliver's //Native CreateMovieControl QT control (Thanks to Kevin Olliver's
//wxQTMovie for some of this). //wxQTMovie for some of this).
// //
#define GetControlPeer(whatever) ctrl->m_peer
wxMediaCtrl* ctrl = (wxMediaCtrl*) m_ctrl;
Rect bounds = wxMacGetBoundsForControl(m_ctrl, Rect bounds = wxMacGetBoundsForControl(m_ctrl,
m_ctrl->GetPosition(), m_ctrl->GetPosition(),
m_ctrl->GetSize()); m_ctrl->GetSize());
@@ -419,7 +425,7 @@ void wxQTMediaBackend::FinishLoad()
//ManuallyIdled - app handles movie idling rather than internal timer event loop //ManuallyIdled - app handles movie idling rather than internal timer event loop
::CreateMovieControl( ::CreateMovieControl(
(WindowRef) (WindowRef)
m_ctrl->MacGetTopLevelWindowRef(), //parent ctrl->MacGetTopLevelWindowRef(), //parent
&bounds, //control bounds &bounds, //control bounds
m_movie, //movie handle m_movie, //movie handle
kMovieControlOptionHideController kMovieControlOptionHideController
@@ -427,10 +433,9 @@ void wxQTMediaBackend::FinishLoad()
| kMovieControlOptionSetKeysEnabled | kMovieControlOptionSetKeysEnabled
// | kMovieControlOptionManuallyIdled // | kMovieControlOptionManuallyIdled
, //flags , //flags
GetControlPeer(m_ctrl)->GetControlRefAddr() ); ctrl->m_peer->GetControlRefAddr() );
::EmbedControl(GetControlPeer(m_ctrl)->GetControlRef(), ::EmbedControl(ctrl->m_peer->GetControlRef(), (ControlRef)ctrl->GetParent()->GetHandle());
(ControlRef) m_ctrl->GetParent()->GetHandle());
#else #else
// //
//"Emulation" //"Emulation"
@@ -600,7 +605,7 @@ void wxQTMediaBackend::Cleanup()
m_timer = NULL; m_timer = NULL;
#if wxUSE_CREATEMOVIECONTROL #if wxUSE_CREATEMOVIECONTROL
DisposeControl(GetControlPeer(m_ctrl)->GetControlRef()); DisposeControl(((wxMediaCtrl*)m_ctrl)->m_peer->GetControlRef());
#endif #endif
StopMovie(m_movie); StopMovie(m_movie);