]>
Commit | Line | Data |
---|---|---|
ff4aedc5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
1a680109 RN |
2 | // Name: wx/mediactrl.h |
3 | // Purpose: wxMediaCtrl class | |
4 | // Author: Ryan Norton <wxprojects@comcast.net> | |
226ec5a7 | 5 | // Modified by: |
1a680109 RN |
6 | // Created: 11/07/04 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Ryan Norton | |
9 | // Licence: wxWindows licence | |
ff4aedc5 | 10 | /////////////////////////////////////////////////////////////////////////////// |
1a680109 | 11 | |
ff4aedc5 RN |
12 | // ============================================================================ |
13 | // Definitions | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // Header guard | |
18 | // ---------------------------------------------------------------------------- | |
19 | #ifndef _WX_MEDIACTRL_H_ | |
20 | #define _WX_MEDIACTRL_H_ | |
21 | ||
22 | // ---------------------------------------------------------------------------- | |
23 | // Pre-compiled header stuff | |
24 | // ---------------------------------------------------------------------------- | |
72259e00 | 25 | |
2ecf902b WS |
26 | #include "wx/defs.h" |
27 | ||
ff4aedc5 RN |
28 | // ---------------------------------------------------------------------------- |
29 | // Compilation guard | |
30 | // ---------------------------------------------------------------------------- | |
2ecf902b | 31 | |
ff4aedc5 RN |
32 | #if wxUSE_MEDIACTRL |
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // Includes | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | #include "wx/control.h" | |
39 | #include "wx/uri.h" | |
40 | ||
41 | // ============================================================================ | |
42 | // Declarations | |
43 | // ============================================================================ | |
44 | ||
45 | // ---------------------------------------------------------------------------- | |
46 | // | |
47 | // Enumerations | |
48 | // | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | enum wxMediaState | |
52 | { | |
53 | wxMEDIASTATE_STOPPED, | |
54 | wxMEDIASTATE_PAUSED, | |
55 | wxMEDIASTATE_PLAYING | |
56 | }; | |
57 | ||
c5191fbd VZ |
58 | enum wxMediaCtrlPlayerControls |
59 | { | |
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 | |
68 | }; | |
69 | ||
ff4aedc5 RN |
70 | #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend") |
71 | #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend") | |
72 | #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend") | |
ce756cb0 | 73 | #define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend") |
557002cf VZ |
74 | #define wxMEDIABACKEND_REALPLAYER wxT("wxRealPlayerMediaBackend") |
75 | #define wxMEDIABACKEND_WMP10 wxT("wxWMP10MediaBackend") | |
c5191fbd | 76 | |
226ec5a7 WS |
77 | // ---------------------------------------------------------------------------- |
78 | // | |
79 | // wxMediaEvent | |
80 | // | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
ff2b312f | 83 | class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent |
226ec5a7 WS |
84 | { |
85 | public: | |
86 | // ------------------------------------------------------------------------ | |
87 | // wxMediaEvent Constructor | |
88 | // | |
89 | // Normal constructor, much the same as wxNotifyEvent | |
90 | // ------------------------------------------------------------------------ | |
4fc81cbc RN |
91 | wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) |
92 | : wxNotifyEvent(commandType, winid) | |
226ec5a7 WS |
93 | { } |
94 | ||
95 | // ------------------------------------------------------------------------ | |
96 | // wxMediaEvent Copy Constructor | |
97 | // | |
98 | // Normal copy constructor, much the same as wxNotifyEvent | |
99 | // ------------------------------------------------------------------------ | |
100 | wxMediaEvent(const wxMediaEvent &clone) | |
101 | : wxNotifyEvent(clone) | |
102 | { } | |
103 | ||
104 | // ------------------------------------------------------------------------ | |
105 | // wxMediaEvent::Clone | |
106 | // | |
107 | // Allocates a copy of this object. | |
108 | // Required for wxEvtHandler::AddPendingEvent | |
109 | // ------------------------------------------------------------------------ | |
110 | virtual wxEvent *Clone() const | |
111 | { return new wxMediaEvent(*this); } | |
112 | ||
113 | ||
114 | // Put this class on wxWidget's RTTI table | |
115 | DECLARE_DYNAMIC_CLASS(wxMediaEvent) | |
116 | }; | |
117 | ||
ff4aedc5 RN |
118 | // ---------------------------------------------------------------------------- |
119 | // | |
120 | // wxMediaCtrl | |
121 | // | |
122 | // ---------------------------------------------------------------------------- | |
123 | ||
ff2b312f | 124 | class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl |
ff4aedc5 RN |
125 | { |
126 | public: | |
bc036010 | 127 | wxMediaCtrl() : m_imp(NULL), m_bLoaded(false) |
ff4aedc5 RN |
128 | { } |
129 | ||
4fc81cbc | 130 | wxMediaCtrl(wxWindow* parent, wxWindowID winid, |
8b5d5223 | 131 | const wxString& fileName = wxEmptyString, |
226ec5a7 | 132 | const wxPoint& pos = wxDefaultPosition, |
ff4aedc5 | 133 | const wxSize& size = wxDefaultSize, |
226ec5a7 | 134 | long style = 0, |
8b5d5223 | 135 | const wxString& szBackend = wxEmptyString, |
ff4aedc5 RN |
136 | const wxValidator& validator = wxDefaultValidator, |
137 | const wxString& name = wxT("mediaCtrl")) | |
bc036010 | 138 | : m_imp(NULL), m_bLoaded(false) |
4fc81cbc | 139 | { Create(parent, winid, fileName, pos, size, style, |
ff4aedc5 RN |
140 | szBackend, validator, name); } |
141 | ||
4fc81cbc | 142 | wxMediaCtrl(wxWindow* parent, wxWindowID winid, |
ff4aedc5 | 143 | const wxURI& location, |
226ec5a7 | 144 | const wxPoint& pos = wxDefaultPosition, |
ff4aedc5 | 145 | const wxSize& size = wxDefaultSize, |
226ec5a7 | 146 | long style = 0, |
8b5d5223 | 147 | const wxString& szBackend = wxEmptyString, |
ff4aedc5 RN |
148 | const wxValidator& validator = wxDefaultValidator, |
149 | const wxString& name = wxT("mediaCtrl")) | |
bc036010 | 150 | : m_imp(NULL), m_bLoaded(false) |
4fc81cbc | 151 | { Create(parent, winid, location, pos, size, style, |
ff4aedc5 RN |
152 | szBackend, validator, name); } |
153 | ||
154 | ~wxMediaCtrl(); | |
155 | ||
4fc81cbc | 156 | bool Create(wxWindow* parent, wxWindowID winid, |
8b5d5223 | 157 | const wxString& fileName = wxEmptyString, |
226ec5a7 | 158 | const wxPoint& pos = wxDefaultPosition, |
ff4aedc5 | 159 | const wxSize& size = wxDefaultSize, |
226ec5a7 | 160 | long style = 0, |
8b5d5223 | 161 | const wxString& szBackend = wxEmptyString, |
ff4aedc5 RN |
162 | const wxValidator& validator = wxDefaultValidator, |
163 | const wxString& name = wxT("mediaCtrl")); | |
164 | ||
4fc81cbc | 165 | bool Create(wxWindow* parent, wxWindowID winid, |
ff4aedc5 | 166 | const wxURI& location, |
226ec5a7 | 167 | const wxPoint& pos = wxDefaultPosition, |
ff4aedc5 | 168 | const wxSize& size = wxDefaultSize, |
226ec5a7 | 169 | long style = 0, |
8b5d5223 | 170 | const wxString& szBackend = wxEmptyString, |
ff4aedc5 | 171 | const wxValidator& validator = wxDefaultValidator, |
c5191fbd | 172 | const wxString& name = wxT("mediaCtrl")); |
ff4aedc5 RN |
173 | |
174 | bool DoCreate(wxClassInfo* instance, | |
4fc81cbc | 175 | wxWindow* parent, wxWindowID winid, |
226ec5a7 | 176 | const wxPoint& pos = wxDefaultPosition, |
ff4aedc5 | 177 | const wxSize& size = wxDefaultSize, |
226ec5a7 | 178 | long style = 0, |
ff4aedc5 RN |
179 | const wxValidator& validator = wxDefaultValidator, |
180 | const wxString& name = wxT("mediaCtrl")); | |
181 | ||
ff4aedc5 RN |
182 | bool Play(); |
183 | bool Pause(); | |
184 | bool Stop(); | |
185 | ||
186 | bool Load(const wxString& fileName); | |
ff4aedc5 | 187 | |
ff4aedc5 RN |
188 | wxMediaState GetState(); |
189 | ||
9180b535 RN |
190 | wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart); |
191 | wxFileOffset Tell(); //FIXME: This should be const | |
192 | wxFileOffset Length(); //FIXME: This should be const | |
973dc0a8 | 193 | |
557002cf | 194 | #if wxABI_VERSION >= 20601 /* 2.6.1+ only */ |
bc036010 RN |
195 | double GetPlaybackRate(); //All but MCI & GStreamer |
196 | bool SetPlaybackRate(double dRate); //All but MCI & GStreamer | |
557002cf | 197 | #endif |
c5191fbd | 198 | |
557002cf | 199 | #if wxABI_VERSION >= 20602 /* 2.6.2+ only */ |
c5191fbd VZ |
200 | bool Load(const wxURI& location); |
201 | bool Load(const wxURI& location, const wxURI& proxy); | |
202 | ||
557002cf VZ |
203 | wxFileOffset GetDownloadProgress(); // DirectShow only |
204 | wxFileOffset GetDownloadTotal(); // DirectShow only | |
bc036010 | 205 | |
c5191fbd VZ |
206 | double GetVolume(); |
207 | bool SetVolume(double dVolume); | |
6f8c67e7 | 208 | |
c5191fbd VZ |
209 | bool ShowPlayerControls( |
210 | wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT); | |
211 | ||
212 | //helpers for the wxPython people | |
213 | bool LoadURI(const wxString& fileName) | |
214 | { return Load(wxURI(fileName)); } | |
215 | bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy) | |
216 | { return Load(wxURI(fileName), wxURI(proxy)); } | |
557002cf | 217 | #endif |
ff4aedc5 | 218 | protected: |
973dc0a8 RN |
219 | static wxClassInfo* NextBackend(); |
220 | ||
226ec5a7 | 221 | void OnMediaFinished(wxMediaEvent& evt); |
ff4aedc5 RN |
222 | virtual void DoMoveWindow(int x, int y, int w, int h); |
223 | wxSize DoGetBestSize() const; | |
224 | ||
bc036010 RN |
225 | //FIXME: This is nasty... find a better way to work around |
226 | //inheritance issues | |
c5191fbd | 227 | #if defined(__WXMAC__) || defined(__WXCOCOA__) |
4fc81cbc | 228 | friend class wxQTMediaBackend; |
3b5023b9 | 229 | #endif |
ff4aedc5 RN |
230 | class wxMediaBackend* m_imp; |
231 | bool m_bLoaded; | |
ff4aedc5 | 232 | |
3839f37e | 233 | DECLARE_DYNAMIC_CLASS(wxMediaCtrl) |
ff4aedc5 RN |
234 | }; |
235 | ||
236 | // ---------------------------------------------------------------------------- | |
237 | // | |
238 | // wxMediaBackend | |
239 | // | |
c5191fbd VZ |
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. | |
244 | // | |
245 | // Note that this is currently not API or ABI compatable - | |
246 | // so statically link or make the client compile on-site. | |
ff4aedc5 RN |
247 | // |
248 | // ---------------------------------------------------------------------------- | |
249 | ||
ff2b312f | 250 | class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject |
ff4aedc5 RN |
251 | { |
252 | public: | |
253 | wxMediaBackend() | |
254 | { } | |
255 | ||
256 | virtual ~wxMediaBackend(); | |
257 | ||
226ec5a7 WS |
258 | virtual bool CreateControl(wxControl* WXUNUSED(ctrl), |
259 | wxWindow* WXUNUSED(parent), | |
4fc81cbc | 260 | wxWindowID WXUNUSED(winid), |
226ec5a7 | 261 | const wxPoint& WXUNUSED(pos), |
78450975 | 262 | const wxSize& WXUNUSED(size), |
226ec5a7 | 263 | long WXUNUSED(style), |
78450975 RN |
264 | const wxValidator& WXUNUSED(validator), |
265 | const wxString& WXUNUSED(name)) | |
ff4aedc5 RN |
266 | { return false; } |
267 | ||
226ec5a7 | 268 | virtual bool Play() |
ff4aedc5 | 269 | { return false; } |
226ec5a7 | 270 | virtual bool Pause() |
ff4aedc5 | 271 | { return false; } |
226ec5a7 | 272 | virtual bool Stop() |
ff4aedc5 RN |
273 | { return false; } |
274 | ||
226ec5a7 | 275 | virtual bool Load(const wxString& WXUNUSED(fileName)) |
ff4aedc5 | 276 | { return false; } |
226ec5a7 | 277 | virtual bool Load(const wxURI& WXUNUSED(location)) |
ff4aedc5 RN |
278 | { return false; } |
279 | ||
226ec5a7 | 280 | virtual bool SetPosition(wxLongLong WXUNUSED(where)) |
ff4aedc5 | 281 | { return 0; } |
226ec5a7 | 282 | virtual wxLongLong GetPosition() |
ff4aedc5 | 283 | { return 0; } |
226ec5a7 | 284 | virtual wxLongLong GetDuration() |
ff4aedc5 RN |
285 | { return 0; } |
286 | ||
226ec5a7 WS |
287 | virtual void Move(int WXUNUSED(x), int WXUNUSED(y), |
288 | int WXUNUSED(w), int WXUNUSED(h)) | |
ff4aedc5 | 289 | { } |
226ec5a7 | 290 | virtual wxSize GetVideoSize() const |
c47addef | 291 | { return wxSize(0,0); } |
ff4aedc5 | 292 | |
226ec5a7 | 293 | virtual double GetPlaybackRate() |
ff4aedc5 | 294 | { return 0.0; } |
226ec5a7 | 295 | virtual bool SetPlaybackRate(double WXUNUSED(dRate)) |
ff4aedc5 RN |
296 | { return false; } |
297 | ||
298 | virtual wxMediaState GetState() | |
299 | { return wxMEDIASTATE_STOPPED; } | |
300 | ||
6f8c67e7 JS |
301 | virtual double GetVolume() |
302 | { return 0.0; } | |
303 | virtual bool SetVolume(double WXUNUSED(dVolume)) | |
304 | { return false; } | |
305 | ||
c5191fbd VZ |
306 | virtual bool Load(const wxURI& WXUNUSED(location), |
307 | const wxURI& WXUNUSED(proxy)) | |
308 | { return false; } | |
309 | ||
310 | virtual bool ShowPlayerControls( | |
311 | wxMediaCtrlPlayerControls WXUNUSED(flags)) | |
312 | { return false; } | |
313 | virtual bool IsInterfaceShown() | |
314 | { return false; } | |
315 | ||
316 | virtual wxLongLong GetDownloadProgress() | |
317 | { return 0; } | |
318 | virtual wxLongLong GetDownloadTotal() | |
319 | { return 0; } | |
320 | ||
07323ed6 RN |
321 | virtual void RESERVED8() {} |
322 | virtual void RESERVED9() {} | |
323 | ||
3839f37e | 324 | DECLARE_DYNAMIC_CLASS(wxMediaBackend) |
ff4aedc5 RN |
325 | }; |
326 | ||
bf354396 | 327 | |
ff4aedc5 RN |
328 | //Event ID to give to our events |
329 | #define wxMEDIA_FINISHED_ID 13000 | |
330 | #define wxMEDIA_STOP_ID 13001 | |
331 | ||
332 | //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later | |
c220a8ec RD |
333 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID) |
334 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMEDIA_STOP_ID) | |
ff4aedc5 RN |
335 | |
336 | //Function type(s) our events need | |
337 | typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&); | |
338 | ||
4153a503 RN |
339 | #define wxMediaEventHandler(func) \ |
340 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func) | |
341 | ||
ff4aedc5 | 342 | //Macro for usage with message maps |
4153a503 RN |
343 | #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ), |
344 | #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ), | |
557002cf VZ |
345 | |
346 | #if wxABI_VERSION >= 20602 /* 2.6.2+ only */ | |
347 | # define wxMEDIA_LOADED_ID 13002 | |
348 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED, wxMEDIA_LOADED_ID) | |
349 | # define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ), | |
350 | #endif | |
351 | ||
352 | #if wxABI_VERSION >= 20603 /* 2.6.3+ only */ | |
353 | # define wxMEDIA_STATECHANGED_ID 13003 | |
354 | # define wxMEDIA_PLAY_ID 13004 | |
355 | # define wxMEDIA_PAUSE_ID 13005 | |
356 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STATECHANGED, wxMEDIA_STATECHANGED_ID) | |
357 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PLAY, wxMEDIA_PLAY_ID) | |
358 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PAUSE, wxMEDIA_PAUSE_ID) | |
359 | # define EVT_MEDIA_STATECHANGED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ), | |
360 | # define EVT_MEDIA_PLAY(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ), | |
361 | # define EVT_MEDIA_PAUSE(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ), | |
362 | #endif | |
c5191fbd | 363 | |
bf354396 VZ |
364 | // ---------------------------------------------------------------------------- |
365 | // common backend base class used by many other backends | |
366 | // ---------------------------------------------------------------------------- | |
367 | ||
368 | class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend | |
369 | { | |
370 | public: | |
371 | // add a pending wxMediaEvent of the given type | |
372 | void QueueEvent(wxEventType evtType); | |
373 | ||
374 | // notify that the movie playback is finished | |
557002cf VZ |
375 | void QueueFinishEvent() |
376 | { | |
377 | #if wxABI_VERSION >= 20603 /* 2.6.3+ only */ | |
378 | QueueEvent(wxEVT_MEDIA_STATECHANGED); | |
379 | #endif | |
380 | QueueEvent(wxEVT_MEDIA_FINISHED); | |
381 | } | |
bf354396 VZ |
382 | |
383 | // send the stop event and return true if it hasn't been vetoed | |
384 | bool SendStopEvent(); | |
385 | ||
557002cf VZ |
386 | // Queue pause event |
387 | void QueuePlayEvent(); | |
388 | ||
389 | // Queue pause event | |
390 | void QueuePauseEvent(); | |
391 | ||
392 | // Queue stop event (no veto) | |
393 | void QueueStopEvent(); | |
394 | ||
bf354396 VZ |
395 | protected: |
396 | // call this when the movie size has changed but not because it has just | |
397 | // been loaded (in this case, call NotifyMovieLoaded() below) | |
398 | void NotifyMovieSizeChanged(); | |
399 | ||
400 | // call this when the movie is fully loaded | |
401 | void NotifyMovieLoaded(); | |
402 | ||
403 | ||
404 | wxMediaCtrl *m_ctrl; // parent control | |
405 | }; | |
406 | ||
ff4aedc5 RN |
407 | // ---------------------------------------------------------------------------- |
408 | // End compilation gaurd | |
409 | // ---------------------------------------------------------------------------- | |
410 | #endif // wxUSE_MEDIACTRL | |
411 | ||
412 | // ---------------------------------------------------------------------------- | |
413 | // End header guard and header itself | |
414 | // ---------------------------------------------------------------------------- | |
415 | #endif // _WX_MEDIACTRL_H_ | |
416 | ||
417 |