mediactrl.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/mediactrl.h
  3. // Purpose: wxMediaCtrl class
  4. // Author: Ryan Norton <wxprojects@comcast.net>
  5. // Modified by:
  6. // Created: 11/07/04
  7. // Copyright: (c) Ryan Norton
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // Definitions
  12. // ============================================================================
  13. // ----------------------------------------------------------------------------
  14. // Header guard
  15. // ----------------------------------------------------------------------------
  16. #ifndef _WX_MEDIACTRL_H_
  17. #define _WX_MEDIACTRL_H_
  18. // ----------------------------------------------------------------------------
  19. // Pre-compiled header stuff
  20. // ----------------------------------------------------------------------------
  21. #include "wx/defs.h"
  22. // ----------------------------------------------------------------------------
  23. // Compilation guard
  24. // ----------------------------------------------------------------------------
  25. #if wxUSE_MEDIACTRL
  26. // ----------------------------------------------------------------------------
  27. // Includes
  28. // ----------------------------------------------------------------------------
  29. #include "wx/control.h"
  30. #include "wx/uri.h"
  31. // ============================================================================
  32. // Declarations
  33. // ============================================================================
  34. // ----------------------------------------------------------------------------
  35. //
  36. // Enumerations
  37. //
  38. // ----------------------------------------------------------------------------
  39. enum wxMediaState
  40. {
  41. wxMEDIASTATE_STOPPED,
  42. wxMEDIASTATE_PAUSED,
  43. wxMEDIASTATE_PLAYING
  44. };
  45. enum wxMediaCtrlPlayerControls
  46. {
  47. wxMEDIACTRLPLAYERCONTROLS_NONE = 0,
  48. //Step controls like fastforward, step one frame etc.
  49. wxMEDIACTRLPLAYERCONTROLS_STEP = 1 << 0,
  50. //Volume controls like the speaker icon, volume slider, etc.
  51. wxMEDIACTRLPLAYERCONTROLS_VOLUME = 1 << 1,
  52. wxMEDIACTRLPLAYERCONTROLS_DEFAULT =
  53. wxMEDIACTRLPLAYERCONTROLS_STEP |
  54. wxMEDIACTRLPLAYERCONTROLS_VOLUME
  55. };
  56. #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
  57. #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
  58. #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
  59. #define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
  60. #define wxMEDIABACKEND_REALPLAYER wxT("wxRealPlayerMediaBackend")
  61. #define wxMEDIABACKEND_WMP10 wxT("wxWMP10MediaBackend")
  62. // ----------------------------------------------------------------------------
  63. //
  64. // wxMediaEvent
  65. //
  66. // ----------------------------------------------------------------------------
  67. class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent
  68. {
  69. public:
  70. // ------------------------------------------------------------------------
  71. // wxMediaEvent Constructor
  72. //
  73. // Normal constructor, much the same as wxNotifyEvent
  74. // ------------------------------------------------------------------------
  75. wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
  76. : wxNotifyEvent(commandType, winid)
  77. { }
  78. // ------------------------------------------------------------------------
  79. // wxMediaEvent Copy Constructor
  80. //
  81. // Normal copy constructor, much the same as wxNotifyEvent
  82. // ------------------------------------------------------------------------
  83. wxMediaEvent(const wxMediaEvent &clone)
  84. : wxNotifyEvent(clone)
  85. { }
  86. // ------------------------------------------------------------------------
  87. // wxMediaEvent::Clone
  88. //
  89. // Allocates a copy of this object.
  90. // Required for wxEvtHandler::AddPendingEvent
  91. // ------------------------------------------------------------------------
  92. virtual wxEvent *Clone() const
  93. { return new wxMediaEvent(*this); }
  94. // Put this class on wxWidget's RTTI table
  95. DECLARE_DYNAMIC_CLASS(wxMediaEvent)
  96. };
  97. // ----------------------------------------------------------------------------
  98. //
  99. // wxMediaCtrl
  100. //
  101. // ----------------------------------------------------------------------------
  102. class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl
  103. {
  104. public:
  105. wxMediaCtrl() : m_imp(NULL), m_bLoaded(false)
  106. { }
  107. wxMediaCtrl(wxWindow* parent, wxWindowID winid,
  108. const wxString& fileName = wxEmptyString,
  109. const wxPoint& pos = wxDefaultPosition,
  110. const wxSize& size = wxDefaultSize,
  111. long style = 0,
  112. const wxString& szBackend = wxEmptyString,
  113. const wxValidator& validator = wxDefaultValidator,
  114. const wxString& name = wxT("mediaCtrl"))
  115. : m_imp(NULL), m_bLoaded(false)
  116. { Create(parent, winid, fileName, pos, size, style,
  117. szBackend, validator, name); }
  118. wxMediaCtrl(wxWindow* parent, wxWindowID winid,
  119. const wxURI& location,
  120. const wxPoint& pos = wxDefaultPosition,
  121. const wxSize& size = wxDefaultSize,
  122. long style = 0,
  123. const wxString& szBackend = wxEmptyString,
  124. const wxValidator& validator = wxDefaultValidator,
  125. const wxString& name = wxT("mediaCtrl"))
  126. : m_imp(NULL), m_bLoaded(false)
  127. { Create(parent, winid, location, pos, size, style,
  128. szBackend, validator, name); }
  129. virtual ~wxMediaCtrl();
  130. bool Create(wxWindow* parent, wxWindowID winid,
  131. const wxString& fileName = wxEmptyString,
  132. const wxPoint& pos = wxDefaultPosition,
  133. const wxSize& size = wxDefaultSize,
  134. long style = 0,
  135. const wxString& szBackend = wxEmptyString,
  136. const wxValidator& validator = wxDefaultValidator,
  137. const wxString& name = wxT("mediaCtrl"));
  138. bool Create(wxWindow* parent, wxWindowID winid,
  139. const wxURI& location,
  140. const wxPoint& pos = wxDefaultPosition,
  141. const wxSize& size = wxDefaultSize,
  142. long style = 0,
  143. const wxString& szBackend = wxEmptyString,
  144. const wxValidator& validator = wxDefaultValidator,
  145. const wxString& name = wxT("mediaCtrl"));
  146. bool DoCreate(const wxClassInfo* instance,
  147. wxWindow* parent, wxWindowID winid,
  148. const wxPoint& pos = wxDefaultPosition,
  149. const wxSize& size = wxDefaultSize,
  150. long style = 0,
  151. const wxValidator& validator = wxDefaultValidator,
  152. const wxString& name = wxT("mediaCtrl"));
  153. bool Play();
  154. bool Pause();
  155. bool Stop();
  156. bool Load(const wxString& fileName);
  157. wxMediaState GetState();
  158. wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart);
  159. wxFileOffset Tell(); //FIXME: This should be const
  160. wxFileOffset Length(); //FIXME: This should be const
  161. double GetPlaybackRate(); //All but MCI & GStreamer
  162. bool SetPlaybackRate(double dRate); //All but MCI & GStreamer
  163. bool Load(const wxURI& location);
  164. bool Load(const wxURI& location, const wxURI& proxy);
  165. wxFileOffset GetDownloadProgress(); // DirectShow only
  166. wxFileOffset GetDownloadTotal(); // DirectShow only
  167. double GetVolume();
  168. bool SetVolume(double dVolume);
  169. bool ShowPlayerControls(
  170. wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT);
  171. //helpers for the wxPython people
  172. bool LoadURI(const wxString& fileName)
  173. { return Load(wxURI(fileName)); }
  174. bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy)
  175. { return Load(wxURI(fileName), wxURI(proxy)); }
  176. protected:
  177. static const wxClassInfo* NextBackend(wxClassInfo::const_iterator* it);
  178. void OnMediaFinished(wxMediaEvent& evt);
  179. virtual void DoMoveWindow(int x, int y, int w, int h);
  180. wxSize DoGetBestSize() const;
  181. //FIXME: This is nasty... find a better way to work around
  182. //inheritance issues
  183. #if defined(__WXOSX_CARBON__)
  184. virtual void MacVisibilityChanged();
  185. #endif
  186. #if defined(__WXOSX_CARBON__) || defined(__WXCOCOA__)
  187. friend class wxQTMediaBackend;
  188. #endif
  189. class wxMediaBackend* m_imp;
  190. bool m_bLoaded;
  191. DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
  192. };
  193. // ----------------------------------------------------------------------------
  194. //
  195. // wxMediaBackend
  196. //
  197. // Derive from this and use standard wxWidgets RTTI
  198. // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
  199. // for wxMediaCtrl. Backends are searched alphabetically -
  200. // the one with the earliest letter is tried first.
  201. //
  202. // Note that this is currently not API or ABI compatible -
  203. // so statically link or make the client compile on-site.
  204. //
  205. // ----------------------------------------------------------------------------
  206. class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject
  207. {
  208. public:
  209. wxMediaBackend()
  210. { }
  211. virtual ~wxMediaBackend();
  212. virtual bool CreateControl(wxControl* WXUNUSED(ctrl),
  213. wxWindow* WXUNUSED(parent),
  214. wxWindowID WXUNUSED(winid),
  215. const wxPoint& WXUNUSED(pos),
  216. const wxSize& WXUNUSED(size),
  217. long WXUNUSED(style),
  218. const wxValidator& WXUNUSED(validator),
  219. const wxString& WXUNUSED(name))
  220. { return false; }
  221. virtual bool Play()
  222. { return false; }
  223. virtual bool Pause()
  224. { return false; }
  225. virtual bool Stop()
  226. { return false; }
  227. virtual bool Load(const wxString& WXUNUSED(fileName))
  228. { return false; }
  229. virtual bool Load(const wxURI& WXUNUSED(location))
  230. { return false; }
  231. virtual bool SetPosition(wxLongLong WXUNUSED(where))
  232. { return 0; }
  233. virtual wxLongLong GetPosition()
  234. { return 0; }
  235. virtual wxLongLong GetDuration()
  236. { return 0; }
  237. virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
  238. int WXUNUSED(w), int WXUNUSED(h))
  239. { }
  240. virtual wxSize GetVideoSize() const
  241. { return wxSize(0,0); }
  242. virtual double GetPlaybackRate()
  243. { return 0.0; }
  244. virtual bool SetPlaybackRate(double WXUNUSED(dRate))
  245. { return false; }
  246. virtual wxMediaState GetState()
  247. { return wxMEDIASTATE_STOPPED; }
  248. virtual double GetVolume()
  249. { return 0.0; }
  250. virtual bool SetVolume(double WXUNUSED(dVolume))
  251. { return false; }
  252. virtual bool Load(const wxURI& WXUNUSED(location),
  253. const wxURI& WXUNUSED(proxy))
  254. { return false; }
  255. virtual bool ShowPlayerControls(
  256. wxMediaCtrlPlayerControls WXUNUSED(flags))
  257. { return false; }
  258. virtual bool IsInterfaceShown()
  259. { return false; }
  260. virtual wxLongLong GetDownloadProgress()
  261. { return 0; }
  262. virtual wxLongLong GetDownloadTotal()
  263. { return 0; }
  264. virtual void MacVisibilityChanged()
  265. { }
  266. virtual void RESERVED9() {}
  267. DECLARE_DYNAMIC_CLASS(wxMediaBackend)
  268. };
  269. //Our events
  270. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMediaEvent );
  271. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMediaEvent );
  272. //Function type(s) our events need
  273. typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
  274. #define wxMediaEventHandler(func) \
  275. wxEVENT_HANDLER_CAST(wxMediaEventFunction, func)
  276. //Macro for usage with message maps
  277. #define EVT_MEDIA_FINISHED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
  278. #define EVT_MEDIA_STOP(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
  279. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED, wxMediaEvent );
  280. #define EVT_MEDIA_LOADED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
  281. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STATECHANGED, wxMediaEvent );
  282. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PLAY, wxMediaEvent );
  283. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PAUSE, wxMediaEvent );
  284. #define EVT_MEDIA_STATECHANGED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
  285. #define EVT_MEDIA_PLAY(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
  286. #define EVT_MEDIA_PAUSE(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
  287. // ----------------------------------------------------------------------------
  288. // common backend base class used by many other backends
  289. // ----------------------------------------------------------------------------
  290. class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend
  291. {
  292. public:
  293. // add a pending wxMediaEvent of the given type
  294. void QueueEvent(wxEventType evtType);
  295. // notify that the movie playback is finished
  296. void QueueFinishEvent()
  297. {
  298. QueueEvent(wxEVT_MEDIA_STATECHANGED);
  299. QueueEvent(wxEVT_MEDIA_FINISHED);
  300. }
  301. // send the stop event and return true if it hasn't been vetoed
  302. bool SendStopEvent();
  303. // Queue pause event
  304. void QueuePlayEvent();
  305. // Queue pause event
  306. void QueuePauseEvent();
  307. // Queue stop event (no veto)
  308. void QueueStopEvent();
  309. protected:
  310. // call this when the movie size has changed but not because it has just
  311. // been loaded (in this case, call NotifyMovieLoaded() below)
  312. void NotifyMovieSizeChanged();
  313. // call this when the movie is fully loaded
  314. void NotifyMovieLoaded();
  315. wxMediaCtrl *m_ctrl; // parent control
  316. };
  317. // ----------------------------------------------------------------------------
  318. // End compilation guard
  319. // ----------------------------------------------------------------------------
  320. #endif // wxUSE_MEDIACTRL
  321. // ----------------------------------------------------------------------------
  322. // End header guard and header itself
  323. // ----------------------------------------------------------------------------
  324. #endif // _WX_MEDIACTRL_H_