]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/mediactrl.cpp
Compilation fix for unix builds with cygwin
[wxWidgets.git] / src / msw / mediactrl.cpp
index 2b1a0fd77b65858d0f346ac3696b5721c92ee5a5..6d56bfa700df7c41993fc4fc35dbc15760a56644 100644 (file)
 //---------------------------------------------------------------------------
 #if wxUSE_MEDIACTRL
 
+#include "wx/dcclient.h"
+#include "wx/thread.h"
+
 //---------------------------------------------------------------------------
 // Externals (somewhere in src/msw/app.cpp)
 //---------------------------------------------------------------------------
 extern "C" WXDLLIMPEXP_BASE HINSTANCE wxGetInstance(void);
 #ifdef __WXWINCE__
-extern WXDLLIMPEXP_CORE      wxChar *wxCanvasClassName;
+extern WXDLLIMPEXP_CORE       wxChar *wxCanvasClassName;
 #else
 extern WXDLLIMPEXP_CORE const wxChar *wxCanvasClassName;
 #endif
@@ -57,16 +60,471 @@ extern WXDLLIMPEXP_CORE const wxChar *wxCanvasClassName;
 //  wxAMMediaBackend
 //
 //---------------------------------------------------------------------------
+//
+//####################THE BIG DIRECTSHOW OVERVIEW############################
+//
+//
+//  OK... this deserves its own little tutorial.  Knowledge of COM and class
+//  factories is assumed throughout this code.
+//
+//  Basically, the way directshow works is that you tell it to render
+//  a file, and it builds and connects a bunch of filters together.
+//
+//  There are many, many ways to do this.
+//
+//  WAYS TO RENDER A FILE (URLS WORK IN DS ALSO)
+//
+//  1)  Create an instance of IGraphBuilder and call RenderFile on it
+//  2)  Create an instance of IMediaControl and call RenderFile on it
+//  3)  Create an instance of IAMMultiMediaStream, call
+//      IAMMultiMediaStream::AddStream and pass an IDirectDraw instance for
+//      the video, and pass an IDirectSound(Buffer?) instance or use the
+//      default sound renderer, then call RenderFile or RenderMoniker
+//  4)  Create a Moniker instance for the file and create and build
+//      all of the filtergraph manually
+//
+//  Our issue here is that we can't use the default representation of 1 and 2
+//  because the IVideoWindow instance hogs a lot of the useful window
+//  messages such as WM_SETCURSOR.
+//
+//  Solution #1 was to use #3 by creating a seperate IDirectDraw instance
+//  for our window and blitting to that through a thread... unfortunately
+//  the blitting resizing is very low quality and its quite slow.
+//
+//  The current way is to use windowless rendering and have directshow
+//  do all the DirectDraw-style clipping to our window
+//
+//  ~~~~~~~~~~~~~~AFTER RENDERING THE FILE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+//  When done rendering the file, we need to get several interfaces from
+//  either a IMediaControl or IGraphBuilder instance -
+//
+//  IMediaPosition - we can set the rate with this... we can also get
+//  positions and set positions through this with REFTIME (double) instead
+//  of the normal LONGLONG that IAMMultiMediaStream and IMediaControl use
+//
+//  IBasicAudio - we need this for setting/getting the volume
+//
+//  Interfaces that we don't use but might be useful one day -
+//
+//  IDirectDrawVideo - you can get this through the IFilter returned
+//  from L"Video Renderer" filter from FindFilter on the IGraphBuilder.
+//  Through this we can set the IDirectDraw instance DrawShow uses.
+//
+//  ~~~~~~~~~~~~~~STOPPING~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+//  There are two ways we can do this -
+//  1)  Have a thread compare the current position to the end position
+//  about every 10 milliseconds
+//  2)  Have IMediaSeekingEx send a message to a windowproc or signal a
+//  windows event
+//
+//  Note that we can do these both, I.E. if an IMediaSeekingEx interface
+//  is unavailable we can check the position instead of an event
+//
+//---------------------------------------------------------------------------
 
 //---------------------------------------------------------------------------
-//  Compilation guard for DirectShow
+//  COM includes
 //---------------------------------------------------------------------------
-#if wxUSE_DIRECTSHOW
+#include "wx/msw/ole/oleutils.h" //wxBasicString, IID etc.
+#include "wx/msw/ole/uuid.h" //IID etc..
 
 //---------------------------------------------------------------------------
-//  DirectShow includes
+//  COM compatability definitions
+//---------------------------------------------------------------------------
+#ifndef STDMETHODCALLTYPE
+#define STDMETHODCALLTYPE __stdcall
+#endif
+#ifndef STDMETHOD
+#define STDMETHOD(funcname)  virtual HRESULT STDMETHODCALLTYPE funcname
+#endif
+#ifndef PURE
+#define PURE = 0
+#endif
 //---------------------------------------------------------------------------
-#include <dshow.h>
+//  IIDS - used by CoCreateInstance and IUnknown::QueryInterface
+//  Dumped from amstream.idl, quartz.idl, direct draw and with some
+//  confirmation from WINE
+//
+//  Some of these are not used but are kept here for future reference anyway
+//---------------------------------------------------------------------------
+
+//QUARTZ
+const IID LIBID_QuartzTypeLib = {0x56A868B0,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IAMCollection = {0x56A868B9,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IMediaControl = {0x56A868B1,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IMediaEvent = {0x56A868B6,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IMediaEventEx = {0x56A868C0,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IMediaPosition = {0x56A868B2,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IBasicAudio = {0x56A868B3,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IVideoWindow = {0x56A868B4,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IBasicVideo = {0x56A868B5,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IBasicVideo2 = {0x329BB360,0xF6EA,0x11D1,{0x90,0x38,0x00,0xA0,0xC9,0x69,0x72,0x98}};
+const IID IID_IDeferredCommand = {0x56A868B8,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IQueueCommand = {0x56A868B7,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IFilterInfo = {0x56A868BA,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IRegFilterInfo = {0x56A868BB,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IMediaTypeInfo = {0x56A868BC,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IPinInfo = {0x56A868BD,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+const IID IID_IAMStats = {0xBC9BCF80,0xDCD2,0x11D2,{0xAB,0xF6,0x00,0xA0,0xC9,0x05,0xF3,0x75}};
+const CLSID CLSID_FilgraphManager = {0xE436EBB3,0x524F,0x11CE,{0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
+
+//AMSTREAM
+const CLSID CLSID_AMMultiMediaStream = {0x49C47CE5, 0x9BA4, 0x11D0,{0x82, 0x12, 0x00, 0xC0, 0x4F, 0xC3, 0x2C, 0x45}};
+const IID IID_IAMMultiMediaStream = {0xBEBE595C, 0x9A6F, 0x11D0,{0x8F, 0xDE, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}};
+const IID IID_IDirectDrawMediaStream = {0xF4104FCE, 0x9A70, 0x11D0,{0x8F, 0xDE, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}};
+const GUID MSPID_PrimaryVideo = {0xa35FF56A, 0x9FDA, 0x11D0,{0x8F, 0xDF, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}};
+const GUID MSPID_PrimaryAudio = {0xa35FF56B, 0x9FDA, 0x11D0,{0x8F, 0xDF, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}};
+
+//DDRAW
+const IID IID_IDirectDraw = {0x6C14DB80,0xA733,0x11CE,{0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60}};
+const CLSID CLSID_DirectDraw = {0xD7B70EE0,0x4340,0x11CF,{0xB0,0x63,0x00,0x20,0xAF,0xC2,0xCD,0x35}};
+
+//??  QUARTZ Also?
+const CLSID CLSID_VideoMixingRenderer = {0xB87BEB7B, 0x8D29, 0x423F,{0xAE, 0x4D, 0x65, 0x82, 0xC1, 0x01, 0x75, 0xAC}};
+const IID IID_IVMRWindowlessControl =   {0x0EB1088C, 0x4DCD, 0x46F0,{0x87, 0x8F, 0x39, 0xDA, 0xE8, 0x6A, 0x51, 0xB7}};
+const IID IID_IFilterGraph =            {0x56A8689F, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}};
+const IID IID_IGraphBuilder =           {0x56A868A9, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}};
+const IID IID_IVMRFilterConfig =        {0x9E5530C5, 0x7034, 0x48B4,{0xBB, 0x46, 0x0B, 0x8A, 0x6E, 0xFC, 0x8E, 0x36}};
+const IID IID_IBaseFilter =             {0x56A86895, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}};
+
+//---------------------------------------------------------------------------
+//  DIRECTDRAW COM INTERFACES
+//---------------------------------------------------------------------------
+//DDSURFACESDESC - we don't need most of the stuff here, esp. DDPIXELFORMAT,
+//so just put stubs in
+struct DDPIXELFORMAT {DWORD dw1,dw2,dw3,dw4,dw5,dw6,dw7,dw8;};
+struct DDCOLORKEY {DWORD dwLow, dwHigh;};
+
+typedef struct IDirectDrawClipper* LPDIRECTDRAWCLIPPER;
+typedef struct IDirectDraw* LPDIRECTDRAW;
+typedef struct IDirectDrawSurface* LPDIRECTDRAWSURFACE;
+typedef struct DDSURFACEDESC* LPDDSURFACEDESC;
+typedef struct IDirectDrawPalette* LPDIRECTDRAWPALETTE;
+typedef struct DDSCAPS* LPDDSCAPS;
+typedef DDCOLORKEY* LPDDCOLORKEY;
+typedef DDPIXELFORMAT* LPDDPIXELFORMAT;
+typedef struct DDCAPS* LPDDCAPS;
+
+struct DDSURFACEDESC
+{
+    DWORD               dwSize;
+    DWORD               dwFlags;
+    DWORD               dwHeight;
+    DWORD               dwWidth;
+    union
+    {
+        LONG            lPitch;
+        DWORD           dwLinearSize;
+    };
+    DWORD               dwBackBufferCount;
+    union
+    {
+        DWORD           dwMipMapCount;
+        DWORD           dwZBufferBitDepth;
+        DWORD           dwRefreshRate;
+    };
+    DWORD               dwAlphaBitDepth;
+    DWORD               dwReserved;
+    LPVOID              lpSurface;
+    DDCOLORKEY          ddckCKDestOverlay;
+    DDCOLORKEY          ddckCKDestBlt;
+    DDCOLORKEY          ddckCKSrcOverlay;
+    DDCOLORKEY          ddckCKSrcBlt;
+    DDPIXELFORMAT ddpfPixelFormat;
+    struct DDSCAPS {DWORD dwCaps;} ddsCaps;
+};
+
+struct IDirectDrawClipper : public IUnknown
+{
+    STDMETHOD(GetClipList)(LPRECT, LPRGNDATA, LPDWORD) PURE;
+    STDMETHOD(GetHWnd)(HWND*) PURE;
+    STDMETHOD(Initialize)(LPDIRECTDRAW, DWORD) PURE;
+    STDMETHOD(IsClipListChanged)(BOOL*) PURE;
+    STDMETHOD(SetClipList)(LPRGNDATA,DWORD) PURE;
+    STDMETHOD(SetHWnd)(DWORD, HWND) PURE;
+};
+
+struct IDirectDrawSurface : public IUnknown
+{
+    STDMETHOD(AddAttachedSurface)(LPDIRECTDRAWSURFACE) PURE;
+    STDMETHOD(AddOverlayDirtyRect)(LPRECT) PURE;
+    STDMETHOD(Blt)(LPRECT,LPDIRECTDRAWSURFACE, LPRECT,DWORD, struct DDBLTFX*) PURE;
+    STDMETHOD(BltBatch)(struct DDBLTBATCH*, DWORD, DWORD ) PURE;
+    STDMETHOD(BltFast)(DWORD,DWORD,LPDIRECTDRAWSURFACE, LPRECT,DWORD) PURE;
+    STDMETHOD(DeleteAttachedSurface)(DWORD,LPDIRECTDRAWSURFACE) PURE;
+    STDMETHOD(EnumAttachedSurfaces)(LPVOID, LPVOID/*LPDDENUMSURFACESCALLBACK*/) PURE;
+    STDMETHOD(EnumOverlayZOrders)(DWORD,LPVOID,LPVOID/*LPDDENUMSURFACESCALLBACK*/) PURE;
+    STDMETHOD(Flip)(LPDIRECTDRAWSURFACE, DWORD) PURE;
+    STDMETHOD(GetAttachedSurface)(LPDDSCAPS, LPDIRECTDRAWSURFACE*) PURE;
+    STDMETHOD(GetBltStatus)(DWORD) PURE;
+    STDMETHOD(GetCaps)(LPDDSCAPS) PURE;
+    STDMETHOD(GetClipper)(LPDIRECTDRAWCLIPPER*) PURE;
+    STDMETHOD(GetColorKey)(DWORD, LPDDCOLORKEY) PURE;
+    STDMETHOD(GetDC)(HDC *) PURE;
+    STDMETHOD(GetFlipStatus)(DWORD) PURE;
+    STDMETHOD(GetOverlayPosition)(LPLONG, LPLONG ) PURE;
+    STDMETHOD(GetPalette)(LPDIRECTDRAWPALETTE FAR*) PURE;
+    STDMETHOD(GetPixelFormat)(LPDDPIXELFORMAT) PURE;
+    STDMETHOD(GetSurfaceDesc)(LPDDSURFACEDESC) PURE;
+    STDMETHOD(Initialize)(LPDIRECTDRAW, LPDDSURFACEDESC) PURE;
+    STDMETHOD(IsLost)(THIS) PURE;
+    STDMETHOD(Lock)(LPRECT,LPDDSURFACEDESC,DWORD,HANDLE) PURE;
+    STDMETHOD(ReleaseDC)(HDC) PURE;
+    STDMETHOD(Restore)(THIS) PURE;
+    STDMETHOD(SetClipper)(LPDIRECTDRAWCLIPPER) PURE;
+    STDMETHOD(SetColorKey)(DWORD, LPDDCOLORKEY) PURE;
+    STDMETHOD(SetOverlayPosition)(LONG, LONG ) PURE;
+    STDMETHOD(SetPalette)(IUnknown*) PURE;
+    STDMETHOD(Unlock)(LPVOID) PURE;
+    STDMETHOD(UpdateOverlay)(LPRECT, LPDIRECTDRAWSURFACE,LPRECT,
+                               DWORD, struct DDOVERLAYFX*) PURE;
+    STDMETHOD(UpdateOverlayDisplay)(DWORD) PURE;
+    STDMETHOD(UpdateOverlayZOrder)(DWORD, LPDIRECTDRAWSURFACE) PURE;
+};
+
+struct IDirectDraw : public IUnknown
+{
+    STDMETHOD(Compact)() PURE;
+    STDMETHOD(CreateClipper)(DWORD, LPDIRECTDRAWCLIPPER*, IUnknown * ) PURE;
+    STDMETHOD(CreatePalette)(DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown * ) PURE;
+    STDMETHOD(CreateSurface)(LPDDSURFACEDESC, LPDIRECTDRAWSURFACE *, IUnknown *) PURE;
+    STDMETHOD(DuplicateSurface)(LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE * ) PURE;
+    STDMETHOD(EnumDisplayModes)(DWORD, LPDDSURFACEDESC, LPVOID, LPVOID ) PURE;
+    STDMETHOD(EnumSurfaces)(DWORD, LPDDSURFACEDESC, LPVOID,LPVOID ) PURE;
+    STDMETHOD(FlipToGDISurface)() PURE;
+    STDMETHOD(GetCaps)(LPDDCAPS, LPDDCAPS) PURE;
+    STDMETHOD(GetDisplayMode)(LPDDSURFACEDESC) PURE;
+    STDMETHOD(GetFourCCCodes)(LPDWORD, LPDWORD ) PURE;
+    STDMETHOD(GetGDISurface)(LPDIRECTDRAWSURFACE *) PURE;
+    STDMETHOD(GetMonitorFrequency)(LPDWORD) PURE;
+    STDMETHOD(GetScanLine)(LPDWORD) PURE;
+    STDMETHOD(GetVerticalBlankStatus)(LPBOOL ) PURE;
+    STDMETHOD(Initialize)(GUID *) PURE;
+    STDMETHOD(RestoreDisplayMode)() PURE;
+    STDMETHOD(SetCooperativeLevel)(HWND, DWORD) PURE;
+    STDMETHOD(SetDisplayMode)(DWORD, DWORD,DWORD, DWORD, DWORD) PURE;
+    STDMETHOD(WaitForVerticalBlank)(DWORD, HANDLE ) PURE;
+};
+
+//---------------------------------------------------------------------------
+//  AMMEDIA COM INTERFACES
+//---------------------------------------------------------------------------
+struct IMediaStream;
+struct IMultiMediaStream;
+struct IStreamSample : public IUnknown
+{
+public:
+    STDMETHOD(GetMediaStream)(IMediaStream **) PURE;
+    STDMETHOD(GetSampleTimes)(LONGLONG *, LONGLONG *, LONGLONG *) PURE;
+    STDMETHOD(SetSampleTimes)(const LONGLONG *, const LONGLONG *) PURE;
+    STDMETHOD(Update)(DWORD, HANDLE, LPVOID, DWORD_PTR) PURE;
+    STDMETHOD(CompletionStatus)(DWORD, DWORD) PURE;
+};
+
+struct IDirectDrawStreamSample : public IStreamSample
+{
+public:
+    STDMETHOD(GetSurface)(IDirectDrawSurface **, RECT *) PURE;
+    STDMETHOD(SetRect)(const RECT *) PURE;
+};
+
+struct IMediaStream : public IUnknown
+{
+    STDMETHOD(GetMultiMediaStream)(IMultiMediaStream **) PURE;
+    STDMETHOD(GetInformation)(GUID *, int *) PURE;
+    STDMETHOD(SetSameFormat)(IMediaStream *, DWORD) PURE;
+    STDMETHOD(AllocateSample)(DWORD, IStreamSample **) PURE;
+    STDMETHOD(CreateSharedSample)(IStreamSample *, DWORD,
+                                  IStreamSample **) PURE;
+    STDMETHOD(SendEndOfStream)(DWORD dwFlags) PURE;
+};
+
+struct IDirectDrawMediaStream : public IMediaStream
+{
+    STDMETHOD(GetFormat)(DDSURFACEDESC *, IDirectDrawPalette **,
+                         DDSURFACEDESC *, DWORD *) PURE;
+    STDMETHOD(SetFormat)(const DDSURFACEDESC *, IDirectDrawPalette *) PURE;
+    STDMETHOD(GetDirectDraw)(IDirectDraw **) PURE;
+    STDMETHOD(SetDirectDraw)(IDirectDraw *) PURE;
+    STDMETHOD(CreateSample)(IDirectDrawSurface *, const RECT *,
+                              DWORD, IDirectDrawStreamSample **) PURE;
+    STDMETHOD(GetTimePerFrame)(LONGLONG *) PURE;
+};
+
+struct IMultiMediaStream : public IUnknown
+{
+    STDMETHOD(GetInformation)(DWORD *, int *) PURE;
+    STDMETHOD(GetMediaStream)(REFGUID, IMediaStream **) PURE;
+    STDMETHOD(EnumMediaStreams)(long, IMediaStream **) PURE;
+    STDMETHOD(GetState)(int *pCurrentState) PURE;
+    STDMETHOD(SetState)(int NewState) PURE;
+    STDMETHOD(GetTime)(LONGLONG *pCurrentTime) PURE;
+    STDMETHOD(GetDuration)(LONGLONG *pDuration) PURE;
+    STDMETHOD(Seek)(LONGLONG SeekTime) PURE;
+    STDMETHOD(GetEndOfStreamEventHandle)(HANDLE *phEOS) PURE;
+};
+
+struct IAMMultiMediaStream : public IMultiMediaStream
+{
+    STDMETHOD(Initialize)(int, DWORD, IUnknown *) PURE;
+    STDMETHOD(GetFilterGraph)(IUnknown **) PURE;
+    STDMETHOD(GetFilter)(IUnknown **) PURE;
+    STDMETHOD(AddMediaStream)(IUnknown *, const GUID*, DWORD,
+                              IMediaStream **) PURE;
+    STDMETHOD(OpenFile)(LPCWSTR, DWORD) PURE;
+    STDMETHOD(OpenMoniker)(IBindCtx *, IMoniker *, DWORD) PURE;
+    STDMETHOD(Render)(DWORD) PURE;
+};
+
+//---------------------------------------------------------------------------
+//  QUARTZ COM INTERFACES (dumped from quartz.idl from MSVC COM Browser)
+//---------------------------------------------------------------------------
+struct IAMCollection : public IDispatch
+{
+    STDMETHOD(get_Count)(long *) PURE;
+    STDMETHOD(Item)(long, IUnknown **) PURE;
+    STDMETHOD(get__NewEnum)(IUnknown **) PURE;
+};
+
+struct IMediaControl : public IDispatch
+{
+    STDMETHOD(Run)() PURE;
+    STDMETHOD(Pause)() PURE;
+    STDMETHOD(Stop)() PURE;
+    STDMETHOD(GetState)(long, long*) PURE;
+    STDMETHOD(RenderFile)(BSTR) PURE;
+    STDMETHOD(AddSourceFilter)(BSTR, IDispatch **) PURE;
+    STDMETHOD(get_FilterCollection)(IDispatch **) PURE;
+    STDMETHOD(get_RegFilterCollection)(IDispatch **) PURE;
+    STDMETHOD(StopWhenReady)() PURE;
+};
+
+struct IMediaEvent : public IDispatch
+{
+    STDMETHOD(GetEventHandle)(LONG_PTR *) PURE;
+    STDMETHOD(GetEvent)(long *, LONG_PTR *, LONG_PTR *, long) PURE;
+    STDMETHOD(WaitForCompletion)(long, long *) PURE;
+    STDMETHOD(CancelDefaultHandling)(long) PURE;
+    STDMETHOD(RestoreDefaultHandling)(long) PURE;
+    STDMETHOD(FreeEventParams)(long, LONG_PTR, LONG_PTR) PURE;
+};
+
+struct IMediaEventEx : public IMediaEvent
+{
+    STDMETHOD(SetNotifyWindow)(LONG_PTR, long, LONG_PTR) PURE;
+    STDMETHOD(SetNotifyFlags)(long) PURE;
+    STDMETHOD(GetNotifyFlags)(long *) PURE;
+};
+
+struct IMediaPosition : public IDispatch
+{
+    STDMETHOD(get_Duration)(double *) PURE;
+    STDMETHOD(put_CurrentPosition)(double) PURE;
+    STDMETHOD(get_CurrentPosition)(double *) PURE;
+    STDMETHOD(get_StopTime)(double *) PURE;
+    STDMETHOD(put_StopTime)(double) PURE;
+    STDMETHOD(get_PrerollTime)(double *) PURE;
+    STDMETHOD(put_PrerollTime)(double) PURE;
+    STDMETHOD(put_Rate)(double) PURE;
+    STDMETHOD(get_Rate)(double *) PURE;
+    STDMETHOD(CanSeekForward)(long *) PURE;
+    STDMETHOD(CanSeekBackward)(long *) PURE;
+};
+
+struct IBasicAudio : public IDispatch
+{
+    STDMETHOD(put_Volume)(long) PURE;
+    STDMETHOD(get_Volume)(long *) PURE;
+    STDMETHOD(put_Balance)(long) PURE;
+    STDMETHOD(get_Balance)(long *) PURE;
+};
+
+//---------------------------------------------------------------------------
+// MISC COM INTERFACES
+//---------------------------------------------------------------------------
+struct IVMRWindowlessControl : public IUnknown
+{
+    STDMETHOD(GetNativeVideoSize)(LONG *, LONG *, LONG *, LONG *) PURE;
+    STDMETHOD(GetMinIdealVideoSize)(LONG *, LONG *) PURE;
+    STDMETHOD(GetMaxIdealVideoSize)(LONG *, LONG *) PURE;
+    STDMETHOD(SetVideoPosition)(const LPRECT,const LPRECT) PURE;
+    STDMETHOD(GetVideoPosition)(LPRECT, LPRECT) PURE;
+    STDMETHOD(GetAspectRatioMode)(DWORD *) PURE;
+    STDMETHOD(SetAspectRatioMode)(DWORD) PURE;
+    STDMETHOD(SetVideoClippingWindow)(HWND) PURE;
+    STDMETHOD(RepaintVideo)(HWND, HDC) PURE;
+    STDMETHOD(DisplayModeChanged)() PURE;
+    STDMETHOD(GetCurrentImage)(BYTE **) PURE;
+    STDMETHOD(SetBorderColor)(COLORREF) PURE;
+    STDMETHOD(GetBorderColor)(COLORREF *) PURE;
+    STDMETHOD(SetColorKey)(COLORREF) PURE;
+    STDMETHOD(GetColorKey)(COLORREF *) PURE;
+};
+
+typedef IUnknown IVMRImageCompositor;
+
+struct IVMRFilterConfig : public IUnknown
+{
+    STDMETHOD(SetImageCompositor)(IVMRImageCompositor *) PURE;
+    STDMETHOD(SetNumberOfStreams)(DWORD) PURE;
+    STDMETHOD(GetNumberOfStreams)(DWORD *) PURE;
+    STDMETHOD(SetRenderingPrefs)(DWORD) PURE;
+    STDMETHOD(GetRenderingPrefs)(DWORD *) PURE;
+    STDMETHOD(SetRenderingMode)(DWORD) PURE;
+    STDMETHOD(GetRenderingMode)(DWORD *) PURE;
+};
+
+typedef IUnknown IBaseFilter;
+typedef IUnknown IPin;
+typedef IUnknown IEnumFilters;
+typedef int AM_MEDIA_TYPE;
+
+struct IFilterGraph : public IUnknown
+{
+    STDMETHOD(AddFilter)(IBaseFilter *, LPCWSTR) PURE;
+    STDMETHOD(RemoveFilter)(IBaseFilter *) PURE;
+    STDMETHOD(EnumFilters)(IEnumFilters **) PURE;
+    STDMETHOD(FindFilterByName)(LPCWSTR, IBaseFilter **) PURE;
+    STDMETHOD(ConnectDirect)(IPin *, IPin *, const AM_MEDIA_TYPE *) PURE;
+    STDMETHOD(Reconnect)(IPin *) PURE;
+    STDMETHOD(Disconnect)(IPin *) PURE;
+    STDMETHOD(SetDefaultSyncSource)() PURE;
+};
+
+struct IGraphBuilder : public IFilterGraph
+{
+public:
+    STDMETHOD(Connect)(IPin *, IPin *) PURE;
+    STDMETHOD(Render)(IPin *) PURE;
+    STDMETHOD(RenderFile)(LPCWSTR, LPCWSTR) PURE;
+    STDMETHOD(AddSourceFilter)(LPCWSTR, LPCWSTR, IBaseFilter **) PURE;
+    STDMETHOD(SetLogFile)(DWORD_PTR) PURE;
+    STDMETHOD(Abort)() PURE;
+    STDMETHOD(ShouldOperationContinue)() PURE;
+};
+
+//------------------------------------------------------------------
+// wxAMMediaBackend (Active Movie)
+//------------------------------------------------------------------
+class WXDLLIMPEXP_MEDIA wxAMMediaThread : public wxThread
+{
+public:
+    virtual ExitCode Entry();
+
+    class wxAMMediaBackend* pThis;
+};
+
+//cludgy workaround for wx events.  slots would be nice :)
+class WXDLLIMPEXP_MEDIA wxAMMediaEvtHandler : public wxEvtHandler
+{
+public:
+    void OnPaint(wxPaintEvent&);
+    void OnEraseBackground(wxEraseEvent&);
+};
+
+typedef BOOL (WINAPI* LPAMGETERRORTEXT)(HRESULT, wxChar *, DWORD);
 
 class WXDLLIMPEXP_MEDIA wxAMMediaBackend : public wxMediaBackend
 {
@@ -102,33 +560,42 @@ public:
     virtual double GetPlaybackRate();
     virtual bool SetPlaybackRate(double);
 
-    void Cleanup();
+    virtual double GetVolume();
+    virtual bool SetVolume(double);
 
-    bool m_bVideo;
-
-    static LRESULT CALLBACK NotifyWndProc(HWND hWnd, UINT nMsg,
-                                          WPARAM wParam, LPARAM lParam);
-
-    LRESULT CALLBACK OnNotifyWndProc(HWND hWnd, UINT nMsg,
-                                          WPARAM wParam, LPARAM lParam);
+    void Cleanup();
+    void OnStop();
+    bool SetWindowlessMode(IGraphBuilder* pGB,
+                           IVMRWindowlessControl** ppVMC = NULL);
 
     wxControl* m_ctrl;
 
+    wxMediaState m_state;
+    wxCriticalSection m_rendercs;
+
+    IVMRWindowlessControl* m_pVMC;
     IGraphBuilder* m_pGB;
-    IMediaControl* m_pMC;
-    IMediaEventEx* m_pME;
-    IVideoWindow* m_pVW;
     IBasicAudio* m_pBA;
-    IBasicVideo* m_pBV;
-    IMediaSeeking* m_pMS;
+    IMediaControl* m_pMC;
+    IMediaEvent* m_pME;
+    IMediaPosition* m_pMS;
+    bool m_bVideo;
+
+    wxAMMediaThread* m_pThread;
 
-    HWND m_hNotifyWnd;
     wxSize m_bestSize;
 
-    DECLARE_DYNAMIC_CLASS(wxAMMediaBackend);
-};
+#ifdef __WXDEBUG__
+    HMODULE m_hQuartzDll;
+    LPAMGETERRORTEXT m_lpAMGetErrorText;
+    wxString GetErrorString(HRESULT hrdsv);
+#endif
+
+    friend class wxAMMediaThread;
+    friend class wxAMMediaEvtHandler;
 
-#endif //wxUSE_DIRECTSHOW
+    DECLARE_DYNAMIC_CLASS(wxAMMediaBackend)
+};
 
 //---------------------------------------------------------------------------
 //
@@ -175,6 +642,9 @@ public:
     virtual double GetPlaybackRate();
     virtual bool SetPlaybackRate(double dRate);
 
+    virtual double GetVolume();
+    virtual bool SetVolume(double);
+
     static LRESULT CALLBACK NotifyWndProc(HWND hWnd, UINT nMsg,
                                              WPARAM wParam, LPARAM lParam);
 
@@ -186,7 +656,7 @@ public:
     HWND m_hNotifyWnd;      //Window to use for MCI events
     bool m_bVideo;          //Whether or not we have video
 
-    DECLARE_DYNAMIC_CLASS(wxMCIMediaBackend);
+    DECLARE_DYNAMIC_CLASS(wxMCIMediaBackend)
 };
 
 //---------------------------------------------------------------------------
@@ -196,20 +666,225 @@ public:
 //---------------------------------------------------------------------------
 
 //---------------------------------------------------------------------------
-//  QT Compilation Guard
+//  QT Includes
 //---------------------------------------------------------------------------
-#if wxUSE_QUICKTIME
+//#include <qtml.h>                   //Windoze QT include
+//#include <QuickTimeComponents.h>    //Standard QT stuff
+#include "wx/dynlib.h"
+
+//---------------------------------------------------------------------------
+//  QT Types
+//---------------------------------------------------------------------------
+typedef struct MovieRecord* Movie;
+typedef wxInt16 OSErr;
+typedef wxInt32 OSStatus;
+#define noErr 0
+#define fsRdPerm 1
+typedef unsigned char                   Str255[256];
+#define StringPtr unsigned char*
+#define newMovieActive 1
+#define Ptr char*
+#define Handle Ptr*
+#define Fixed long
+#define OSType unsigned long
+#define CGrafPtr struct GrafPort *
+#define TimeScale long
+#define TimeBase struct TimeBaseRecord *
+
+#ifndef URLDataHandlerSubType
+#if defined(__WATCOMC__) || defined(__MINGW32__)
+// use magic numbers for compilers which complain about multicharacter integers
+const OSType URLDataHandlerSubType     = 1970433056;
+const OSType VisualMediaCharacteristic = 1702454643;
+#else
+const OSType URLDataHandlerSubType     = 'url ';
+const OSType VisualMediaCharacteristic = 'eyes';
+#endif
+#endif
+
+struct FSSpec {
+    short      vRefNum;
+    long       parID;
+    Str255     name;  /*Str63 on mac, Str255 on msw */
+};
+
+struct Rect {
+    short      top;
+    short      left;
+    short      bottom;
+    short      right;
+};
+
+struct wide {
+    wxInt32    hi;
+    wxUint32   lo;
+};
+
+struct TimeRecord {
+    wide       value; /* units */
+    TimeScale  scale; /* units per second */
+    TimeBase   base;
+};
 
 //---------------------------------------------------------------------------
-//  QT Includes
+//  QT Library
 //---------------------------------------------------------------------------
-#include <qtml.h>                   //Windoze QT include
-#include <QuickTimeComponents.h>    //Standard QT stuff
+#define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
+    typedef rettype (* name ## Type) args ; \
+    name ## Type pfn_ ## name; \
+    rettype name args \
+    { if (m_ok) return pfn_ ## name shortargs ; return defret; }
 
-class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackend
+#define wxDL_VOIDMETHOD_DEFINE( name, args, shortargs ) \
+    typedef void (* name ## Type) args ; \
+    name ## Type pfn_ ## name; \
+    void name args \
+    { if (m_ok) pfn_ ## name shortargs ; }
+
+#define wxDL_METHOD_LOAD( lib, name, success ) \
+    pfn_ ## name = (name ## Type) lib.GetSymbol( wxT(#name), &success ); \
+    if (!success) { wxLog::EnableLogging(bWasLoggingEnabled); return false; }
+
+
+//Class that utilizes Robert Roeblings Dynamic Library Macros
+class WXDLLIMPEXP_MEDIA wxQuickTimeLibrary
 {
 public:
+    ~wxQuickTimeLibrary()
+    {
+        if(m_dll.IsLoaded())
+            m_dll.Unload();
+    }
+
+    bool Initialize();
+    bool IsOk() const {return m_ok;}
+
+protected:
+    wxDynamicLibrary m_dll;
+    bool m_ok;
+
+public:
+    wxDL_VOIDMETHOD_DEFINE( StartMovie, (Movie m), (m) );
+    wxDL_VOIDMETHOD_DEFINE( StopMovie, (Movie m), (m) );
+    wxDL_METHOD_DEFINE( bool, IsMovieDone, (Movie m), (m), false);
+    wxDL_VOIDMETHOD_DEFINE( GoToBeginningOfMovie, (Movie m), (m) );
+    wxDL_METHOD_DEFINE( OSErr, GetMoviesError, (), (), -1);
+    wxDL_METHOD_DEFINE( OSErr, EnterMovies, (), (), -1);
+    wxDL_VOIDMETHOD_DEFINE( ExitMovies, (), () );
+    wxDL_METHOD_DEFINE( OSErr, InitializeQTML, (long flags), (flags), -1);
+    wxDL_VOIDMETHOD_DEFINE( TerminateQTML, (), () );
+
+    wxDL_METHOD_DEFINE( OSErr, NativePathNameToFSSpec,
+                        (char* inName, FSSpec* outFile, long flags),
+                        (inName, outFile, flags), -1);
+
+    wxDL_METHOD_DEFINE( OSErr, OpenMovieFile,
+                        (const FSSpec * fileSpec, short * resRefNum, wxInt8 permission),
+                        (fileSpec, resRefNum, permission), -1 );
+
+    wxDL_METHOD_DEFINE( OSErr, CloseMovieFile,
+                        (short resRefNum), (resRefNum), -1);
+
+    wxDL_METHOD_DEFINE( OSErr, NewMovieFromFile,
+                            (Movie * theMovie, short resRefNum, short *  resId,
+                             StringPtr resName, short newMovieFlags,
+                             bool * dataRefWasChanged),
+                             (theMovie, resRefNum, resId, resName, newMovieFlags,
+                              dataRefWasChanged), -1);
+
+    wxDL_VOIDMETHOD_DEFINE( SetMovieRate, (Movie m, Fixed rate), (m, rate) );
+    wxDL_METHOD_DEFINE( Fixed, GetMovieRate, (Movie m), (m), 0);
+    wxDL_VOIDMETHOD_DEFINE( MoviesTask, (Movie m, long maxms), (m, maxms) );
+    wxDL_VOIDMETHOD_DEFINE( BlockMove,
+        (const char* p1, const char* p2, long s), (p1,p2,s) );
+    wxDL_METHOD_DEFINE( Handle, NewHandleClear, (long s), (s), NULL );
+
+    wxDL_METHOD_DEFINE( OSErr, NewMovieFromDataRef,
+                           (Movie * m, short flags, short * id,
+                            Handle  dataRef, OSType  dataRefType),
+                            (m,flags,id,dataRef,dataRefType), -1 );
+
+    wxDL_VOIDMETHOD_DEFINE( DisposeHandle, (Handle h), (h) );
+    wxDL_VOIDMETHOD_DEFINE( GetMovieNaturalBoundsRect, (Movie m, Rect* r), (m,r) );
+    wxDL_METHOD_DEFINE( void*, GetMovieIndTrackType,
+                        (Movie m, long index, OSType type, long flags),
+                        (m,index,type,flags), NULL );
+    wxDL_VOIDMETHOD_DEFINE( CreatePortAssociation,
+            (void* hWnd, void* junk, long morejunk), (hWnd, junk, morejunk) );
+    wxDL_METHOD_DEFINE(void*, GetNativeWindowPort, (void* hWnd), (hWnd), NULL);
+    wxDL_VOIDMETHOD_DEFINE(SetMovieGWorld, (Movie m, CGrafPtr port, void* whatever),
+                            (m, port, whatever) );
+    wxDL_VOIDMETHOD_DEFINE(DisposeMovie, (Movie m), (m) );
+    wxDL_VOIDMETHOD_DEFINE(SetMovieBox, (Movie m, Rect* r), (m,r));
+    wxDL_VOIDMETHOD_DEFINE(SetMovieTimeScale, (Movie m, long s), (m,s));
+    wxDL_METHOD_DEFINE(long, GetMovieDuration, (Movie m), (m), 0);
+    wxDL_METHOD_DEFINE(TimeBase, GetMovieTimeBase, (Movie m), (m), 0);
+    wxDL_METHOD_DEFINE(TimeScale, GetMovieTimeScale, (Movie m), (m), 0);
+    wxDL_METHOD_DEFINE(long, GetMovieTime, (Movie m, void* cruft), (m,cruft), 0);
+    wxDL_VOIDMETHOD_DEFINE(SetMovieTime, (Movie m, TimeRecord* tr), (m,tr) );
+    wxDL_METHOD_DEFINE(short, GetMovieVolume, (Movie m), (m), 0);
+    wxDL_VOIDMETHOD_DEFINE(SetMovieVolume, (Movie m, short sVolume), (m,sVolume) );
+};
+
+bool wxQuickTimeLibrary::Initialize()
+{
+    m_ok = false;
 
+    bool bWasLoggingEnabled = wxLog::EnableLogging(false);    //Turn off the wxDynamicLibrary logging
+
+    if(!m_dll.Load(wxT("qtmlClient.dll")))
+    {
+        wxLog::EnableLogging(bWasLoggingEnabled);
+        return false;
+    }
+
+    bool bOk;   //TODO:  Get rid of this, use m_ok instead (not a biggie)
+
+    wxDL_METHOD_LOAD( m_dll, StartMovie, bOk );
+    wxDL_METHOD_LOAD( m_dll, StopMovie, bOk );
+    wxDL_METHOD_LOAD( m_dll, IsMovieDone, bOk );
+    wxDL_METHOD_LOAD( m_dll, GoToBeginningOfMovie, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMoviesError, bOk );
+    wxDL_METHOD_LOAD( m_dll, EnterMovies, bOk );
+    wxDL_METHOD_LOAD( m_dll, ExitMovies, bOk );
+    wxDL_METHOD_LOAD( m_dll, InitializeQTML, bOk );
+    wxDL_METHOD_LOAD( m_dll, TerminateQTML, bOk );
+    wxDL_METHOD_LOAD( m_dll, NativePathNameToFSSpec, bOk );
+    wxDL_METHOD_LOAD( m_dll, OpenMovieFile, bOk );
+    wxDL_METHOD_LOAD( m_dll, CloseMovieFile, bOk );
+    wxDL_METHOD_LOAD( m_dll, NewMovieFromFile, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieRate, bOk );
+    wxDL_METHOD_LOAD( m_dll, SetMovieRate, bOk );
+    wxDL_METHOD_LOAD( m_dll, MoviesTask, bOk );
+    wxDL_METHOD_LOAD( m_dll, BlockMove, bOk );
+    wxDL_METHOD_LOAD( m_dll, NewHandleClear, bOk );
+    wxDL_METHOD_LOAD( m_dll, NewMovieFromDataRef, bOk );
+    wxDL_METHOD_LOAD( m_dll, DisposeHandle, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieNaturalBoundsRect, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieIndTrackType, bOk );
+    wxDL_METHOD_LOAD( m_dll, CreatePortAssociation, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetNativeWindowPort, bOk );
+    wxDL_METHOD_LOAD( m_dll, SetMovieGWorld, bOk );
+    wxDL_METHOD_LOAD( m_dll, DisposeMovie, bOk );
+    wxDL_METHOD_LOAD( m_dll, SetMovieBox, bOk );
+    wxDL_METHOD_LOAD( m_dll, SetMovieTimeScale, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieDuration, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieTimeBase, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieTimeScale, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieTime, bOk );
+    wxDL_METHOD_LOAD( m_dll, SetMovieTime, bOk );
+    wxDL_METHOD_LOAD( m_dll, GetMovieVolume, bOk );
+    wxDL_METHOD_LOAD( m_dll, SetMovieVolume, bOk );
+
+    wxLog::EnableLogging(bWasLoggingEnabled);
+    m_ok = true;
+
+    return true;
+}
+
+class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackend
+{
+public:
     wxQTMediaBackend();
     ~wxQTMediaBackend();
 
@@ -240,22 +915,22 @@ public:
     virtual double GetPlaybackRate();
     virtual bool SetPlaybackRate(double dRate);
 
+    virtual double GetVolume();
+    virtual bool SetVolume(double);
+
     void Cleanup();
     void FinishLoad();
 
     wxSize m_bestSize;              //Original movie size
-    struct MovieRecord* m_movie;    //QT Movie handle/instance
+    Movie m_movie;    //QT Movie handle/instance
     wxControl* m_ctrl;              //Parent control
     bool m_bVideo;                  //Whether or not we have video
     class _wxQTTimer* m_timer;      //Timer for streaming the movie
+    wxQuickTimeLibrary m_lib;
 
-    DECLARE_DYNAMIC_CLASS(wxQTMediaBackend);
+    DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
 };
 
-//---------------------------------------------------------------------------
-//  End QT Compilation Guard
-//---------------------------------------------------------------------------
-#endif //wxUSE_QUICKTIME
 
 //===========================================================================
 //  IMPLEMENTATION
@@ -267,44 +942,45 @@ public:
 //
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-//---------------------------------------------------------------------------
-// Only use if user wants it -
-//---------------------------------------------------------------------------
-#if wxUSE_DIRECTSHOW
-
 IMPLEMENT_DYNAMIC_CLASS(wxAMMediaBackend, wxMediaBackend);
 
-// Numerical value for when the graph reaches the stop position
-#define WM_GRAPHNOTIFY  WM_USER+13
-
 //---------------------------------------------------------------------------
 // Usual debugging macros
 //---------------------------------------------------------------------------
 #ifdef __WXDEBUG__
-#define wxAMVERIFY(x) \
-{ \
-    HRESULT hrdsv = (x); \
-    if ( FAILED(hrdsv) ) \
-    { \
-        /*TCHAR szError[MAX_ERROR_TEXT_LEN];*/ \
-        /*if( AMGetErrorText(hrdsv, szError, MAX_ERROR_TEXT_LEN) == 0)*/ \
-        /*{*/ \
-            /*wxFAIL_MSG( wxString::Format(wxT("DirectShow error \"%s\" ")*/\
-                                         /*wxT("occured at line %i in ")*/ \
-                                         /*wxT("mediactrl.cpp"),*/ \
-                                            /*szError, __LINE__) );*/ \
-        /*}*/ \
-        /*else*/ \
-            wxFAIL_MSG( wxString::Format(wxT("Unknown error (%i) ") \
-                                         wxT("occured at") \
-                                         wxT(" line %i in mediactrl.cpp."), \
-                                         (int)hrdsv, __LINE__) ); \
-    } \
+#define MAX_ERROR_TEXT_LEN 160
+#include "wx/log.h"             //wxLogDebug et al.
+
+//Get the error string for Active Movie
+wxString wxAMMediaBackend::GetErrorString(HRESULT hrdsv)
+{
+    wxChar szError[MAX_ERROR_TEXT_LEN];
+    if( m_lpAMGetErrorText != NULL &&
+       (*m_lpAMGetErrorText)(hrdsv, szError, MAX_ERROR_TEXT_LEN) == 0)
+    {
+        return wxString::Format(wxT("DirectShow error \"%s\" \n")
+                                     wxT("(numeric %i)\n")
+                                     wxT("occured at line %i in ")
+                                     wxT("mediactrl.cpp"),
+                                     szError, (int)hrdsv, __LINE__);
+    }
+    else
+    {
+        return wxString::Format(wxT("Unknown error (%i) ")
+                                     wxT("occurred at")
+                                     wxT(" line %i in mediactrl.cpp."),
+                                     (int)hrdsv, __LINE__);
+    }
 }
+
+#define wxAMFAIL(x) wxFAIL_MSG(GetErrorString(x));
 #define wxVERIFY(x) wxASSERT((x))
+#define wxAMLOG(x) wxLogDebug(GetErrorString(x))
 #else
 #define wxAMVERIFY(x) (x)
 #define wxVERIFY(x) (x)
+#define wxAMLOG(x)
+#define wxAMFAIL(x)
 #endif
 
 //---------------------------------------------------------------------------
@@ -317,7 +993,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxAMMediaBackend, wxMediaBackend);
 //
 // Sets m_hNotifyWnd to NULL to signify that we haven't loaded anything yet
 //---------------------------------------------------------------------------
-wxAMMediaBackend::wxAMMediaBackend() : m_hNotifyWnd(NULL)
+wxAMMediaBackend::wxAMMediaBackend()
+                 :m_state(wxMEDIASTATE_STOPPED)
+                 ,m_pVMC(NULL)
+                 ,m_pGB(NULL)
+                 ,m_pBA(NULL)
+                 ,m_pMC(NULL)
+                 ,m_pME(NULL)
+                 ,m_pMS(NULL)
+                 ,m_pThread(NULL)
+#ifdef __WXDEBUG__
+                 ,m_hQuartzDll(NULL)
+#endif
 {
 }
 
@@ -328,17 +1015,19 @@ wxAMMediaBackend::wxAMMediaBackend() : m_hNotifyWnd(NULL)
 //---------------------------------------------------------------------------
 wxAMMediaBackend::~wxAMMediaBackend()
 {
-    if (m_hNotifyWnd)
+    if (m_pVMC)
         Cleanup();
+#ifdef __WXDEBUG__
+    if(m_hQuartzDll)
+        ::FreeLibrary(m_hQuartzDll);
+#endif
 }
 
 //---------------------------------------------------------------------------
 // wxAMMediaBackend::CreateControl
 //
-// ActiveMovie does not really have any native control to speak of,
-// so we just create a normal control.
-//
-// We also check to see if ActiveMovie is installed
+// 1) Check to see if Active Movie supports windowless controls
+// 2) Connect events to the media control and its TLW
 //---------------------------------------------------------------------------
 bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
                                      wxWindowID id,
@@ -348,132 +1037,231 @@ bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
                                      const wxValidator& validator,
                                      const wxString& name)
 {
-    //create our filter graph
-    HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
-                      IID_IGraphBuilder, (void**)&m_pGB);
+#ifdef __WXDEBUG__
+    m_hQuartzDll = ::LoadLibrary(wxT("quartz.dll"));
+    if(m_hQuartzDll)
+    {
+            m_lpAMGetErrorText = (LPAMGETERRORTEXT) ::GetProcAddress(
+                m_hQuartzDll,
+            wxString::Format(wxT("AMGetErrorText%s"),
+
+#ifdef __WXUNICODE__
+            wxT("W")
+#else
+            wxT("A")
+#endif
+#ifdef __WXWINCE__
+                             )
+#else
+                             ).mb_str(wxConvLocal)
+#endif
+                             );
+    }
+#endif
+
+    //Make sure a valid windowless video mixing interface exists
+    IGraphBuilder* pGB;
+    if( ::CoCreateInstance(CLSID_FilgraphManager, NULL,
+                                  CLSCTX_INPROC_SERVER,
+                                  IID_IGraphBuilder, (void**)&pGB) != 0 )
+        return false;
 
-   //directshow not installed?
-    if ( FAILED(hr) )
+    if( !SetWindowlessMode(pGB) )
         return false;
 
-    //release the filter graph - we don't need it yet
-    m_pGB->Release();
-    m_pGB = NULL;
+    //clean up
+    pGB->Release();
 
     //
     // 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
+    // is a child window, it refreshes properly
     //
     if ( !ctrl->wxControl::Create(parent, id, pos, size,
                             (style & ~wxBORDER_MASK) | wxBORDER_NONE | wxCLIP_CHILDREN,
                             validator, name) )
         return false;
 
+    // My problem with this was only with a previous patch, probably the third rewrite
+    // fixed it as a side-effect. In fact, the erase background style of drawing not
+    // only works now, but is much better than paint-based updates (the paint event
+    // handler flickers if the wxMediaCtrl shares a sizer with another child window,
+    // or is on a notebook)
+    //  - Greg Hazel
+    ctrl->Connect(ctrl->GetId(), wxEVT_ERASE_BACKGROUND,
+        wxEraseEventHandler(wxAMMediaEvtHandler::OnEraseBackground),
+        NULL, (wxEvtHandler*) this);
+
+    //
+    // done...
+    //
     m_ctrl = ctrl;
     return true;
 }
 
-
 //---------------------------------------------------------------------------
-// wxAMMediaBackend::Load (file version)
+// wxAMMediaBackend::SetWindowlessMode
 //
-// Creates an Active Movie filter graph from a file or url
+// Adds a Video Mixing Renderer to a Filter Graph and obtains the
+// windowless control from it
 //---------------------------------------------------------------------------
-bool wxAMMediaBackend::Load(const wxString& fileName)
+bool wxAMMediaBackend::SetWindowlessMode(IGraphBuilder* pGB,
+                                         IVMRWindowlessControl** ppVMC)
 {
-    if(m_hNotifyWnd)
-        Cleanup();
-
-    CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
-                      IID_IGraphBuilder, (void**)&m_pGB);
+    HRESULT hr;
 
-    //load the graph & render
-    if( FAILED(m_pGB->RenderFile(fileName.wc_str(wxConvLocal), NULL)) )
+    //
+    // Create and add a custom Video Mixing Render to the graph
+    //
+    IBaseFilter* pVMR;
+    if( ::CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
+                CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pVMR) != 0 )
         return false;
 
-    //get the interfaces, all of them
-    wxAMVERIFY( m_pGB->QueryInterface(IID_IMediaControl, (void**)&m_pMC) );
-    wxAMVERIFY( m_pGB->QueryInterface(IID_IMediaEventEx, (void**)&m_pME) );
-    wxAMVERIFY( m_pGB->QueryInterface(IID_IMediaSeeking, (void**)&m_pMS) );
-    wxAMVERIFY( m_pGB->QueryInterface(IID_IVideoWindow, (void**)&m_pVW) );
-    wxAMVERIFY( m_pGB->QueryInterface(IID_IBasicAudio, (void**)&m_pBA) );
-    wxAMVERIFY( m_pGB->QueryInterface(IID_IBasicVideo, (void**)&m_pBV) );
-
-    //We could tell if the media has audio or not by
-    //something like
-    //-----
-    //long lVolume;
-    //pBA->get_Volume(&lVolume) == E_NOTIMPL
-    //-----
-    //here...
+    hr = pGB->AddFilter(pVMR, L"Video Mixing Renderer");
+    if ( hr != 0)
+    {
+        wxAMLOG(hr);
+        pVMR->Release();
+        return false;
+    }
 
     //
-    //Obtain the _actual_ size of the movie & remember it
+    // Set the graph to windowless mode
     //
-    long    nX,
-            nY;
+    IVMRFilterConfig* pConfig;
+    hr = pVMR->QueryInterface(IID_IVMRFilterConfig, (void**)&pConfig);
+    if( hr != 0 )
+    {
+        wxAMLOG(hr);
+        pVMR->Release();
+        return false;
+    }
 
-    m_bestSize.x = m_bestSize.y = 0;
+    hr = pConfig->SetRenderingMode(2);
+    if( hr != 0) //2 == VMRMode_Windowless
+    {
+        wxAMLOG(hr);
+        pConfig->Release();
+        pVMR->Release();
+        return false;
+    }
 
-    m_bVideo = SUCCEEDED( m_pVW->GetWindowPosition( &nX,
-                                                    &nY,
-                                                    (long*)&m_bestSize.x,
-                                                    (long*)&m_bestSize.y) );
+    pConfig->Release();
 
     //
-    //If we have video in the media - set it up so that
-    //its a child window of the control, its visible,
-    //and that the control is the owner of the video window
+    // Obtain the windowless control
     //
-    if (m_bVideo)
+    IVMRWindowlessControl* pVMC;
+    hr = pVMR->QueryInterface(IID_IVMRWindowlessControl, (void**)&pVMC);
+    if( hr != 0 )
     {
-        wxAMVERIFY( m_pVW->put_Owner((OAHWND)m_ctrl->GetHandle()) );
-        wxAMVERIFY( m_pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS) );
-        wxAMVERIFY( m_pVW->put_Visible(OATRUE) ); //OATRUE == -1
+        wxAMLOG(hr);
+        pVMR->Release();
+        return false;
     }
 
     //
-    // Create a hidden window and register to handle
-    // directshow events for this graph
-    // Note that wxCanvasClassName is already registered
-    // and used by all wxWindows and normal wxControls
+    // Success
     //
-    m_hNotifyWnd = ::CreateWindow
-                    (
-                        wxCanvasClassName,
-                        NULL,
-                        0, 0, 0, 0,
-                        0,
-                        (HWND) NULL,
-                        (HMENU)NULL,
-                        wxGetInstance(),
-                        (LPVOID) NULL
-                    );
+    if(ppVMC)
+        *ppVMC = pVMC;
+    else
+        pVMC->Release();
 
-    if(!m_hNotifyWnd)
+    pVMR->Release();
+    return true;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::Load (file version)
+//
+// 1) Cleans up previously loaded data
+// 2) Creates a filter graph
+// 3) Add a video mixer, set the graph to windowless mode and clip
+//    output to our media control
+// 4) Query interfaces to use later
+// 5) Get native video size (which becomes our best size)
+// 6) Refresh parent's sizers
+// 7) Start event/rendering thread
+//---------------------------------------------------------------------------
+bool wxAMMediaBackend::Load(const wxString& fileName)
+{
+    HRESULT hr;
+
+    //if previously loaded cleanup
+    if(m_pVMC)
+        Cleanup();
+
+    //Create interfaces - we already checked for success in CreateControl
+    ::CoCreateInstance(CLSID_FilgraphManager, NULL, CLSCTX_INPROC_SERVER,
+                     IID_IGraphBuilder, (void**)&m_pGB);
+
+
+    // Set and clip output
+    SetWindowlessMode(m_pGB, &m_pVMC);
+    hr = m_pVMC->SetVideoClippingWindow((HWND)m_ctrl->GetHandle());
+
+    if(hr != 0)
     {
-        wxLogSysError( wxT("Could not create hidden needed for ")
-                       wxT("registering for DirectShow events!")  );
+        m_bestSize.x = m_bestSize.y = 0;
+        wxAMFAIL(hr);
+        return false;
+    }
+
+    //load the graph & render
+    if( m_pGB->RenderFile(fileName.wc_str(wxConvLocal), NULL) != 0 )
+        return false;
 
+    //
+    //Get the interfaces, all of them
+    //
+    hr = m_pGB->QueryInterface(IID_IMediaEvent, (void**)&m_pME);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
         return false;
     }
 
-    ::SetWindowLongPtr(m_hNotifyWnd, GWLP_WNDPROC,
-                       (LONG_PTR)wxAMMediaBackend::NotifyWndProc);
+    hr = m_pGB->QueryInterface(IID_IMediaControl, (void**)&m_pMC);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return false;
+    }
 
-    ::SetWindowLong(m_hNotifyWnd, GWL_USERDATA,
-                       (LONG) this);
+    hr = m_pGB->QueryInterface(IID_IMediaPosition, (void**)&m_pMS);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return false;
+    }
 
-    wxAMVERIFY( m_pME->SetNotifyWindow((OAHWND)m_hNotifyWnd,
-                                       WM_GRAPHNOTIFY, 0) );
+    hr = m_pGB->QueryInterface(IID_IBasicAudio, (void**)&m_pBA);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        //not critical
+    }
 
     //
-    //set the time format
+    // Get original video size
     //
-    wxAMVERIFY( m_pMS->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME) );
+    hr = m_pVMC->GetNativeVideoSize((LONG*)&m_bestSize.x, (LONG*)&m_bestSize.y,
+                                   NULL, NULL);
+    if(hr != 0)
+    {
+        m_bestSize.x = m_bestSize.y = 0;
+        wxAMFAIL(hr);
+        return false;
+    }
+
+    if(m_bestSize.x == 0 && m_bestSize.y == 0)
+        m_bVideo = false;
+    else
+        m_bVideo = true;
 
     //
     // Force the parent window of this control to recalculate
@@ -484,7 +1272,19 @@ bool wxAMMediaBackend::Load(const wxString& fileName)
     m_ctrl->GetParent()->Layout();
     m_ctrl->GetParent()->Refresh();
     m_ctrl->GetParent()->Update();
+    m_ctrl->SetSize(m_ctrl->GetSize());
 
+    //
+    //  Create the event thread
+    //
+    m_pThread = new wxAMMediaThread;
+    m_pThread->pThis = this;
+    m_pThread->Create();
+    m_pThread->Run();
+
+    //
+    //  done
+    //
     return true;
 }
 
@@ -500,14 +1300,53 @@ bool wxAMMediaBackend::Load(const wxURI& location)
     return Load(location.BuildUnescapedURI());
 }
 
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::Cleanup
+//
+// Releases all the directshow interfaces we use
+// TODO: Maybe only create one instance of IAMMultiMediaStream and reuse it
+// rather than recreating it each time?
+//---------------------------------------------------------------------------
+void wxAMMediaBackend::Cleanup()
+{
+    // RN:  This could be a bad ptr if load failed after
+    // m_pVMC was created
+    if(m_pThread)
+    {
+        m_pThread->Delete();
+        m_pThread = NULL;
+    }
+
+    // Release and zero DirectShow interfaces
+    SAFE_RELEASE(m_pMC);
+    SAFE_RELEASE(m_pME);
+    SAFE_RELEASE(m_pMS);
+    SAFE_RELEASE(m_pBA);
+    SAFE_RELEASE(m_pGB);
+    SAFE_RELEASE(m_pVMC);
+}
+
+
 //---------------------------------------------------------------------------
 // wxAMMediaBackend::Play
 //
-// Plays the stream.  If it is non-seekable, it will restart it.
+// Plays the stream.  If it is non-seekable, it will restart it (implicit).
+//
+// Note that we use SUCCEEDED here because run/pause/stop tend to be overly
+// picky and return warnings on pretty much every call
 //---------------------------------------------------------------------------
 bool wxAMMediaBackend::Play()
 {
-    return SUCCEEDED( m_pMC->Run() );
+    wxCriticalSectionLocker lock(m_rendercs);
+
+    if( SUCCEEDED(m_pMC->Run()) )
+    {
+        m_state = wxMEDIASTATE_PLAYING;
+        m_ctrl->Refresh(); //videoless control finicky about refreshing
+        return true;
+    }
+
+    return false;
 }
 
 //---------------------------------------------------------------------------
@@ -517,7 +1356,15 @@ bool wxAMMediaBackend::Play()
 //---------------------------------------------------------------------------
 bool wxAMMediaBackend::Pause()
 {
-    return SUCCEEDED( m_pMC->Pause() );
+    wxCriticalSectionLocker lock(m_rendercs);
+
+    if( SUCCEEDED(m_pMC->Pause()) )
+    {
+        m_state = wxMEDIASTATE_PAUSED;
+        return true;
+    }
+
+    return false;
 }
 
 //---------------------------------------------------------------------------
@@ -527,34 +1374,43 @@ bool wxAMMediaBackend::Pause()
 //---------------------------------------------------------------------------
 bool wxAMMediaBackend::Stop()
 {
-    bool bOK = SUCCEEDED( m_pMC->Stop() );
+    wxCriticalSectionLocker lock(m_rendercs);
 
+    if( SUCCEEDED(m_pMC->Stop()) )
+    {
     //We don't care if it can't get to the beginning in directshow -
     //it could be a non-seeking filter (wince midi) in which case playing
     //starts all over again
-    SetPosition(0);
-    return bOK;
+        wxAMMediaBackend::SetPosition(0);
+
+        m_state = wxMEDIASTATE_STOPPED;
+        return true;
+    }
+
+    return false;
 }
 
 //---------------------------------------------------------------------------
 // wxAMMediaBackend::SetPosition
 //
 // 1) Translates the current position's time to directshow time,
-//    which is in a scale of 100 nanoseconds
+//    which is in a scale of 1 second (in a double)
 // 2) Sets the play position of the IMediaSeeking interface -
 //    passing NULL as the stop position means to keep the old
 //    stop position
 //---------------------------------------------------------------------------
 bool wxAMMediaBackend::SetPosition(wxLongLong where)
 {
-    LONGLONG pos = ((LONGLONG)where.GetValue()) * 10000;
+    HRESULT hr = m_pMS->put_CurrentPosition(
+                        ((LONGLONG)where.GetValue()) / 1000.0
+                                     );
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return false;
+    }
 
-    return SUCCEEDED( m_pMS->SetPositions(
-                                &pos,
-                                AM_SEEKING_AbsolutePositioning,
-                                NULL,
-                                AM_SEEKING_NoPositioning
-                                    ) );
+    return true;
 }
 
 //---------------------------------------------------------------------------
@@ -565,51 +1421,108 @@ bool wxAMMediaBackend::SetPosition(wxLongLong where)
 //---------------------------------------------------------------------------
 wxLongLong wxAMMediaBackend::GetPosition()
 {
-    LONGLONG outCur, outStop;
-    wxAMVERIFY( m_pMS->GetPositions(&outCur, &outStop) );
+    double outCur;
+    HRESULT hr = m_pMS->get_CurrentPosition(&outCur);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return 0;
+    }
+
+    //h,m,s,milli - outdur is in 1 second (double)
+    outCur *= 1000;
+    wxLongLong ll;
+    ll.Assign(outCur);
+
+    return ll;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::GetVolume
+//
+// Gets the volume through the IBasicAudio interface -
+// value ranges from 0 (MAX volume) to -10000 (minimum volume).
+// -100 per decibel.
+//---------------------------------------------------------------------------
+double wxAMMediaBackend::GetVolume()
+{
+    if(m_pBA)
+    {
+        long lVolume;
+        HRESULT hr = m_pBA->get_Volume(&lVolume);
+        if(FAILED(hr))
+        {
+            wxAMLOG(hr);
+            return 0.0;
+        }
+
+        return (((double)(lVolume + 10000)) / 10000.0);
+    }
+
+    wxLogDebug(wxT("No directshow audio interface"));
+    return 0.0;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::SetVolume
+//
+// Sets the volume through the IBasicAudio interface -
+// value ranges from 0 (MAX volume) to -10000 (minimum volume).
+// -100 per decibel.
+//---------------------------------------------------------------------------
+bool wxAMMediaBackend::SetVolume(double dVolume)
+{
+    if(m_pBA)
+    {
+        HRESULT hr = m_pBA->put_Volume( (long) ((dVolume-1.0) * 10000.0) );
+        if(FAILED(hr))
+        {
+            wxAMLOG(hr);
+            return false;
+        }
+        return true;
+    }
 
-    //h,m,s,milli - outdur is in 100 nanos
-    return outCur/10000;
+    wxLogDebug(wxT("No directshow audio interface"));
+    return false;
 }
 
 //---------------------------------------------------------------------------
 // wxAMMediaBackend::GetDuration
 //
-// 1) Obtains the duration of the media from the IMediaSeeking interface
+// 1) Obtains the duration of the media from IAMMultiMediaStream
 // 2) Converts that value to our time base, and returns it
+//
+// NB: With VBR MP3 files the default DirectShow MP3 render does not
+// read the Xing header correctly, resulting in skewed values for duration
+// and seeking
 //---------------------------------------------------------------------------
 wxLongLong wxAMMediaBackend::GetDuration()
 {
-    LONGLONG outDuration;
-    wxAMVERIFY( m_pMS->GetDuration(&outDuration) );
+    double outDuration;
+    HRESULT hr = m_pMS->get_Duration(&outDuration);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return 0;
+    }
+
+    //h,m,s,milli - outdur is in 1 second (double)
+    outDuration *= 1000;
+    wxLongLong ll;
+    ll.Assign(outDuration);
 
-    //h,m,s,milli - outdur is in 100 nanos
-    return outDuration/10000;
+    return ll;
 }
 
 //---------------------------------------------------------------------------
 // wxAMMediaBackend::GetState
 //
-// Obtains the state from the IMediaControl interface.
-// Note that it's enumeration values for stopping/playing
-// etc. are the same as ours, so we just do a straight cast.
-// TODO: MS recommends against INFINITE here for
-//       IMediaControl::GetState- do it in stages
+// Returns the cached state
 //---------------------------------------------------------------------------
 wxMediaState wxAMMediaBackend::GetState()
 {
-    HRESULT hr;
-    OAFilterState theState;
-    hr = m_pMC->GetState(INFINITE, &theState);
-
-    wxASSERT( SUCCEEDED(hr) );
-
-    //MSW state is the same as ours
-    //State_Stopped   = 0,
-    //State_Paused    = State_Stopped + 1,
-    //State_Running   = State_Paused + 1
-
-    return (wxMediaState) theState;
+    return m_state;
 }
 
 //---------------------------------------------------------------------------
@@ -621,7 +1534,12 @@ wxMediaState wxAMMediaBackend::GetState()
 double wxAMMediaBackend::GetPlaybackRate()
 {
     double dRate;
-    wxAMVERIFY( m_pMS->GetRate(&dRate) );
+    HRESULT hr = m_pMS->get_Rate(&dRate);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return 0.0;
+    }
     return dRate;
 }
 
@@ -633,31 +1551,74 @@ double wxAMMediaBackend::GetPlaybackRate()
 //---------------------------------------------------------------------------
 bool wxAMMediaBackend::SetPlaybackRate(double dRate)
 {
-    return SUCCEEDED( m_pMS->SetRate(dRate) );
+    HRESULT hr = m_pMS->put_Rate(dRate);
+    if(FAILED(hr))
+    {
+        wxAMLOG(hr);
+        return false;
+    }
+
+    return true;
+}
+
+//---------------------------------------------------------------------------
+// wxAMMediaBackend::GetVideoSize
+//
+// Obtains the cached original video size
+//---------------------------------------------------------------------------
+wxSize wxAMMediaBackend::GetVideoSize() const
+{
+    return m_bestSize;
 }
 
 //---------------------------------------------------------------------------
-// wxAMMediaBackend::NotifyWndProc
+// wxAMMediaBackend::Move
 //
-// Here we check to see if DirectShow tells us we've reached the stop
-// position in our stream - if it has, it may not actually stop
-// the stream - which we need to do...
+// We take care of this in our redrawing
 //---------------------------------------------------------------------------
-LRESULT CALLBACK wxAMMediaBackend::NotifyWndProc(HWND hWnd, UINT nMsg,
-                                                    WPARAM wParam,
-                                                    LPARAM lParam)
+void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
+                            int w, int h)
 {
-    wxAMMediaBackend* backend = (wxAMMediaBackend*)
-        ::GetWindowLong(hWnd, GWL_USERDATA);
+    //don't use deferred positioning on windows
+    if(m_pVMC && m_bVideo)
+    {
+        RECT srcRect, destRect;
 
-    return backend->OnNotifyWndProc(hWnd, nMsg, wParam, lParam);
+        //portion of video to display in window
+        srcRect.top = 0; srcRect.left = 0;
+        srcRect.bottom = m_bestSize.y; srcRect.right = m_bestSize.x;
+
+        //it happens.
+        if (w < 0)
+        {
+            w = 0;
+        }
+        if (h < 0)
+        {
+            h = 0;
+        }
+
+        //position in window client coordinates to display and stretch to
+        destRect.top = 0; destRect.left = 0;
+        destRect.bottom = h; destRect.right = w;
+
+        //set the windowless control positions
+        HRESULT hr = m_pVMC->SetVideoPosition(&srcRect, &destRect);
+        if(FAILED(hr))
+        {
+            wxAMLOG(hr);
+        }
+    }
 }
 
-LRESULT CALLBACK wxAMMediaBackend::OnNotifyWndProc(HWND hWnd, UINT nMsg,
-                                                    WPARAM wParam,
-                                                    LPARAM lParam)
+//---------------------------------------------------------------------------
+// wxAMMediaThread::Entry
+//
+// Render the current movie frame
+//---------------------------------------------------------------------------
+wxThread::ExitCode wxAMMediaThread::Entry()
 {
-    if (nMsg == WM_GRAPHNOTIFY)
+    while(!TestDestroy())
     {
         LONG    evCode,
                 evParam1,
@@ -668,100 +1629,87 @@ LRESULT CALLBACK wxAMMediaBackend::OnNotifyWndProc(HWND hWnd, UINT nMsg,
         // to go through them one by one, stopping at (Hopefully only one)
         // EC_COMPLETE message
         //
-        while(SUCCEEDED(m_pME->GetEvent(&evCode, (LONG_PTR *) &evParam1,
-                                       (LONG_PTR *) &evParam2, 0)
-                       )
-             )
+        while( pThis->m_pME->GetEvent(&evCode, (LONG_PTR *) &evParam1,
+                                      (LONG_PTR *) &evParam2, 0) == 0 )
         {
             // Cleanup memory that GetEvent allocated
-            wxAMVERIFY( m_pME->FreeEventParams(evCode, evParam1, evParam2) );
-
+            HRESULT hr = pThis->m_pME->FreeEventParams(evCode,
+                                                evParam1, evParam2);
+            if(hr != 0)
+            {
+                //Even though this makes a messagebox this
+                //is windows where we can do gui stuff in seperate
+                //threads :)
+                wxFAIL_MSG(pThis->GetErrorString(hr));
+            }
             // If this is the end of the clip, notify handler
-            if(EC_COMPLETE == evCode)
+            else if(1 == evCode) //EC_COMPLETE
             {
-                //send the event to our child
-                wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId());
-                m_ctrl->ProcessEvent(theEvent);
-
-                //if the user didn't veto it, stop the stream
-                if (theEvent.IsAllowed())
-                {
-                    //Interestingly enough, DirectShow does not actually stop
-                    //the filters - even when it reaches the end!
-                    wxVERIFY( Stop() );
-
-                    //send the event to our child
-                    wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
-                                          m_ctrl->GetId());
-                    m_ctrl->ProcessEvent(theEvent);
-                }
+                pThis->OnStop();
             }
         }
-    }
-    return DefWindowProc(hWnd, nMsg, wParam, lParam);
-}
 
-//---------------------------------------------------------------------------
-// wxAMMediaBackend::Cleanup
-//
-// 1) Hide/disowns the video window (MS says bad things will happen if
-//    you don't)
-// 2) Releases all the directshow interfaces we use
-// TODO: Maybe there's a way to redirect the IGraphBuilder each time
-//       we load, rather then creating and destroying the interfaces
-//       each time?
-//---------------------------------------------------------------------------
-void wxAMMediaBackend::Cleanup()
-{
-    // Hide then disown the window
-    if(m_pVW)
-    {
-        m_pVW->put_Visible(OAFALSE); //OSFALSE == 0
-        m_pVW->put_Owner(NULL);
+        Sleep(10);
     }
 
-    // Release and zero DirectShow interfaces
-    SAFE_RELEASE(m_pME);
-    SAFE_RELEASE(m_pMS);
-    SAFE_RELEASE(m_pMC);
-    SAFE_RELEASE(m_pBA);
-    SAFE_RELEASE(m_pBV);
-    SAFE_RELEASE(m_pVW);
-    SAFE_RELEASE(m_pGB);
-
-    // Get rid of our hidden Window
-    DestroyWindow(m_hNotifyWnd);
-    m_hNotifyWnd = NULL;
+    return NULL;
 }
 
 
 //---------------------------------------------------------------------------
-// wxAMMediaBackend::GetVideoSize
+// wxAMMediaBackend::OnStop
 //
-// Obtains the cached original video size
+// Handle stopping when the stream ends
 //---------------------------------------------------------------------------
-wxSize wxAMMediaBackend::GetVideoSize() const
+void wxAMMediaBackend::OnStop()
 {
-    return m_bestSize;
+    //send the event to our child
+    wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId());
+    m_ctrl->ProcessEvent(theEvent);
+
+    //if the user didn't veto it, stop the stream
+    if (theEvent.IsAllowed())
+    {
+        //Interestingly enough, DirectShow does not actually stop
+        //the filters - even when it reaches the end!
+        wxVERIFY( Stop() );
+
+        //send the event to our child
+        wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
+                              m_ctrl->GetId());
+        m_ctrl->ProcessEvent(theEvent);
+    }
 }
 
 //---------------------------------------------------------------------------
-// wxAMMediaBackend::Move
+// wxAMMediaEvtHandler::OnEraseBackground
 //
-// Resizes the IVideoWindow to the size of the control window
+// Tell WX not to erase the background of our control window
 //---------------------------------------------------------------------------
-void wxAMMediaBackend::Move(int x, int y, int w, int h)
+void wxAMMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
 {
-    if(m_hNotifyWnd && m_bVideo)
+    wxAMMediaBackend* pThis = (wxAMMediaBackend*) this;
+    if(pThis->m_pVMC && pThis->m_bVideo)
     {
-        wxAMVERIFY( m_pVW->SetWindowPosition(0, 0, w, h) );
+        //TODO: Use wxClientDC?
+        HDC hdc = ::GetDC((HWND)pThis->m_ctrl->GetHandle());
+        HRESULT hr = pThis->m_pVMC->RepaintVideo((HWND)pThis->m_ctrl->GetHandle(),
+                                        hdc);
+        if(FAILED(hr))
+        {
+            wxFAIL_MSG(pThis->GetErrorString(hr));
+        }
+        ::ReleaseDC((HWND)pThis->m_ctrl->GetHandle(), hdc);
+    }
+    else
+    {
+        evt.Skip();
     }
 }
 
 //---------------------------------------------------------------------------
 // End of wxAMMediaBackend
 //---------------------------------------------------------------------------
-#endif //wxUSE_DIRECTSHOW
 
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 //
@@ -769,7 +1717,6 @@ void wxAMMediaBackend::Move(int x, int y, int w, int h)
 //
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-
 IMPLEMENT_DYNAMIC_CLASS(wxMCIMediaBackend, wxMediaBackend);
 
 //---------------------------------------------------------------------------
@@ -830,6 +1777,15 @@ typedef struct {
     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
 //
@@ -966,23 +1922,21 @@ bool wxMCIMediaBackend::Load(const wxString& fileName)
         return false;
     }
 
-    ::SetWindowLong(m_hNotifyWnd, GWL_WNDPROC,
-                       (LONG)wxMCIMediaBackend::NotifyWndProc);
+    wxSetWindowProc(m_hNotifyWnd, wxMCIMediaBackend::NotifyWndProc);
 
     ::SetWindowLong(m_hNotifyWnd, GWL_USERDATA,
                        (LONG) this);
 
-    m_ctrl->Show(false);
-
     //
     //Here, if the parent of the control has a sizer - we
     //tell it to recalculate the size of this control since
-    //the user opened a seperate media file
+    //the user opened a separate media file
     //
     m_ctrl->InvalidateBestSize();
     m_ctrl->GetParent()->Layout();
     m_ctrl->GetParent()->Refresh();
     m_ctrl->GetParent()->Update();
+    m_ctrl->SetSize(m_ctrl->GetSize());
 
     return true;
 }
@@ -1080,7 +2034,13 @@ 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;
@@ -1114,6 +2074,48 @@ wxLongLong wxMCIMediaBackend::GetPosition()
     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
+                        0x00800000L | 0x01000000L, //MCI_DGV_SETAUDIO+(_ITEM | _VALUE)
+                       (DWORD)(LPSTR)&audioParms) != 0)
+        return false;
+    return true;
+}
+
 //---------------------------------------------------------------------------
 // wxMCIMediaBackend::GetDuration
 //
@@ -1142,14 +2144,19 @@ void wxMCIMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
     if (m_hNotifyWnd && m_bVideo)
     {
         MCI_DGV_RECT_PARMS putParms; //ifdefed MCI_DGV_PUT_PARMS
-        putParms.rc.top = 0;
-        putParms.rc.bottom = 0;
-        putParms.rc.right = w;
+        memset(&putParms, 0, sizeof(MCI_DGV_RECT_PARMS));
         putParms.rc.bottom = h;
+        putParms.rc.right = w;
 
-        wxMCIVERIFY( mciSendCommand(m_hDev, MCI_PUT,
+        //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) );
+        }
     }
 }
 
@@ -1213,7 +2220,11 @@ LRESULT CALLBACK wxMCIMediaBackend::NotifyWndProc(HWND hWnd, UINT nMsg,
                                                   LPARAM lParam)
 {
     wxMCIMediaBackend* backend = (wxMCIMediaBackend*)
+#ifdef _WIN32
         ::GetWindowLong(hWnd, GWL_USERDATA);
+#else
+        ::GetWindowLongPtr(hWnd, GWLP_USERDATA);
+#endif
     wxASSERT(backend);
 
     return backend->OnNotifyWndProc(hWnd, nMsg, wParam, lParam);
@@ -1253,8 +2264,6 @@ LRESULT CALLBACK wxMCIMediaBackend::OnNotifyWndProc(HWND hWnd, UINT nMsg,
 // TODO: Dynamically load from qtml.dll
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-#if wxUSE_QUICKTIME
-
 IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend);
 
 //Time between timer calls
@@ -1268,8 +2277,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend);
 class _wxQTTimer : public wxTimer
 {
 public:
-    _wxQTTimer(Movie movie, wxQTMediaBackend* parent) :
-        m_movie(movie), m_bPaused(false), m_parent(parent)
+    _wxQTTimer(Movie movie, wxQTMediaBackend* parent, wxQuickTimeLibrary* pLib) :
+        m_movie(movie), m_bPaused(false), m_parent(parent), m_pLib(pLib)
     {
     }
 
@@ -1292,8 +2301,8 @@ public:
     {
         if (!m_bPaused)
         {
-            if(!IsMovieDone(m_movie))
-                MoviesTask(m_movie, MOVIE_DELAY);
+            if(!m_pLib->IsMovieDone(m_movie))
+                m_pLib->MoviesTask(m_movie, MOVIE_DELAY);
             else
             {
                 wxMediaEvent theEvent(wxEVT_MEDIA_STOP,
@@ -1304,7 +2313,7 @@ public:
                 {
                     Stop();
                     m_parent->Stop();
-                    wxASSERT(::GetMoviesError() == noErr);
+                    wxASSERT(m_pLib->GetMoviesError() == noErr);
 
                     //send the event to our child
                     wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
@@ -1319,6 +2328,7 @@ protected:
     Movie m_movie;                  //Our movie instance
     bool m_bPaused;                 //Whether we are paused or not
     wxQTMediaBackend* m_parent;     //Backend pointer
+    wxQuickTimeLibrary* m_pLib;         //Interfaces
 };
 
 //---------------------------------------------------------------------------
@@ -1344,10 +2354,13 @@ wxQTMediaBackend::~wxQTMediaBackend()
     if(m_timer)
         Cleanup();
 
-    //Note that ExitMovies() is not neccessary, but
-    //the docs are fuzzy on whether or not TerminateQTML is
-    ExitMovies();
-    TerminateQTML();
+    if(m_lib.IsOk())
+    {
+        //Note that ExitMovies() is not necessary, but
+        //the docs are fuzzy on whether or not TerminateQTML is
+        m_lib.ExitMovies();
+        m_lib.TerminateQTML();
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -1364,13 +2377,16 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
                                      const wxValidator& validator,
                                      const wxString& name)
 {
-    int nError;
-    if ((nError = InitializeQTML(0)) != noErr)    //-2093 no dll
+    if(!m_lib.Initialize())
+        return false;
+
+    int nError = m_lib.InitializeQTML(0);
+    if (nError != noErr)    //-2093 no dll
     {
         wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError));
         return false;
     }
-    EnterMovies();
+    m_lib.EnterMovies();
 
     //
     // Create window
@@ -1402,36 +2418,36 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
     if(m_timer)
         Cleanup();
 
-    OSErr err = noErr;
-    short movieResFile;
+    short movieResFile = 0; //= 0 because of annoying VC6 warning
     FSSpec sfFile;
 
-    if (NativePathNameToFSSpec ((char*) (const char*) fileName.mb_str(),
+    if (m_lib.NativePathNameToFSSpec ((char*) (const char*) fileName.mb_str(),
                                 &sfFile, 0) != noErr)
         return false;
 
-    if (OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr)
+    if (m_lib.OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr)
         return false;
 
     short movieResID = 0;
     Str255 movieName;
 
-    err = NewMovieFromFile (
-    &m_movie,
-    movieResFile,
-    &movieResID,
-    movieName,
-    newMovieActive,
-    NULL); //wasChanged
+    OSErr err = m_lib.NewMovieFromFile (
+                   &m_movie,
+                   movieResFile,
+                   &movieResID,
+                   movieName,
+                   newMovieActive,
+                   NULL
+                ); //wasChanged
 
-    CloseMovieFile (movieResFile);
+    m_lib.CloseMovieFile (movieResFile);
 
     if (err != noErr)
         return false;
 
     FinishLoad();
 
-    return ::GetMoviesError() == noErr;
+    return m_lib.GetMoviesError() == noErr;
 }
 
 //---------------------------------------------------------------------------
@@ -1446,36 +2462,36 @@ bool wxQTMediaBackend::Load(const wxURI& location)
 
     wxString theURI = location.BuildURI();
 
-    OSErr err = noErr;
-
-    Handle theHandle = NewHandleClear(theURI.length() + 1);
+    Handle theHandle = m_lib.NewHandleClear(theURI.length() + 1);
     wxASSERT(theHandle);
 
-    BlockMove(theURI.mb_str(), *theHandle, theURI.length() + 1);
+    m_lib.BlockMove(theURI.mb_str(), *theHandle, theURI.length() + 1);
 
     //create the movie from the handle that refers to the URI
-    err = NewMovieFromDataRef(&m_movie, newMovieActive,
+    OSErr err = m_lib.NewMovieFromDataRef(&m_movie, newMovieActive,
                                 NULL, theHandle,
                                 URLDataHandlerSubType);
 
-    DisposeHandle(theHandle);
+    m_lib.DisposeHandle(theHandle);
 
     if (err != noErr)
         return false;
 
     //preroll movie for streaming
     //TODO:Async this?
-    TimeValue timeNow;
+ /*
+     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);
+    m_lib.SetMovieRate(m_movie, playRate);
+*/
 
     FinishLoad();
 
-    return ::GetMoviesError() == noErr;
+    return m_lib.GetMoviesError() == noErr;
 }
 
 //---------------------------------------------------------------------------
@@ -1485,38 +2501,40 @@ bool wxQTMediaBackend::Load(const wxURI& location)
 //---------------------------------------------------------------------------
 void wxQTMediaBackend::FinishLoad()
 {
-    m_timer = new _wxQTTimer(m_movie, (wxQTMediaBackend*) this);
+    m_timer = new _wxQTTimer(m_movie, (wxQTMediaBackend*) this, &m_lib);
     wxASSERT(m_timer);
 
     //get the real size of the movie
     Rect outRect;
-    ::GetMovieNaturalBoundsRect (m_movie, &outRect);
-    wxASSERT(::GetMoviesError() == noErr);
+    memset(&outRect, 0, sizeof(Rect)); //for annoying VC6 warning
+    m_lib.GetMovieNaturalBoundsRect (m_movie, &outRect);
+    wxASSERT(m_lib.GetMoviesError() == noErr);
 
     m_bestSize.x = outRect.right - outRect.left;
     m_bestSize.y = outRect.bottom - outRect.top;
 
     //reparent movie/*AudioMediaCharacteristic*/
-    if(GetMovieIndTrackType(m_movie, 1,
+    if(m_lib.GetMovieIndTrackType(m_movie, 1,
                             VisualMediaCharacteristic,
-                            movieTrackCharacteristic |
-                                movieTrackEnabledOnly) != NULL)
+                            (1 << 1) //movieTrackCharacteristic
+                            | (1 << 2) //movieTrackEnabledOnly
+                            ) != NULL)
     {
-        CreatePortAssociation(m_ctrl->GetHWND(), NULL, 0L);
+        m_lib.CreatePortAssociation(m_ctrl->GetHWND(), NULL, 0L);
 
-        SetMovieGWorld(m_movie,
-                       (CGrafPtr) GetNativeWindowPort(m_ctrl->GetHWND()),
-                       nil);
+        m_lib.SetMovieGWorld(m_movie,
+                       (CGrafPtr) m_lib.GetNativeWindowPort(m_ctrl->GetHWND()),
+                       NULL);
     }
 
     //we want millisecond precision
-    ::SetMovieTimeScale(m_movie, 1000);
-    wxASSERT(::GetMoviesError() == noErr);
+    m_lib.SetMovieTimeScale(m_movie, 1000);
+    wxASSERT(m_lib.GetMoviesError() == noErr);
 
     //
     //Here, if the parent of the control has a sizer - we
     //tell it to recalculate the size of this control since
-    //the user opened a seperate media file
+    //the user opened a separate media file
     //
     m_ctrl->InvalidateBestSize();
     m_ctrl->GetParent()->Layout();
@@ -1531,10 +2549,10 @@ void wxQTMediaBackend::FinishLoad()
 //---------------------------------------------------------------------------
 bool wxQTMediaBackend::Play()
 {
-    ::StartMovie(m_movie);
+    m_lib.StartMovie(m_movie);
     m_timer->SetPaused(false);
     m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
-    return ::GetMoviesError() == noErr;
+    return m_lib.GetMoviesError() == noErr;
 }
 
 //---------------------------------------------------------------------------
@@ -1544,10 +2562,10 @@ bool wxQTMediaBackend::Play()
 //---------------------------------------------------------------------------
 bool wxQTMediaBackend::Pause()
 {
-    ::StopMovie(m_movie);
+    m_lib.StopMovie(m_movie);
     m_timer->SetPaused(true);
     m_timer->Stop();
-    return ::GetMoviesError() == noErr;
+    return m_lib.GetMoviesError() == noErr;
 }
 
 //---------------------------------------------------------------------------
@@ -1560,12 +2578,12 @@ bool wxQTMediaBackend::Stop()
     m_timer->SetPaused(false);
     m_timer->Stop();
 
-    ::StopMovie(m_movie);
-    if(::GetMoviesError() != noErr)
+    m_lib.StopMovie(m_movie);
+    if(m_lib.GetMoviesError() != noErr)
         return false;
 
-    ::GoToBeginningOfMovie(m_movie);
-    return ::GetMoviesError() == noErr;
+    m_lib.GoToBeginningOfMovie(m_movie);
+    return m_lib.GetMoviesError() == noErr;
 }
 
 //---------------------------------------------------------------------------
@@ -1575,7 +2593,7 @@ bool wxQTMediaBackend::Stop()
 //---------------------------------------------------------------------------
 double wxQTMediaBackend::GetPlaybackRate()
 {
-    return ( ((double)::GetMovieRate(m_movie)) / 0x10000);
+    return ( ((double)m_lib.GetMovieRate(m_movie)) / 0x10000);
 }
 
 //---------------------------------------------------------------------------
@@ -1585,8 +2603,8 @@ double wxQTMediaBackend::GetPlaybackRate()
 //---------------------------------------------------------------------------
 bool wxQTMediaBackend::SetPlaybackRate(double dRate)
 {
-    ::SetMovieRate(m_movie, (Fixed) (dRate * 0x10000));
-    return ::GetMoviesError() == noErr;
+    m_lib.SetMovieRate(m_movie, (Fixed) (dRate * 0x10000));
+    return m_lib.GetMoviesError() == noErr;
 }
 
 //---------------------------------------------------------------------------
@@ -1598,12 +2616,12 @@ bool wxQTMediaBackend::SetPosition(wxLongLong where)
 {
     TimeRecord theTimeRecord;
     memset(&theTimeRecord, 0, sizeof(TimeRecord));
-    theTimeRecord.value.lo = where.GetValue();
-    theTimeRecord.scale = ::GetMovieTimeScale(m_movie);
-    theTimeRecord.base = ::GetMovieTimeBase(m_movie);
-    ::SetMovieTime(m_movie, &theTimeRecord);
+    theTimeRecord.value.lo = where.GetLo();
+    theTimeRecord.scale = m_lib.GetMovieTimeScale(m_movie);
+    theTimeRecord.base = m_lib.GetMovieTimeBase(m_movie);
+    m_lib.SetMovieTime(m_movie, &theTimeRecord);
 
-    if (::GetMoviesError() != noErr)
+    if (m_lib.GetMoviesError() != noErr)
         return false;
 
     return true;
@@ -1613,11 +2631,58 @@ bool wxQTMediaBackend::SetPosition(wxLongLong where)
 // wxQTMediaBackend::GetPosition
 //
 // 1) Calls GetMovieTime to get the position we are in in the movie
-// in milliseconds (we called 
+// in milliseconds (we called
 //---------------------------------------------------------------------------
 wxLongLong wxQTMediaBackend::GetPosition()
 {
-    return ::GetMovieTime(m_movie, NULL);
+    return m_lib.GetMovieTime(m_movie, NULL);
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::GetVolume
+//
+// Gets the volume through GetMovieVolume - which returns a 16 bit short -
+//
+// +--------+--------+
+// +   (1)  +   (2)  +
+// +--------+--------+
+//
+// (1) first 8 bits are value before decimal
+// (2) second 8 bits are value after decimal
+//
+// Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
+// 1 (full gain and sound)
+//---------------------------------------------------------------------------
+double wxQTMediaBackend::GetVolume()
+{
+    short sVolume = m_lib.GetMovieVolume(m_movie);
+
+    if(sVolume & (128 << 8)) //negative - no sound
+        return 0.0;
+
+    return (sVolume & (127 << 8)) ? 1.0 : ((double)(sVolume & 255)) / 255.0;
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::SetVolume
+//
+// Sets the volume through SetMovieVolume - which takes a 16 bit short -
+//
+// +--------+--------+
+// +   (1)  +   (2)  +
+// +--------+--------+
+//
+// (1) first 8 bits are value before decimal
+// (2) second 8 bits are value after decimal
+//
+// Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
+// 1 (full gain and sound)
+//---------------------------------------------------------------------------
+bool wxQTMediaBackend::SetVolume(double dVolume)
+{
+    short sVolume = (short) (dVolume >= .9999 ? 1 << 8 : (dVolume * 255) );
+    m_lib.SetMovieVolume(m_movie, sVolume);
+    return true;
 }
 
 //---------------------------------------------------------------------------
@@ -1627,7 +2692,7 @@ wxLongLong wxQTMediaBackend::GetPosition()
 //---------------------------------------------------------------------------
 wxLongLong wxQTMediaBackend::GetDuration()
 {
-    return ::GetMovieDuration(m_movie);
+    return m_lib.GetMovieDuration(m_movie);
 }
 
 //---------------------------------------------------------------------------
@@ -1657,8 +2722,8 @@ void wxQTMediaBackend::Cleanup()
     delete m_timer;
     m_timer = NULL;
 
-    StopMovie(m_movie);
-    DisposeMovie(m_movie);
+    m_lib.StopMovie(m_movie);
+    m_lib.DisposeMovie(m_movie);
 }
 
 //---------------------------------------------------------------------------
@@ -1676,21 +2741,20 @@ wxSize wxQTMediaBackend::GetVideoSize() const
 //
 // TODO
 //---------------------------------------------------------------------------
-void wxQTMediaBackend::Move(int x, int y, int w, int h)
+void wxQTMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), int w, int h)
 {
     if(m_timer)
     {
-        Rect theRect = {0, 0, h, w};
+        Rect theRect = {0, 0, (short)h, (short)w};
 
-        ::SetMovieBox(m_movie, &theRect);
-        wxASSERT(::GetMoviesError() == noErr);
+        m_lib.SetMovieBox(m_movie, &theRect);
+        wxASSERT(m_lib.GetMoviesError() == noErr);
     }
 }
 
 //---------------------------------------------------------------------------
-//  End QT Compilation Guard
+//  End QT Backend
 //---------------------------------------------------------------------------
-#endif //wxUSE_QUICKTIME
 
 //in source file that contains stuff you don't directly use
 #include <wx/html/forcelnk.h>