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")
79 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 class WXDLLIMPEXP_MEDIA wxMediaEvent
: public wxNotifyEvent
88 // ------------------------------------------------------------------------
89 // wxMediaEvent Constructor
91 // Normal constructor, much the same as wxNotifyEvent
92 // ------------------------------------------------------------------------
93 wxMediaEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
94 : wxNotifyEvent(commandType
, winid
)
97 // ------------------------------------------------------------------------
98 // wxMediaEvent Copy Constructor
100 // Normal copy constructor, much the same as wxNotifyEvent
101 // ------------------------------------------------------------------------
102 wxMediaEvent(const wxMediaEvent
&clone
)
103 : wxNotifyEvent(clone
)
106 // ------------------------------------------------------------------------
107 // wxMediaEvent::Clone
109 // Allocates a copy of this object.
110 // Required for wxEvtHandler::AddPendingEvent
111 // ------------------------------------------------------------------------
112 virtual wxEvent
*Clone() const
113 { return new wxMediaEvent(*this); }
116 // Put this class on wxWidget's RTTI table
117 DECLARE_DYNAMIC_CLASS(wxMediaEvent
)
120 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 class WXDLLIMPEXP_MEDIA wxMediaCtrl
: public wxControl
129 wxMediaCtrl() : m_imp(NULL
), m_bLoaded(false)
132 wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
,
133 const wxString
& fileName
= wxEmptyString
,
134 const wxPoint
& pos
= wxDefaultPosition
,
135 const wxSize
& size
= wxDefaultSize
,
137 const wxString
& szBackend
= wxEmptyString
,
138 const wxValidator
& validator
= wxDefaultValidator
,
139 const wxString
& name
= wxT("mediaCtrl"))
140 : m_imp(NULL
), m_bLoaded(false)
141 { Create(parent
, winid
, fileName
, pos
, size
, style
,
142 szBackend
, validator
, name
); }
144 wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
,
145 const wxURI
& location
,
146 const wxPoint
& pos
= wxDefaultPosition
,
147 const wxSize
& size
= wxDefaultSize
,
149 const wxString
& szBackend
= wxEmptyString
,
150 const wxValidator
& validator
= wxDefaultValidator
,
151 const wxString
& name
= wxT("mediaCtrl"))
152 : m_imp(NULL
), m_bLoaded(false)
153 { Create(parent
, winid
, location
, pos
, size
, style
,
154 szBackend
, validator
, name
); }
158 bool Create(wxWindow
* parent
, wxWindowID winid
,
159 const wxString
& fileName
= wxEmptyString
,
160 const wxPoint
& pos
= wxDefaultPosition
,
161 const wxSize
& size
= wxDefaultSize
,
163 const wxString
& szBackend
= wxEmptyString
,
164 const wxValidator
& validator
= wxDefaultValidator
,
165 const wxString
& name
= wxT("mediaCtrl"));
167 bool Create(wxWindow
* parent
, wxWindowID winid
,
168 const wxURI
& location
,
169 const wxPoint
& pos
= wxDefaultPosition
,
170 const wxSize
& size
= wxDefaultSize
,
172 const wxString
& szBackend
= wxEmptyString
,
173 const wxValidator
& validator
= wxDefaultValidator
,
174 const wxString
& name
= wxT("mediaCtrl"));
176 bool DoCreate(wxClassInfo
* instance
,
177 wxWindow
* parent
, wxWindowID winid
,
178 const wxPoint
& pos
= wxDefaultPosition
,
179 const wxSize
& size
= wxDefaultSize
,
181 const wxValidator
& validator
= wxDefaultValidator
,
182 const wxString
& name
= wxT("mediaCtrl"));
188 bool Load(const wxString
& fileName
);
190 wxMediaState
GetState();
192 wxFileOffset
Seek(wxFileOffset where
, wxSeekMode mode
= wxFromStart
);
193 wxFileOffset
Tell(); //FIXME: This should be const
194 wxFileOffset
Length(); //FIXME: This should be const
196 #if wxABI_VERSION >= 20601 /* 2.6.1+ only */
197 double GetPlaybackRate(); //All but MCI & GStreamer
198 bool SetPlaybackRate(double dRate
); //All but MCI & GStreamer
201 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
202 bool Load(const wxURI
& location
);
203 bool Load(const wxURI
& location
, const wxURI
& proxy
);
205 wxFileOffset
GetDownloadProgress();
206 wxFileOffset
GetDownloadTotal();
209 bool SetVolume(double dVolume
);
211 bool ShowPlayerControls(
212 wxMediaCtrlPlayerControls flags
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
);
214 //helpers for the wxPython people
215 bool LoadURI(const wxString
& fileName
)
216 { return Load(wxURI(fileName
)); }
217 bool LoadURIWithProxy(const wxString
& fileName
, const wxString
& proxy
)
218 { return Load(wxURI(fileName
), wxURI(proxy
)); }
221 static wxClassInfo
* NextBackend();
223 void OnMediaFinished(wxMediaEvent
& evt
);
224 virtual void DoMoveWindow(int x
, int y
, int w
, int h
);
225 wxSize
DoGetBestSize() const;
227 //FIXME: This is nasty... find a better way to work around
229 #if defined(__WXMAC__) || defined(__WXCOCOA__)
230 friend class wxQTMediaBackend
;
232 class wxMediaBackend
* m_imp
;
235 DECLARE_DYNAMIC_CLASS(wxMediaCtrl
)
238 // ----------------------------------------------------------------------------
242 // Derive from this and use standard wxWidgets RTTI
243 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
244 // for wxMediaCtrl. Backends are searched alphabetically -
245 // the one with the earliest letter is tried first.
247 // Note that this is currently not API or ABI compatable -
248 // so statically link or make the client compile on-site.
250 // ----------------------------------------------------------------------------
252 class WXDLLIMPEXP_MEDIA wxMediaBackend
: public wxObject
258 virtual ~wxMediaBackend();
260 virtual bool CreateControl(wxControl
* WXUNUSED(ctrl
),
261 wxWindow
* WXUNUSED(parent
),
262 wxWindowID
WXUNUSED(winid
),
263 const wxPoint
& WXUNUSED(pos
),
264 const wxSize
& WXUNUSED(size
),
265 long WXUNUSED(style
),
266 const wxValidator
& WXUNUSED(validator
),
267 const wxString
& WXUNUSED(name
))
277 virtual bool Load(const wxString
& WXUNUSED(fileName
))
279 virtual bool Load(const wxURI
& WXUNUSED(location
))
282 virtual bool SetPosition(wxLongLong
WXUNUSED(where
))
284 virtual wxLongLong
GetPosition()
286 virtual wxLongLong
GetDuration()
289 virtual void Move(int WXUNUSED(x
), int WXUNUSED(y
),
290 int WXUNUSED(w
), int WXUNUSED(h
))
292 virtual wxSize
GetVideoSize() const
293 { return wxSize(0,0); }
295 virtual double GetPlaybackRate()
297 virtual bool SetPlaybackRate(double WXUNUSED(dRate
))
300 virtual wxMediaState
GetState()
301 { return wxMEDIASTATE_STOPPED
; }
303 virtual double GetVolume()
305 virtual bool SetVolume(double WXUNUSED(dVolume
))
308 virtual bool Load(const wxURI
& WXUNUSED(location
),
309 const wxURI
& WXUNUSED(proxy
))
312 virtual bool ShowPlayerControls(
313 wxMediaCtrlPlayerControls
WXUNUSED(flags
))
315 virtual bool IsInterfaceShown()
318 virtual wxLongLong
GetDownloadProgress()
320 virtual wxLongLong
GetDownloadTotal()
323 virtual void RESERVED8() {}
324 virtual void RESERVED9() {}
326 DECLARE_DYNAMIC_CLASS(wxMediaBackend
)
330 //Event ID to give to our events
331 #define wxMEDIA_FINISHED_ID 13000
332 #define wxMEDIA_STOP_ID 13001
334 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
335 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_FINISHED
, wxMEDIA_FINISHED_ID
)
336 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STOP
, wxMEDIA_STOP_ID
)
338 //Function type(s) our events need
339 typedef void (wxEvtHandler::*wxMediaEventFunction
)(wxMediaEvent
&);
341 #define wxMediaEventHandler(func) \
342 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
344 //Macro for usage with message maps
345 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
346 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
348 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
349 # define wxMEDIA_LOADED_ID 13002
350 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_LOADED
, wxMEDIA_LOADED_ID
)
351 # define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
354 // ----------------------------------------------------------------------------
355 // common backend base class used by many other backends
356 // ----------------------------------------------------------------------------
358 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase
: public wxMediaBackend
361 // add a pending wxMediaEvent of the given type
362 void QueueEvent(wxEventType evtType
);
364 // notify that the movie playback is finished
365 void QueueFinishEvent() { QueueEvent(wxEVT_MEDIA_FINISHED
); }
367 // send the stop event and return true if it hasn't been vetoed
368 bool SendStopEvent();
371 // call this when the movie size has changed but not because it has just
372 // been loaded (in this case, call NotifyMovieLoaded() below)
373 void NotifyMovieSizeChanged();
375 // call this when the movie is fully loaded
376 void NotifyMovieLoaded();
379 wxMediaCtrl
*m_ctrl
; // parent control
382 // ----------------------------------------------------------------------------
383 // End compilation gaurd
384 // ----------------------------------------------------------------------------
385 #endif // wxUSE_MEDIACTRL
387 // ----------------------------------------------------------------------------
388 // End header guard and header itself
389 // ----------------------------------------------------------------------------
390 #endif // _WX_MEDIACTRL_H_