1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        wx/mediactrl.h 
   3 // Purpose:     wxMediaCtrl class 
   4 // Author:      Ryan Norton <wxprojects@comcast.net> 
   8 // Copyright:   (c) Ryan Norton 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  19 #ifndef _WX_MEDIACTRL_H_ 
  20 #define _WX_MEDIACTRL_H_ 
  22 // ---------------------------------------------------------------------------- 
  23 // Pre-compiled header stuff 
  24 // ---------------------------------------------------------------------------- 
  28 // ---------------------------------------------------------------------------- 
  30 // ---------------------------------------------------------------------------- 
  34 // ---------------------------------------------------------------------------- 
  36 // ---------------------------------------------------------------------------- 
  38 #include "wx/control.h" 
  41 // ============================================================================ 
  43 // ============================================================================ 
  45 // ---------------------------------------------------------------------------- 
  49 // ---------------------------------------------------------------------------- 
  58 enum wxMediaCtrlPlayerControls
 
  60     wxMEDIACTRLPLAYERCONTROLS_NONE           
=   0, 
  61     //Step controls like fastfoward, step one frame etc. 
  62     wxMEDIACTRLPLAYERCONTROLS_STEP           
=   1 << 0, 
  63     //Volume controls like the speaker icon, volume slider, etc. 
  64     wxMEDIACTRLPLAYERCONTROLS_VOLUME         
=   1 << 1, 
  65     wxMEDIACTRLPLAYERCONTROLS_DEFAULT        
= 
  66                     wxMEDIACTRLPLAYERCONTROLS_STEP 
| 
  67                     wxMEDIACTRLPLAYERCONTROLS_VOLUME
 
  70 #define wxMEDIABACKEND_DIRECTSHOW   wxT("wxAMMediaBackend") 
  71 #define wxMEDIABACKEND_MCI          wxT("wxMCIMediaBackend") 
  72 #define wxMEDIABACKEND_QUICKTIME    wxT("wxQTMediaBackend") 
  73 #define wxMEDIABACKEND_GSTREAMER    wxT("wxGStreamerMediaBackend") 
  74 #define wxMEDIABACKEND_REALPLAYER   wxT("wxRealPlayerMediaBackend") 
  75 #define wxMEDIABACKEND_WMP10        wxT("wxWMP10MediaBackend") 
  77 // ---------------------------------------------------------------------------- 
  81 // ---------------------------------------------------------------------------- 
  83 class WXDLLIMPEXP_MEDIA wxMediaEvent 
: public wxNotifyEvent
 
  86     // ------------------------------------------------------------------------ 
  87     // wxMediaEvent Constructor 
  89     // Normal constructor, much the same as wxNotifyEvent 
  90     // ------------------------------------------------------------------------ 
  91     wxMediaEvent(wxEventType commandType 
= wxEVT_NULL
, int winid 
= 0) 
  92         : wxNotifyEvent(commandType
, winid
) 
  95     // ------------------------------------------------------------------------ 
  96     // wxMediaEvent Copy Constructor 
  98     // Normal copy constructor, much the same as wxNotifyEvent 
  99     // ------------------------------------------------------------------------ 
 100     wxMediaEvent(const wxMediaEvent 
&clone
) 
 101             : wxNotifyEvent(clone
) 
 104     // ------------------------------------------------------------------------ 
 105     // wxMediaEvent::Clone 
 107     // Allocates a copy of this object. 
 108     // Required for wxEvtHandler::AddPendingEvent 
 109     // ------------------------------------------------------------------------ 
 110     virtual wxEvent 
*Clone() const 
 111     {   return new wxMediaEvent(*this);     } 
 114     // Put this class on wxWidget's RTTI table 
 115     DECLARE_DYNAMIC_CLASS(wxMediaEvent
) 
 118 // ---------------------------------------------------------------------------- 
 122 // ---------------------------------------------------------------------------- 
 124 class WXDLLIMPEXP_MEDIA wxMediaCtrl 
: public wxControl
 
 127     wxMediaCtrl() : m_imp(NULL
), m_bLoaded(false) 
 130     wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
, 
 131                 const wxString
& fileName 
= wxEmptyString
, 
 132                 const wxPoint
& pos 
= wxDefaultPosition
, 
 133                 const wxSize
& size 
= wxDefaultSize
, 
 135                 const wxString
& szBackend 
= wxEmptyString
, 
 136                 const wxValidator
& validator 
= wxDefaultValidator
, 
 137                 const wxString
& name 
= wxT("mediaCtrl")) 
 138                 : m_imp(NULL
), m_bLoaded(false) 
 139     {   Create(parent
, winid
, fileName
, pos
, size
, style
, 
 140                szBackend
, validator
, name
);                             } 
 142     wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
, 
 143                 const wxURI
& location
, 
 144                 const wxPoint
& pos 
= wxDefaultPosition
, 
 145                 const wxSize
& size 
= wxDefaultSize
, 
 147                 const wxString
& szBackend 
= wxEmptyString
, 
 148                 const wxValidator
& validator 
= wxDefaultValidator
, 
 149                 const wxString
& name 
= wxT("mediaCtrl")) 
 150                 : m_imp(NULL
), m_bLoaded(false) 
 151     {   Create(parent
, winid
, location
, pos
, size
, style
, 
 152                szBackend
, validator
, name
);                             } 
 154     virtual ~wxMediaCtrl(); 
 156     bool Create(wxWindow
* parent
, wxWindowID winid
, 
 157                 const wxString
& fileName 
= wxEmptyString
, 
 158                 const wxPoint
& pos 
= wxDefaultPosition
, 
 159                 const wxSize
& size 
= wxDefaultSize
, 
 161                 const wxString
& szBackend 
= wxEmptyString
, 
 162                 const wxValidator
& validator 
= wxDefaultValidator
, 
 163                 const wxString
& name 
= wxT("mediaCtrl")); 
 165     bool Create(wxWindow
* parent
, wxWindowID winid
, 
 166                 const wxURI
& location
, 
 167                 const wxPoint
& pos 
= wxDefaultPosition
, 
 168                 const wxSize
& size 
= wxDefaultSize
, 
 170                 const wxString
& szBackend 
= wxEmptyString
, 
 171                 const wxValidator
& validator 
= wxDefaultValidator
, 
 172                 const wxString
& name 
= wxT("mediaCtrl")); 
 174     bool DoCreate(const wxClassInfo
* instance
, 
 175                 wxWindow
* parent
, wxWindowID winid
, 
 176                 const wxPoint
& pos 
= wxDefaultPosition
, 
 177                 const wxSize
& size 
= wxDefaultSize
, 
 179                 const wxValidator
& validator 
= wxDefaultValidator
, 
 180                 const wxString
& name 
= wxT("mediaCtrl")); 
 186     bool Load(const wxString
& fileName
); 
 188     wxMediaState 
GetState(); 
 190     wxFileOffset 
Seek(wxFileOffset where
, wxSeekMode mode 
= wxFromStart
); 
 191     wxFileOffset 
Tell(); //FIXME: This should be const 
 192     wxFileOffset 
Length(); //FIXME: This should be const 
 194     double GetPlaybackRate();           //All but MCI & GStreamer 
 195     bool SetPlaybackRate(double dRate
); //All but MCI & GStreamer 
 197     bool Load(const wxURI
& location
); 
 198     bool Load(const wxURI
& location
, const wxURI
& proxy
); 
 200     wxFileOffset 
GetDownloadProgress(); // DirectShow only 
 201     wxFileOffset 
GetDownloadTotal();    // DirectShow only 
 204     bool   SetVolume(double dVolume
); 
 206     bool    ShowPlayerControls( 
 207         wxMediaCtrlPlayerControls flags 
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
); 
 209     //helpers for the wxPython people 
 210     bool LoadURI(const wxString
& fileName
) 
 211     {   return Load(wxURI(fileName
));       } 
 212     bool LoadURIWithProxy(const wxString
& fileName
, const wxString
& proxy
) 
 213     {   return Load(wxURI(fileName
), wxURI(proxy
));       } 
 216     static const wxClassInfo
* NextBackend(wxClassInfo::const_iterator
* it
); 
 218     void OnMediaFinished(wxMediaEvent
& evt
); 
 219     virtual void DoMoveWindow(int x
, int y
, int w
, int h
); 
 220     wxSize 
DoGetBestSize() const; 
 222     //FIXME:  This is nasty... find a better way to work around 
 224 #if defined(__WXOSX_CARBON__) 
 225     virtual void MacVisibilityChanged(); 
 227 #if defined(__WXOSX_CARBON__) || defined(__WXCOCOA__) 
 228     friend class wxQTMediaBackend
; 
 230     class wxMediaBackend
* m_imp
; 
 233     DECLARE_DYNAMIC_CLASS(wxMediaCtrl
) 
 236 // ---------------------------------------------------------------------------- 
 240 // Derive from this and use standard wxWidgets RTTI 
 241 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend 
 242 // for wxMediaCtrl.  Backends are searched alphabetically - 
 243 // the one with the earliest letter is tried first. 
 245 // Note that this is currently not API or ABI compatable - 
 246 // so statically link or make the client compile on-site. 
 248 // ---------------------------------------------------------------------------- 
 250 class WXDLLIMPEXP_MEDIA wxMediaBackend 
: public wxObject
 
 256     virtual ~wxMediaBackend(); 
 258     virtual bool CreateControl(wxControl
* WXUNUSED(ctrl
), 
 259                                wxWindow
* WXUNUSED(parent
), 
 260                                wxWindowID 
WXUNUSED(winid
), 
 261                                const wxPoint
& WXUNUSED(pos
), 
 262                                const wxSize
& WXUNUSED(size
), 
 263                                long WXUNUSED(style
), 
 264                                const wxValidator
& WXUNUSED(validator
), 
 265                                const wxString
& WXUNUSED(name
)) 
 275     virtual bool Load(const wxString
& WXUNUSED(fileName
)) 
 277     virtual bool Load(const wxURI
& WXUNUSED(location
)) 
 280     virtual bool SetPosition(wxLongLong 
WXUNUSED(where
)) 
 282     virtual wxLongLong 
GetPosition() 
 284     virtual wxLongLong 
GetDuration() 
 287     virtual void Move(int WXUNUSED(x
), int WXUNUSED(y
), 
 288                       int WXUNUSED(w
), int WXUNUSED(h
)) 
 290     virtual wxSize 
GetVideoSize() const 
 291     {   return wxSize(0,0);             } 
 293     virtual double GetPlaybackRate() 
 295     virtual bool SetPlaybackRate(double WXUNUSED(dRate
)) 
 298     virtual wxMediaState 
GetState() 
 299     {   return wxMEDIASTATE_STOPPED
;    } 
 301     virtual double GetVolume() 
 303     virtual bool SetVolume(double WXUNUSED(dVolume
)) 
 306     virtual bool Load(const wxURI
& WXUNUSED(location
), 
 307                       const wxURI
& WXUNUSED(proxy
)) 
 310     virtual bool   ShowPlayerControls( 
 311                     wxMediaCtrlPlayerControls 
WXUNUSED(flags
)) 
 313     virtual bool   IsInterfaceShown() 
 316     virtual wxLongLong 
GetDownloadProgress() 
 318     virtual wxLongLong 
GetDownloadTotal() 
 321     virtual void MacVisibilityChanged() 
 323     virtual void RESERVED9() {} 
 325     DECLARE_DYNAMIC_CLASS(wxMediaBackend
) 
 330 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_FINISHED
, wxMediaEvent 
); 
 331 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STOP
, wxMediaEvent 
); 
 333 //Function type(s) our events need 
 334 typedef void (wxEvtHandler::*wxMediaEventFunction
)(wxMediaEvent
&); 
 336 #define wxMediaEventHandler(func) \ 
 337     wxEVENT_HANDLER_CAST(wxMediaEventFunction, func) 
 339 //Macro for usage with message maps 
 340 #define EVT_MEDIA_FINISHED(winid, fn)   wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ), 
 341 #define EVT_MEDIA_STOP(winid, fn)       wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ), 
 343 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_LOADED
, wxMediaEvent 
); 
 344 #define EVT_MEDIA_LOADED(winid, fn)     wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ), 
 346 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STATECHANGED
, wxMediaEvent 
); 
 347 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_PLAY
, wxMediaEvent 
); 
 348 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_PAUSE
, wxMediaEvent 
); 
 349 #define EVT_MEDIA_STATECHANGED(winid, fn)   wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ), 
 350 #define EVT_MEDIA_PLAY(winid, fn)           wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ), 
 351 #define EVT_MEDIA_PAUSE(winid, fn)          wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ), 
 353 // ---------------------------------------------------------------------------- 
 354 // common backend base class used by many other backends 
 355 // ---------------------------------------------------------------------------- 
 357 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase 
: public wxMediaBackend
 
 360     // add a pending wxMediaEvent of the given type 
 361     void QueueEvent(wxEventType evtType
); 
 363     // notify that the movie playback is finished 
 364     void QueueFinishEvent() 
 366         QueueEvent(wxEVT_MEDIA_STATECHANGED
); 
 367         QueueEvent(wxEVT_MEDIA_FINISHED
); 
 370     // send the stop event and return true if it hasn't been vetoed 
 371     bool SendStopEvent(); 
 374     void QueuePlayEvent(); 
 377     void QueuePauseEvent(); 
 379     // Queue stop event (no veto) 
 380     void QueueStopEvent(); 
 383     // call this when the movie size has changed but not because it has just 
 384     // been loaded (in this case, call NotifyMovieLoaded() below) 
 385     void NotifyMovieSizeChanged(); 
 387     // call this when the movie is fully loaded 
 388     void NotifyMovieLoaded(); 
 391     wxMediaCtrl 
*m_ctrl
;      // parent control 
 394 // ---------------------------------------------------------------------------- 
 395 // End compilation gaurd 
 396 // ---------------------------------------------------------------------------- 
 397 #endif // wxUSE_MEDIACTRL 
 399 // ---------------------------------------------------------------------------- 
 400 // End header guard and header itself 
 401 // ---------------------------------------------------------------------------- 
 402 #endif // _WX_MEDIACTRL_H_