+//---------------------------------------------------------------------------
+// wxAMMediaBackend::GetState
+//
+// Returns the cached state
+//---------------------------------------------------------------------------
+wxMediaState wxAMMediaBackend::GetState()
+{
+ StateConstants nState;
+ HRESULT hr = m_pAM->get_CurrentState(&nState);
+ if(FAILED(hr))
+ {
+ wxAMLOG(hr);
+ return wxMEDIASTATE_STOPPED;
+ }
+
+ return (wxMediaState)nState;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::GetPlaybackRate
+//
+// Pretty simple way of obtaining the playback rate from
+// the IMediaSeeking interface
+//---------------------------------------------------------------------------
+double wxAMMediaBackend::GetPlaybackRate()
+{
+ double dRate;
+ HRESULT hr = m_pAM->get_Rate(&dRate);
+ if(FAILED(hr))
+ {
+ wxAMLOG(hr);
+ return 0.0;
+ }
+ return dRate;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::SetPlaybackRate
+//
+// Sets the playback rate of the media - DirectShow is pretty good
+// about this, actually
+//---------------------------------------------------------------------------
+bool wxAMMediaBackend::SetPlaybackRate(double dRate)
+{
+ HRESULT hr = m_pAM->put_Rate(dRate);
+ if(FAILED(hr))
+ {
+ wxAMLOG(hr);
+ return false;
+ }
+
+ return true;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::GetDownloadXXX
+//
+// Queries for and gets the total size of the file and the current
+// progress in downloading that file from the IAMOpenProgress
+// interface from the media player interface's filter graph
+//---------------------------------------------------------------------------
+void wxAMMediaBackend::DoGetDownloadProgress(wxLongLong* pLoadProgress,
+ wxLongLong* pLoadTotal)
+{
+ LONGLONG loadTotal = 0, loadProgress = 0;
+ IUnknown* pFG;
+ IAMOpenProgress* pOP;
+ HRESULT hr;
+ hr = m_pAM->get_FilterGraph(&pFG);
+ if(SUCCEEDED(hr))
+ {
+ hr = pFG->QueryInterface(IID_IAMOpenProgress, (void**)&pOP);
+ if(SUCCEEDED(hr))
+ {
+ hr = pOP->QueryProgress(&loadTotal, &loadProgress);
+ pOP->Release();
+ }
+ pFG->Release();
+ }
+
+ if(SUCCEEDED(hr))
+ {
+ *pLoadProgress = loadProgress;
+ *pLoadTotal = loadTotal;
+ }
+ else
+ {
+ //When not loading from a URL QueryProgress will return
+ //E_NOINTERFACE or whatever
+ //wxAMFAIL(hr);
+ *pLoadProgress = 0;
+ *pLoadTotal = 0;
+ }
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::GetVideoSize
+//
+// Obtains the cached original video size
+//---------------------------------------------------------------------------
+wxSize wxAMMediaBackend::GetVideoSize() const
+{
+ return m_bestSize;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::Move
+//
+// We take care of this in our redrawing
+//---------------------------------------------------------------------------
+void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
+ int WXUNUSED(w), int WXUNUSED(h))
+{
+}
+
+//---------------------------------------------------------------------------
+// End of wxAMMediaBackend
+//---------------------------------------------------------------------------
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//
+// wxMCIMediaBackend
+//
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+IMPLEMENT_DYNAMIC_CLASS(wxMCIMediaBackend, wxMediaBackend)
+
+//---------------------------------------------------------------------------
+// Usual debugging macros for MCI returns
+//---------------------------------------------------------------------------
+
+#ifdef __WXDEBUG__
+#define wxMCIVERIFY(arg) \
+{ \
+ DWORD nRet; \
+ if ( (nRet = (arg)) != 0) \
+ { \
+ TCHAR sz[5000]; \
+ mciGetErrorString(nRet, sz, 5000); \
+ wxFAIL_MSG(wxString::Format(_T("MCI Error:%s"), sz)); \
+ } \
+}
+#else
+#define wxMCIVERIFY(arg) (arg);
+#endif
+
+//---------------------------------------------------------------------------
+// Simulation for <digitalv.h>
+//
+// Mingw and possibly other compilers don't have the digitalv.h header
+// that is needed to have some essential features of mci work with
+// windows - so we provide the declarations for the types we use here
+//---------------------------------------------------------------------------
+
+typedef struct {
+ DWORD_PTR dwCallback;
+#ifdef MCI_USE_OFFEXT
+ POINT ptOffset;
+ POINT ptExtent;
+#else
+ RECT rc;
+#endif
+} MCI_DGV_RECT_PARMS;
+
+typedef struct {
+ DWORD_PTR dwCallback;
+ HWND hWnd;
+#ifndef _WIN32
+ WORD wReserved1;
+#endif
+ UINT nCmdShow;
+#ifndef _WIN32
+ WORD wReserved2;
+#endif
+ wxChar* lpstrText;
+} MCI_DGV_WINDOW_PARMS;
+
+typedef struct {
+ DWORD_PTR dwCallback;
+ DWORD dwTimeFormat;
+ DWORD dwAudio;
+ DWORD dwFileFormat;
+ DWORD dwSpeed;
+} MCI_DGV_SET_PARMS;
+
+typedef struct {
+ DWORD_PTR dwCallback;
+ DWORD dwItem;
+ DWORD dwValue;
+ DWORD dwOver;
+ wxChar* lpstrAlgorithm;
+ wxChar* lpstrQuality;
+} MCI_DGV_SETAUDIO_PARMS;
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend Constructor
+//
+// Here we don't need to do much except say we don't have any video :)
+//---------------------------------------------------------------------------
+wxMCIMediaBackend::wxMCIMediaBackend() : m_hNotifyWnd(NULL), m_bVideo(false)
+{
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend Destructor
+//
+// We close the mci device - note that there may not be an mci device here,
+// or it may fail - but we don't really care, since we're destructing
+//---------------------------------------------------------------------------
+wxMCIMediaBackend::~wxMCIMediaBackend()
+{
+ if(m_hNotifyWnd)
+ {
+ mciSendCommand(m_hDev, MCI_CLOSE, 0, 0);
+ DestroyWindow(m_hNotifyWnd);
+ m_hNotifyWnd = NULL;
+ }
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Create
+//
+// Here we just tell wxMediaCtrl that mci does exist (which it does, on all
+// msw systems, at least in some form dating back to win16 days)
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
+ wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ //
+ // Create window
+ // By default wxWindow(s) is created with a border -
+ // so we need to get rid of those, and create with
+ // wxCLIP_CHILDREN, so that if the driver/backend
+ // is a child window, it refereshes properly
+ //
+ if ( !ctrl->wxControl::Create(parent, id, pos, size,
+ (style & ~wxBORDER_MASK) | wxBORDER_NONE | wxCLIP_CHILDREN,
+ validator, name) )
+ return false;
+
+ m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
+ return true;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Load (file version)
+//
+// Here we have MCI load a file and device, set the time format to our
+// default (milliseconds), and set the video (if any) to play in the control
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::Load(const wxString& fileName)
+{
+ //
+ //if the user already called load close the previous MCI device
+ //
+ if(m_hNotifyWnd)
+ {
+ mciSendCommand(m_hDev, MCI_CLOSE, 0, 0);
+ DestroyWindow(m_hNotifyWnd);
+ m_hNotifyWnd = NULL;
+ }
+
+ //
+ //Opens a file and has MCI select a device. Normally you'd put
+ //MCI_OPEN_TYPE in addition to MCI_OPEN_ELEMENT - however if you
+ //omit this it tells MCI to select the device instead. This is
+ //good because we have no reliable way of "enumerating" the devices
+ //in MCI
+ //
+ MCI_OPEN_PARMS openParms;
+ openParms.lpstrElementName = (wxChar*) fileName.c_str();
+
+ if ( mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT,
+ (DWORD)(LPVOID)&openParms) != 0)
+ return false;
+
+ m_hDev = openParms.wDeviceID;
+
+ //
+ //Now set the time format for the device to milliseconds
+ //
+ MCI_SET_PARMS setParms;
+ setParms.dwCallback = 0;
+ setParms.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
+
+ if (mciSendCommand(m_hDev, MCI_SET, MCI_SET_TIME_FORMAT,
+ (DWORD)(LPVOID)&setParms) != 0)
+ return false;
+
+ //
+ //Now tell the MCI device to display the video in our wxMediaCtrl
+ //
+ MCI_DGV_WINDOW_PARMS windowParms;
+ windowParms.hWnd = (HWND)m_ctrl->GetHandle();
+
+ m_bVideo = (mciSendCommand(m_hDev, MCI_WINDOW,
+ 0x00010000L, //MCI_DGV_WINDOW_HWND
+ (DWORD)(LPVOID)&windowParms) == 0);
+
+ //
+ // Create a hidden window and register to handle
+ // MCI events
+ // Note that wxCanvasClassName is already registered
+ // and used by all wxWindows and normal wxControls
+ //
+ m_hNotifyWnd = ::CreateWindow
+ (
+ wxCanvasClassName,
+ NULL,
+ 0, 0, 0, 0,
+ 0,
+ (HWND) NULL,
+ (HMENU)NULL,
+ wxGetInstance(),
+ (LPVOID) NULL
+ );
+
+ if(!m_hNotifyWnd)
+ {
+ wxLogSysError( wxT("Could not create hidden needed for ")
+ wxT("registering for MCI events!") );
+
+ return false;
+ }
+
+ wxSetWindowProc(m_hNotifyWnd, wxMCIMediaBackend::NotifyWndProc);
+ wxSetWindowUserData(m_hNotifyWnd, this);
+
+ NotifyMovieLoaded();
+
+ return true;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Load (URL version)
+//
+// MCI doesn't support URLs directly (?)
+//
+// TODO: Use wxURL/wxFileSystem and mmioInstallProc
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::Load(const wxURI& WXUNUSED(location))
+{
+ return false;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Play
+//
+// Plays/Resumes the MCI device... a couple notes:
+// 1) Certain drivers will crash and burn if we don't pass them an
+// MCI_PLAY_PARMS, despite the documentation that says otherwise...
+// 2) There is a MCI_RESUME command, but MCI_PLAY does the same thing
+// and will resume from a stopped state also, so there's no need to
+// call both, for example
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::Play()
+{
+ MCI_PLAY_PARMS playParms;
+ playParms.dwCallback = (DWORD)m_hNotifyWnd;
+
+ bool bOK = ( mciSendCommand(m_hDev, MCI_PLAY, MCI_NOTIFY,
+ (DWORD)(LPVOID)&playParms) == 0 );
+
+ if(bOK)
+ m_ctrl->Show(m_bVideo);
+
+ return bOK;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Pause
+//
+// Pauses the MCI device - nothing special
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::Pause()
+{
+ return (mciSendCommand(m_hDev, MCI_PAUSE, MCI_WAIT, 0) == 0);
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Stop
+//
+// Stops the MCI device & seeks to the beginning as wxMediaCtrl docs outline
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::Stop()
+{
+ return (mciSendCommand(m_hDev, MCI_STOP, MCI_WAIT, 0) == 0) &&
+ (mciSendCommand(m_hDev, MCI_SEEK, MCI_SEEK_TO_START, 0) == 0);
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::GetState
+//
+// Here we get the state and convert it to a wxMediaState -
+// since we use direct comparisons with MCI_MODE_PLAY and
+// MCI_MODE_PAUSE, we don't care if the MCI_STATUS call
+// fails or not
+//---------------------------------------------------------------------------
+wxMediaState wxMCIMediaBackend::GetState()
+{
+ MCI_STATUS_PARMS statusParms;
+ statusParms.dwItem = MCI_STATUS_MODE;
+
+ mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
+ (DWORD)(LPVOID)&statusParms);
+
+ if(statusParms.dwReturn == MCI_MODE_PAUSE)
+ return wxMEDIASTATE_PAUSED;
+ else if(statusParms.dwReturn == MCI_MODE_PLAY)
+ return wxMEDIASTATE_PLAYING;
+ else
+ return wxMEDIASTATE_STOPPED;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::SetPosition
+//
+// Here we set the position of the device in the stream.
+// Note that MCI actually stops the device after you seek it if the
+// device is playing/paused, so we need to play the file after
+// MCI seeks like normal APIs would
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::SetPosition(wxLongLong where)
+{
+ MCI_SEEK_PARMS seekParms;
+ seekParms.dwCallback = 0;
+#if wxUSE_LONGLONG_NATIVE && !wxUSE_LONGLONG_WX
+ seekParms.dwTo = (DWORD)where.GetValue();
+#else /* wxUSE_LONGLONG_WX */
+ /* no way to return it in one piece */
+ wxASSERT( where.GetHi()==0 );
+ seekParms.dwTo = (DWORD)where.GetLo();
+#endif /* wxUSE_LONGLONG_* */
+
+ //device was playing?
+ bool bReplay = GetState() == wxMEDIASTATE_PLAYING;
+
+ if( mciSendCommand(m_hDev, MCI_SEEK, MCI_TO,
+ (DWORD)(LPVOID)&seekParms) != 0)
+ return false;
+
+ //If the device was playing, resume it
+ if (bReplay)
+ return Play();
+ else
+ return true;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::GetPosition
+//
+// Gets the position of the device in the stream using the current
+// time format... nothing special here...
+//---------------------------------------------------------------------------
+wxLongLong wxMCIMediaBackend::GetPosition()
+{
+ MCI_STATUS_PARMS statusParms;
+ statusParms.dwItem = MCI_STATUS_POSITION;
+
+ if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
+ (DWORD)(LPSTR)&statusParms) != 0)
+ return 0;
+
+ return statusParms.dwReturn;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::GetVolume
+//
+// Gets the volume of the current media via the MCI_DGV_STATUS_VOLUME
+// message. Value ranges from 0 (minimum) to 1000 (maximum volume).
+//---------------------------------------------------------------------------
+double wxMCIMediaBackend::GetVolume()
+{
+ MCI_STATUS_PARMS statusParms;
+ statusParms.dwCallback = 0;
+ statusParms.dwItem = 0x4019; //MCI_DGV_STATUS_VOLUME
+
+ if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
+ (DWORD)(LPSTR)&statusParms) != 0)
+ return 0;
+
+ return ((double)statusParms.dwReturn) / 1000.0;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::SetVolume
+//
+// Sets the volume of the current media via the MCI_DGV_SETAUDIO_VOLUME
+// message. Value ranges from 0 (minimum) to 1000 (maximum volume).
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::SetVolume(double dVolume)
+{
+ MCI_DGV_SETAUDIO_PARMS audioParms;
+ audioParms.dwCallback = 0;
+ audioParms.dwItem = 0x4002; //MCI_DGV_SETAUDIO_VOLUME
+ audioParms.dwValue = (DWORD) (dVolume * 1000.0);
+ audioParms.dwOver = 0;
+ audioParms.lpstrAlgorithm = NULL;
+ audioParms.lpstrQuality = NULL;
+
+ if (mciSendCommand(m_hDev, 0x0873, //MCI_SETAUDIO
+ //MCI_DGV_SETAUDIO+(_ITEM | _VALUE)
+ 0x00800000L | 0x01000000L,
+ (DWORD)(LPSTR)&audioParms) != 0)
+ return false;
+ return true;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::GetDuration
+//
+// Gets the duration of the stream... nothing special
+//---------------------------------------------------------------------------
+wxLongLong wxMCIMediaBackend::GetDuration()
+{
+ MCI_STATUS_PARMS statusParms;
+ statusParms.dwItem = MCI_STATUS_LENGTH;
+
+ if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
+ (DWORD)(LPSTR)&statusParms) != 0)
+ return 0;
+
+ return statusParms.dwReturn;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::Move
+//
+// Moves the window to a location
+//---------------------------------------------------------------------------
+void wxMCIMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
+ int w, int h)
+{
+ if (m_hNotifyWnd && m_bVideo)
+ {
+ MCI_DGV_RECT_PARMS putParms; //ifdefed MCI_DGV_PUT_PARMS
+ memset(&putParms, 0, sizeof(MCI_DGV_RECT_PARMS));
+ putParms.rc.bottom = h;
+ putParms.rc.right = w;
+
+ //wxStackWalker will crash and burn here on assert
+ //and mci doesn't like 0 and 0 for some reason (out of range )
+ //so just don't it in that case
+ if(w || h)
+ {
+ wxMCIVERIFY( mciSendCommand(m_hDev, MCI_PUT,
+ 0x00040000L, //MCI_DGV_PUT_DESTINATION
+ (DWORD)(LPSTR)&putParms) );
+ }
+ }
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::GetVideoSize
+//
+// Gets the original size of the movie for sizers
+//---------------------------------------------------------------------------
+wxSize wxMCIMediaBackend::GetVideoSize() const
+{
+ if(m_bVideo)
+ {
+ MCI_DGV_RECT_PARMS whereParms; //ifdefed MCI_DGV_WHERE_PARMS
+
+ wxMCIVERIFY( mciSendCommand(m_hDev, MCI_WHERE,
+ 0x00020000L, //MCI_DGV_WHERE_SOURCE
+ (DWORD)(LPSTR)&whereParms) );
+
+ return wxSize(whereParms.rc.right, whereParms.rc.bottom);
+ }
+ return wxSize(0,0);
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::GetPlaybackRate
+//
+// TODO
+//---------------------------------------------------------------------------
+double wxMCIMediaBackend::GetPlaybackRate()
+{
+ return 1.0;
+}
+
+//---------------------------------------------------------------------------
+// wxMCIMediaBackend::SetPlaybackRate
+//
+// TODO
+//---------------------------------------------------------------------------
+bool wxMCIMediaBackend::SetPlaybackRate(double WXUNUSED(dRate))
+{
+/*
+ MCI_WAVE_SET_SAMPLESPERSEC
+ MCI_DGV_SET_PARMS setParms;
+ setParms.dwSpeed = (DWORD) (dRate * 1000.0);
+
+ return (mciSendCommand(m_hDev, MCI_SET,
+ 0x00020000L, //MCI_DGV_SET_SPEED
+ (DWORD)(LPSTR)&setParms) == 0);
+*/
+ return false;
+}
+
+//---------------------------------------------------------------------------
+// [static] wxMCIMediaBackend::MSWWindowProc
+//
+// Here we process a message when MCI reaches the stopping point
+// in the stream
+//---------------------------------------------------------------------------
+LRESULT CALLBACK wxMCIMediaBackend::NotifyWndProc(HWND hWnd, UINT nMsg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ wxMCIMediaBackend* backend =
+ (wxMCIMediaBackend*)wxGetWindowUserData(hWnd);
+
+ return backend->OnNotifyWndProc(hWnd, nMsg, wParam, lParam);
+}
+
+LRESULT CALLBACK wxMCIMediaBackend::OnNotifyWndProc(HWND hWnd, UINT nMsg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ if(nMsg == MM_MCINOTIFY)
+ {
+ wxASSERT(lParam == (LPARAM) m_hDev);
+ if(wParam == MCI_NOTIFY_SUCCESSFUL && lParam == (LPARAM)m_hDev)
+ {
+ if ( SendStopEvent() )
+ {
+ wxMCIVERIFY( mciSendCommand(m_hDev, MCI_SEEK,
+ MCI_SEEK_TO_START, 0) );
+
+ QueueFinishEvent();
+ }
+ }
+ }
+ return DefWindowProc(hWnd, nMsg, wParam, lParam);
+}
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//
+// wxQTMediaBackend
+//
+// TODO: Use a less cludgy way to pause/get state/set state
+// FIXME: Greg Hazel reports that sometimes files that cannot be played
+// with this backend are treated as playable anyway - not verifyed though.
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
+
+//Time between timer calls - this is the Apple recommondation to the TCL
+//team I believe
+#define MOVIE_DELAY 20
+
+#include "wx/timer.h"
+
+
+//---------------------------------------------------------------------------
+// wxQTLoadTimer
+//
+// QT, esp. QT for Windows is very picky about how you go about
+// async loading. If you were to go through a Windows message loop
+// or a MoviesTask or both and then check the movie load state
+// it would still return 1000 (loading)... even (pre)prerolling doesn't
+// help. However, making a load timer like this works
+//---------------------------------------------------------------------------
+class wxQTLoadTimer : public wxTimer
+{
+public:
+ wxQTLoadTimer(Movie movie, wxQTMediaBackend* parent, wxQuickTimeLibrary* pLib) :
+ m_movie(movie), m_parent(parent), m_pLib(pLib) {}
+
+ void Notify()
+ {
+ m_pLib->MoviesTask(m_movie, 0);
+ //kMovieLoadStatePlayable
+ if(m_pLib->GetMovieLoadState(m_movie) >= 10000)
+ {
+ m_parent->FinishLoad();
+ delete this;
+ }
+ }
+
+protected:
+ Movie m_movie; //Our movie instance
+ wxQTMediaBackend* m_parent; //Backend pointer
+ wxQuickTimeLibrary* m_pLib; //Interfaces
+};
+
+
+// --------------------------------------------------------------------------
+// wxQTPlayTimer - Handle Asyncronous Playing
+//
+// 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.
+// --------------------------------------------------------------------------
+class wxQTPlayTimer : public wxTimer
+{
+public:
+ wxQTPlayTimer(Movie movie, wxQTMediaBackend* parent,
+ wxQuickTimeLibrary* pLib) :
+ m_movie(movie), m_parent(parent), m_pLib(pLib) {}
+
+ void Notify()
+ {
+ //
+ // OK, a little explaining - basically originally
+ // we only called MoviesTask if the movie was actually
+ // playing (not paused or stopped)... this was before
+ // we realized MoviesTask actually handles repainting
+ // of the current frame - so if you were to resize
+ // or something it would previously not redraw that
+ // portion of the movie.
+ //
+ // So now we call MoviesTask always so that it repaints
+ // correctly.
+ //
+ m_pLib->MoviesTask(m_movie, 0);
+
+ //
+ // Handle the stop event - if the movie has reached
+ // the end, notify our handler
+ //
+ // m_bPlaying == !(Stopped | Paused)
+ //
+ if (m_parent->m_bPlaying)
+ {
+ if(m_pLib->IsMovieDone(m_movie))
+ {
+ if ( m_parent->SendStopEvent() )
+ {
+ m_parent->Stop();
+ wxASSERT(m_pLib->GetMoviesError() == noErr);
+
+ m_parent->QueueFinishEvent();
+ }
+ }
+ }
+ }
+
+protected:
+ Movie m_movie; //Our movie instance
+ wxQTMediaBackend* m_parent; //Backend pointer
+ wxQuickTimeLibrary* m_pLib; //Interfaces
+};
+
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::QTWndProc
+//
+// Forwards events to the Movie Controller so that it can
+// redraw itself/process messages etc..
+//---------------------------------------------------------------------------
+LRESULT CALLBACK wxQTMediaBackend::QTWndProc(HWND hWnd, UINT nMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ wxQTMediaBackend* pThis = (wxQTMediaBackend*)wxGetWindowUserData(hWnd);
+
+ MSG msg;
+ msg.hwnd = hWnd;
+ msg.message = nMsg;
+ msg.wParam = wParam;
+ msg.lParam = lParam;
+ msg.time = 0;
+ msg.pt.x = 0;
+ msg.pt.y = 0;
+ EventRecord theEvent;
+ pThis->m_lib.NativeEventToMacEvent(&msg, &theEvent);
+ pThis->m_lib.MCIsPlayerEvent(pThis->m_pMC, &theEvent);
+ return pThis->m_ctrl->MSWWindowProc(nMsg, wParam, lParam);
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend Destructor
+//
+// Sets m_timer to NULL signifying we havn't loaded anything yet
+//---------------------------------------------------------------------------
+wxQTMediaBackend::wxQTMediaBackend()
+: m_movie(NULL), m_bPlaying(false), m_timer(NULL), m_pMC(NULL)
+{
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend Destructor
+//
+// 1) Cleans up the QuickTime movie instance
+// 2) Decrements the QuickTime reference counter - if this reaches
+// 0, QuickTime shuts down
+// 3) Decrements the QuickTime Windows Media Layer reference counter -
+// if this reaches 0, QuickTime shuts down the Windows Media Layer
+//---------------------------------------------------------------------------
+wxQTMediaBackend::~wxQTMediaBackend()
+{
+ if(m_movie)
+ Cleanup();
+
+ if(m_lib.IsOk())
+ {
+ if(m_pMC)
+ {
+ m_lib.DisposeMovieController(m_pMC);
+ // m_pMC = NULL;
+ }
+
+ // destroy wxQTMediaEvtHandler we pushed on it
+ m_ctrl->PopEventHandler(true);
+
+ m_lib.DestroyPortAssociation(
+ (CGrafPtr)m_lib.GetNativeWindowPort(m_ctrl->GetHWND()));
+
+ //Note that ExitMovies() is not necessary, but
+ //the docs are fuzzy on whether or not TerminateQTML is
+ m_lib.ExitMovies();
+ m_lib.TerminateQTML();
+ }
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::CreateControl
+//
+// 1) Intializes QuickTime
+// 2) Creates the control window
+//---------------------------------------------------------------------------
+bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
+ wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ if(!m_lib.Initialize())
+ return false;
+
+ int nError = m_lib.InitializeQTML(0);
+ if (nError != noErr) //-2093 no dll