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 // ----------------------------------------------------------------------------
25 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
26 #pragma interface "mediactrl.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 #include "wx/control.h"
44 // ============================================================================
46 // ============================================================================
48 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
61 enum wxMediaCtrlPlayerControls
63 wxMEDIACTRLPLAYERCONTROLS_NONE
= 0,
64 //Step controls like fastfoward, step one frame etc.
65 wxMEDIACTRLPLAYERCONTROLS_STEP
= 1 << 0,
66 //Volume controls like the speaker icon, volume slider, etc.
67 wxMEDIACTRLPLAYERCONTROLS_VOLUME
= 1 << 1,
68 wxMEDIACTRLPLAYERCONTROLS_DEFAULT
=
69 wxMEDIACTRLPLAYERCONTROLS_STEP
|
70 wxMEDIACTRLPLAYERCONTROLS_VOLUME
73 #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
74 #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
75 #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
76 #define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
77 #define wxMEDIABACKEND_REALPLAYER wxT("wxRealPlayerMediaBackend")
78 #define wxMEDIABACKEND_WMP10 wxT("wxWMP10MediaBackend")
80 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 class WXDLLIMPEXP_MEDIA wxMediaEvent
: public wxNotifyEvent
89 // ------------------------------------------------------------------------
90 // wxMediaEvent Constructor
92 // Normal constructor, much the same as wxNotifyEvent
93 // ------------------------------------------------------------------------
94 wxMediaEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
95 : wxNotifyEvent(commandType
, winid
)
98 // ------------------------------------------------------------------------
99 // wxMediaEvent Copy Constructor
101 // Normal copy constructor, much the same as wxNotifyEvent
102 // ------------------------------------------------------------------------
103 wxMediaEvent(const wxMediaEvent
&clone
)
104 : wxNotifyEvent(clone
)
107 // ------------------------------------------------------------------------
108 // wxMediaEvent::Clone
110 // Allocates a copy of this object.
111 // Required for wxEvtHandler::AddPendingEvent
112 // ------------------------------------------------------------------------
113 virtual wxEvent
*Clone() const
114 { return new wxMediaEvent(*this); }
117 // Put this class on wxWidget's RTTI table
118 DECLARE_DYNAMIC_CLASS(wxMediaEvent
)
121 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 class WXDLLIMPEXP_MEDIA wxMediaCtrl
: public wxControl
130 wxMediaCtrl() : m_imp(NULL
), m_bLoaded(false)
133 wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
,
134 const wxString
& fileName
= wxEmptyString
,
135 const wxPoint
& pos
= wxDefaultPosition
,
136 const wxSize
& size
= wxDefaultSize
,
138 const wxString
& szBackend
= wxEmptyString
,
139 const wxValidator
& validator
= wxDefaultValidator
,
140 const wxString
& name
= wxT("mediaCtrl"))
141 : m_imp(NULL
), m_bLoaded(false)
142 { Create(parent
, winid
, fileName
, pos
, size
, style
,
143 szBackend
, validator
, name
); }
145 wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
,
146 const wxURI
& location
,
147 const wxPoint
& pos
= wxDefaultPosition
,
148 const wxSize
& size
= wxDefaultSize
,
150 const wxString
& szBackend
= wxEmptyString
,
151 const wxValidator
& validator
= wxDefaultValidator
,
152 const wxString
& name
= wxT("mediaCtrl"))
153 : m_imp(NULL
), m_bLoaded(false)
154 { Create(parent
, winid
, location
, pos
, size
, style
,
155 szBackend
, validator
, name
); }
159 bool Create(wxWindow
* parent
, wxWindowID winid
,
160 const wxString
& fileName
= wxEmptyString
,
161 const wxPoint
& pos
= wxDefaultPosition
,
162 const wxSize
& size
= wxDefaultSize
,
164 const wxString
& szBackend
= wxEmptyString
,
165 const wxValidator
& validator
= wxDefaultValidator
,
166 const wxString
& name
= wxT("mediaCtrl"));
168 bool Create(wxWindow
* parent
, wxWindowID winid
,
169 const wxURI
& location
,
170 const wxPoint
& pos
= wxDefaultPosition
,
171 const wxSize
& size
= wxDefaultSize
,
173 const wxString
& szBackend
= wxEmptyString
,
174 const wxValidator
& validator
= wxDefaultValidator
,
175 const wxString
& name
= wxT("mediaCtrl"));
177 bool DoCreate(wxClassInfo
* instance
,
178 wxWindow
* parent
, wxWindowID winid
,
179 const wxPoint
& pos
= wxDefaultPosition
,
180 const wxSize
& size
= wxDefaultSize
,
182 const wxValidator
& validator
= wxDefaultValidator
,
183 const wxString
& name
= wxT("mediaCtrl"));
189 bool Load(const wxString
& fileName
);
191 wxMediaState
GetState();
193 wxFileOffset
Seek(wxFileOffset where
, wxSeekMode mode
= wxFromStart
);
194 wxFileOffset
Tell(); //FIXME: This should be const
195 wxFileOffset
Length(); //FIXME: This should be const
197 #if wxABI_VERSION >= 20601 /* 2.6.1+ only */
198 double GetPlaybackRate(); //All but MCI & GStreamer
199 bool SetPlaybackRate(double dRate
); //All but MCI & GStreamer
202 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
203 bool Load(const wxURI
& location
);
204 bool Load(const wxURI
& location
, const wxURI
& proxy
);
206 wxFileOffset
GetDownloadProgress(); // DirectShow only
207 wxFileOffset
GetDownloadTotal(); // DirectShow only
210 bool SetVolume(double dVolume
);
212 bool ShowPlayerControls(
213 wxMediaCtrlPlayerControls flags
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
);
215 //helpers for the wxPython people
216 bool LoadURI(const wxString
& fileName
)
217 { return Load(wxURI(fileName
)); }
218 bool LoadURIWithProxy(const wxString
& fileName
, const wxString
& proxy
)
219 { return Load(wxURI(fileName
), wxURI(proxy
)); }
222 static wxClassInfo
* NextBackend();
224 void OnMediaFinished(wxMediaEvent
& evt
);
225 virtual void DoMoveWindow(int x
, int y
, int w
, int h
);
226 wxSize
DoGetBestSize() const;
228 //FIXME: This is nasty... find a better way to work around
230 #if defined(__WXMAC__) || defined(__WXCOCOA__)
231 friend class wxQTMediaBackend
;
233 class wxMediaBackend
* m_imp
;
236 DECLARE_DYNAMIC_CLASS(wxMediaCtrl
)
239 // ----------------------------------------------------------------------------
243 // Derive from this and use standard wxWidgets RTTI
244 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
245 // for wxMediaCtrl. Backends are searched alphabetically -
246 // the one with the earliest letter is tried first.
248 // Note that this is currently not API or ABI compatable -
249 // so statically link or make the client compile on-site.
251 // ----------------------------------------------------------------------------
253 class WXDLLIMPEXP_MEDIA wxMediaBackend
: public wxObject
259 virtual ~wxMediaBackend();
261 virtual bool CreateControl(wxControl
* WXUNUSED(ctrl
),
262 wxWindow
* WXUNUSED(parent
),
263 wxWindowID
WXUNUSED(winid
),
264 const wxPoint
& WXUNUSED(pos
),
265 const wxSize
& WXUNUSED(size
),
266 long WXUNUSED(style
),
267 const wxValidator
& WXUNUSED(validator
),
268 const wxString
& WXUNUSED(name
))
278 virtual bool Load(const wxString
& WXUNUSED(fileName
))
280 virtual bool Load(const wxURI
& WXUNUSED(location
))
283 virtual bool SetPosition(wxLongLong
WXUNUSED(where
))
285 virtual wxLongLong
GetPosition()
287 virtual wxLongLong
GetDuration()
290 virtual void Move(int WXUNUSED(x
), int WXUNUSED(y
),
291 int WXUNUSED(w
), int WXUNUSED(h
))
293 virtual wxSize
GetVideoSize() const
294 { return wxSize(0,0); }
296 virtual double GetPlaybackRate()
298 virtual bool SetPlaybackRate(double WXUNUSED(dRate
))
301 virtual wxMediaState
GetState()
302 { return wxMEDIASTATE_STOPPED
; }
304 virtual double GetVolume()
306 virtual bool SetVolume(double WXUNUSED(dVolume
))
309 virtual bool Load(const wxURI
& WXUNUSED(location
),
310 const wxURI
& WXUNUSED(proxy
))
313 virtual bool ShowPlayerControls(
314 wxMediaCtrlPlayerControls
WXUNUSED(flags
))
316 virtual bool IsInterfaceShown()
319 virtual wxLongLong
GetDownloadProgress()
321 virtual wxLongLong
GetDownloadTotal()
324 virtual void RESERVED8() {}
325 virtual void RESERVED9() {}
327 DECLARE_DYNAMIC_CLASS(wxMediaBackend
)
331 //Event ID to give to our events
332 #define wxMEDIA_FINISHED_ID 13000
333 #define wxMEDIA_STOP_ID 13001
335 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
336 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_FINISHED
, wxMEDIA_FINISHED_ID
)
337 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STOP
, wxMEDIA_STOP_ID
)
339 //Function type(s) our events need
340 typedef void (wxEvtHandler::*wxMediaEventFunction
)(wxMediaEvent
&);
342 #define wxMediaEventHandler(func) \
343 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
345 //Macro for usage with message maps
346 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
347 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
349 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
350 # define wxMEDIA_LOADED_ID 13002
351 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_LOADED
, wxMEDIA_LOADED_ID
)
352 # define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
355 #if wxABI_VERSION >= 20603 /* 2.6.3+ only */
356 # define wxMEDIA_STATECHANGED_ID 13003
357 # define wxMEDIA_PLAY_ID 13004
358 # define wxMEDIA_PAUSE_ID 13005
359 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STATECHANGED
, wxMEDIA_STATECHANGED_ID
)
360 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_PLAY
, wxMEDIA_PLAY_ID
)
361 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_PAUSE
, wxMEDIA_PAUSE_ID
)
362 # define EVT_MEDIA_STATECHANGED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
363 # define EVT_MEDIA_PLAY(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
364 # define EVT_MEDIA_PAUSE(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
367 // ----------------------------------------------------------------------------
368 // common backend base class used by many other backends
369 // ----------------------------------------------------------------------------
371 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase
: public wxMediaBackend
374 // add a pending wxMediaEvent of the given type
375 void QueueEvent(wxEventType evtType
);
377 // notify that the movie playback is finished
378 void QueueFinishEvent()
380 #if wxABI_VERSION >= 20603 /* 2.6.3+ only */
381 QueueEvent(wxEVT_MEDIA_STATECHANGED
);
383 QueueEvent(wxEVT_MEDIA_FINISHED
);
386 // send the stop event and return true if it hasn't been vetoed
387 bool SendStopEvent();
390 void QueuePlayEvent();
393 void QueuePauseEvent();
395 // Queue stop event (no veto)
396 void QueueStopEvent();
399 // call this when the movie size has changed but not because it has just
400 // been loaded (in this case, call NotifyMovieLoaded() below)
401 void NotifyMovieSizeChanged();
403 // call this when the movie is fully loaded
404 void NotifyMovieLoaded();
407 wxMediaCtrl
*m_ctrl
; // parent control
410 // ----------------------------------------------------------------------------
411 // End compilation gaurd
412 // ----------------------------------------------------------------------------
413 #endif // wxUSE_MEDIACTRL
415 // ----------------------------------------------------------------------------
416 // End header guard and header itself
417 // ----------------------------------------------------------------------------
418 #endif // _WX_MEDIACTRL_H_