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")
76 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 class WXDLLIMPEXP_MEDIA wxMediaEvent
: public wxNotifyEvent
85 // ------------------------------------------------------------------------
86 // wxMediaEvent Constructor
88 // Normal constructor, much the same as wxNotifyEvent
89 // ------------------------------------------------------------------------
90 wxMediaEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
91 : wxNotifyEvent(commandType
, winid
)
94 // ------------------------------------------------------------------------
95 // wxMediaEvent Copy Constructor
97 // Normal copy constructor, much the same as wxNotifyEvent
98 // ------------------------------------------------------------------------
99 wxMediaEvent(const wxMediaEvent
&clone
)
100 : wxNotifyEvent(clone
)
103 // ------------------------------------------------------------------------
104 // wxMediaEvent::Clone
106 // Allocates a copy of this object.
107 // Required for wxEvtHandler::AddPendingEvent
108 // ------------------------------------------------------------------------
109 virtual wxEvent
*Clone() const
110 { return new wxMediaEvent(*this); }
113 // Put this class on wxWidget's RTTI table
114 DECLARE_DYNAMIC_CLASS(wxMediaEvent
)
117 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 class WXDLLIMPEXP_MEDIA wxMediaCtrl
: public wxControl
126 wxMediaCtrl() : m_imp(NULL
), m_bLoaded(false)
129 wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
,
130 const wxString
& fileName
= wxEmptyString
,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
134 const wxString
& szBackend
= wxEmptyString
,
135 const wxValidator
& validator
= wxDefaultValidator
,
136 const wxString
& name
= wxT("mediaCtrl"))
137 : m_imp(NULL
), m_bLoaded(false)
138 { Create(parent
, winid
, fileName
, pos
, size
, style
,
139 szBackend
, validator
, name
); }
141 wxMediaCtrl(wxWindow
* parent
, wxWindowID winid
,
142 const wxURI
& location
,
143 const wxPoint
& pos
= wxDefaultPosition
,
144 const wxSize
& size
= wxDefaultSize
,
146 const wxString
& szBackend
= wxEmptyString
,
147 const wxValidator
& validator
= wxDefaultValidator
,
148 const wxString
& name
= wxT("mediaCtrl"))
149 : m_imp(NULL
), m_bLoaded(false)
150 { Create(parent
, winid
, location
, pos
, size
, style
,
151 szBackend
, validator
, name
); }
155 bool Create(wxWindow
* parent
, wxWindowID winid
,
156 const wxString
& fileName
= wxEmptyString
,
157 const wxPoint
& pos
= wxDefaultPosition
,
158 const wxSize
& size
= wxDefaultSize
,
160 const wxString
& szBackend
= wxEmptyString
,
161 const wxValidator
& validator
= wxDefaultValidator
,
162 const wxString
& name
= wxT("mediaCtrl"));
164 bool Create(wxWindow
* parent
, wxWindowID winid
,
165 const wxURI
& location
,
166 const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& size
= wxDefaultSize
,
169 const wxString
& szBackend
= wxEmptyString
,
170 const wxValidator
& validator
= wxDefaultValidator
,
171 const wxString
& name
= wxT("mediaCtrl"));
173 bool DoCreate(wxClassInfo
* instance
,
174 wxWindow
* parent
, wxWindowID winid
,
175 const wxPoint
& pos
= wxDefaultPosition
,
176 const wxSize
& size
= wxDefaultSize
,
178 const wxValidator
& validator
= wxDefaultValidator
,
179 const wxString
& name
= wxT("mediaCtrl"));
185 bool Load(const wxString
& fileName
);
187 wxMediaState
GetState();
189 wxFileOffset
Seek(wxFileOffset where
, wxSeekMode mode
= wxFromStart
);
190 wxFileOffset
Tell(); //FIXME: This should be const
191 wxFileOffset
Length(); //FIXME: This should be const
193 double GetPlaybackRate(); //All but MCI & GStreamer
194 bool SetPlaybackRate(double dRate
); //All but MCI & GStreamer
196 bool Load(const wxURI
& location
);
197 bool Load(const wxURI
& location
, const wxURI
& proxy
);
199 wxFileOffset
GetDownloadProgress();
200 wxFileOffset
GetDownloadTotal();
203 bool SetVolume(double dVolume
);
205 bool ShowPlayerControls(
206 wxMediaCtrlPlayerControls flags
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
);
208 //helpers for the wxPython people
209 bool LoadURI(const wxString
& fileName
)
210 { return Load(wxURI(fileName
)); }
211 bool LoadURIWithProxy(const wxString
& fileName
, const wxString
& proxy
)
212 { return Load(wxURI(fileName
), wxURI(proxy
)); }
215 static wxClassInfo
* NextBackend();
217 void OnMediaFinished(wxMediaEvent
& evt
);
218 virtual void DoMoveWindow(int x
, int y
, int w
, int h
);
219 wxSize
DoGetBestSize() const;
221 //FIXME: This is nasty... find a better way to work around
223 #if defined(__WXMAC__) || defined(__WXCOCOA__)
224 friend class wxQTMediaBackend
;
226 class wxMediaBackend
* m_imp
;
229 DECLARE_DYNAMIC_CLASS(wxMediaCtrl
)
232 // ----------------------------------------------------------------------------
236 // Derive from this and use standard wxWidgets RTTI
237 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
238 // for wxMediaCtrl. Backends are searched alphabetically -
239 // the one with the earliest letter is tried first.
241 // Note that this is currently not API or ABI compatable -
242 // so statically link or make the client compile on-site.
244 // ----------------------------------------------------------------------------
246 class WXDLLIMPEXP_MEDIA wxMediaBackend
: public wxObject
252 virtual ~wxMediaBackend();
254 virtual bool CreateControl(wxControl
* WXUNUSED(ctrl
),
255 wxWindow
* WXUNUSED(parent
),
256 wxWindowID
WXUNUSED(winid
),
257 const wxPoint
& WXUNUSED(pos
),
258 const wxSize
& WXUNUSED(size
),
259 long WXUNUSED(style
),
260 const wxValidator
& WXUNUSED(validator
),
261 const wxString
& WXUNUSED(name
))
271 virtual bool Load(const wxString
& WXUNUSED(fileName
))
273 virtual bool Load(const wxURI
& WXUNUSED(location
))
276 virtual bool SetPosition(wxLongLong
WXUNUSED(where
))
278 virtual wxLongLong
GetPosition()
280 virtual wxLongLong
GetDuration()
283 virtual void Move(int WXUNUSED(x
), int WXUNUSED(y
),
284 int WXUNUSED(w
), int WXUNUSED(h
))
286 virtual wxSize
GetVideoSize() const
287 { return wxSize(0,0); }
289 virtual double GetPlaybackRate()
291 virtual bool SetPlaybackRate(double WXUNUSED(dRate
))
294 virtual wxMediaState
GetState()
295 { return wxMEDIASTATE_STOPPED
; }
297 virtual double GetVolume()
299 virtual bool SetVolume(double WXUNUSED(dVolume
))
302 virtual bool Load(const wxURI
& WXUNUSED(location
),
303 const wxURI
& WXUNUSED(proxy
))
306 virtual bool ShowPlayerControls(
307 wxMediaCtrlPlayerControls
WXUNUSED(flags
))
309 virtual bool IsInterfaceShown()
312 virtual wxLongLong
GetDownloadProgress()
314 virtual wxLongLong
GetDownloadTotal()
317 virtual void RESERVED8() {}
318 virtual void RESERVED9() {}
320 DECLARE_DYNAMIC_CLASS(wxMediaBackend
)
324 //Event ID to give to our events
325 #define wxMEDIA_FINISHED_ID 13000
326 #define wxMEDIA_STOP_ID 13001
327 #define wxMEDIA_LOADED_ID 13002
329 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
330 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_FINISHED
, wxMEDIA_FINISHED_ID
)
331 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STOP
, wxMEDIA_STOP_ID
)
332 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_LOADED
, wxMEDIA_LOADED_ID
)
334 //Function type(s) our events need
335 typedef void (wxEvtHandler::*wxMediaEventFunction
)(wxMediaEvent
&);
337 #define wxMediaEventHandler(func) \
338 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
340 //Macro for usage with message maps
341 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
342 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
343 #define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
345 // ----------------------------------------------------------------------------
346 // common backend base class used by many other backends
347 // ----------------------------------------------------------------------------
349 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase
: public wxMediaBackend
352 // add a pending wxMediaEvent of the given type
353 void QueueEvent(wxEventType evtType
);
355 // notify that the movie playback is finished
356 void QueueFinishEvent() { QueueEvent(wxEVT_MEDIA_FINISHED
); }
358 // send the stop event and return true if it hasn't been vetoed
359 bool SendStopEvent();
362 // call this when the movie size has changed but not because it has just
363 // been loaded (in this case, call NotifyMovieLoaded() below)
364 void NotifyMovieSizeChanged();
366 // call this when the movie is fully loaded
367 void NotifyMovieLoaded();
370 wxMediaCtrl
*m_ctrl
; // parent control
373 // ----------------------------------------------------------------------------
374 // End compilation gaurd
375 // ----------------------------------------------------------------------------
376 #endif // wxUSE_MEDIACTRL
378 // ----------------------------------------------------------------------------
379 // End header guard and header itself
380 // ----------------------------------------------------------------------------
381 #endif // _WX_MEDIACTRL_H_