1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mediactrl.h
3 // Purpose: wxMediaCtrl class
4 // Author: Ryan Norton <wxprojects@comcast.net>
7 // Copyright: (c) Ryan Norton
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
18 #ifndef _WX_MEDIACTRL_H_
19 #define _WX_MEDIACTRL_H_
21 // ----------------------------------------------------------------------------
22 // Pre-compiled header stuff
23 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 #include "wx/control.h"
40 // ============================================================================
42 // ============================================================================
44 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
57 enum wxMediaCtrlPlayerControls
59 wxMEDIACTRLPLAYERCONTROLS_NONE
= 0,
60 //Step controls like fastforward, step one frame etc.
61 wxMEDIACTRLPLAYERCONTROLS_STEP
= 1 << 0,
62 //Volume controls like the speaker icon, volume slider, etc.
63 wxMEDIACTRLPLAYERCONTROLS_VOLUME
= 1 << 1,
64 wxMEDIACTRLPLAYERCONTROLS_DEFAULT
=
65 wxMEDIACTRLPLAYERCONTROLS_STEP
|
66 wxMEDIACTRLPLAYERCONTROLS_VOLUME
69 #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
70 #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
71 #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
72 #define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
73 #define wxMEDIABACKEND_REALPLAYER wxT("wxRealPlayerMediaBackend")
74 #define wxMEDIABACKEND_WMP10 wxT("wxWMP10MediaBackend")
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
); }
153 virtual ~wxMediaCtrl();
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(const 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(); // DirectShow only
200 wxFileOffset
GetDownloadTotal(); // DirectShow only
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 const wxClassInfo
* NextBackend(wxClassInfo::const_iterator
* it
);
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(__WXOSX_CARBON__)
224 virtual void MacVisibilityChanged();
226 #if defined(__WXOSX_CARBON__) || defined(__WXCOCOA__)
227 friend class wxQTMediaBackend
;
229 class wxMediaBackend
* m_imp
;
232 DECLARE_DYNAMIC_CLASS(wxMediaCtrl
)
235 // ----------------------------------------------------------------------------
239 // Derive from this and use standard wxWidgets RTTI
240 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
241 // for wxMediaCtrl. Backends are searched alphabetically -
242 // the one with the earliest letter is tried first.
244 // Note that this is currently not API or ABI compatible -
245 // so statically link or make the client compile on-site.
247 // ----------------------------------------------------------------------------
249 class WXDLLIMPEXP_MEDIA wxMediaBackend
: public wxObject
255 virtual ~wxMediaBackend();
257 virtual bool CreateControl(wxControl
* WXUNUSED(ctrl
),
258 wxWindow
* WXUNUSED(parent
),
259 wxWindowID
WXUNUSED(winid
),
260 const wxPoint
& WXUNUSED(pos
),
261 const wxSize
& WXUNUSED(size
),
262 long WXUNUSED(style
),
263 const wxValidator
& WXUNUSED(validator
),
264 const wxString
& WXUNUSED(name
))
274 virtual bool Load(const wxString
& WXUNUSED(fileName
))
276 virtual bool Load(const wxURI
& WXUNUSED(location
))
279 virtual bool SetPosition(wxLongLong
WXUNUSED(where
))
281 virtual wxLongLong
GetPosition()
283 virtual wxLongLong
GetDuration()
286 virtual void Move(int WXUNUSED(x
), int WXUNUSED(y
),
287 int WXUNUSED(w
), int WXUNUSED(h
))
289 virtual wxSize
GetVideoSize() const
290 { return wxSize(0,0); }
292 virtual double GetPlaybackRate()
294 virtual bool SetPlaybackRate(double WXUNUSED(dRate
))
297 virtual wxMediaState
GetState()
298 { return wxMEDIASTATE_STOPPED
; }
300 virtual double GetVolume()
302 virtual bool SetVolume(double WXUNUSED(dVolume
))
305 virtual bool Load(const wxURI
& WXUNUSED(location
),
306 const wxURI
& WXUNUSED(proxy
))
309 virtual bool ShowPlayerControls(
310 wxMediaCtrlPlayerControls
WXUNUSED(flags
))
312 virtual bool IsInterfaceShown()
315 virtual wxLongLong
GetDownloadProgress()
317 virtual wxLongLong
GetDownloadTotal()
320 virtual void MacVisibilityChanged()
322 virtual void RESERVED9() {}
324 DECLARE_DYNAMIC_CLASS(wxMediaBackend
)
329 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_FINISHED
, wxMediaEvent
);
330 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STOP
, wxMediaEvent
);
332 //Function type(s) our events need
333 typedef void (wxEvtHandler::*wxMediaEventFunction
)(wxMediaEvent
&);
335 #define wxMediaEventHandler(func) \
336 wxEVENT_HANDLER_CAST(wxMediaEventFunction, func)
338 //Macro for usage with message maps
339 #define EVT_MEDIA_FINISHED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
340 #define EVT_MEDIA_STOP(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
342 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_LOADED
, wxMediaEvent
);
343 #define EVT_MEDIA_LOADED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
345 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_STATECHANGED
, wxMediaEvent
);
346 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_PLAY
, wxMediaEvent
);
347 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA
, wxEVT_MEDIA_PAUSE
, wxMediaEvent
);
348 #define EVT_MEDIA_STATECHANGED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
349 #define EVT_MEDIA_PLAY(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
350 #define EVT_MEDIA_PAUSE(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
352 // ----------------------------------------------------------------------------
353 // common backend base class used by many other backends
354 // ----------------------------------------------------------------------------
356 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase
: public wxMediaBackend
359 // add a pending wxMediaEvent of the given type
360 void QueueEvent(wxEventType evtType
);
362 // notify that the movie playback is finished
363 void QueueFinishEvent()
365 QueueEvent(wxEVT_MEDIA_STATECHANGED
);
366 QueueEvent(wxEVT_MEDIA_FINISHED
);
369 // send the stop event and return true if it hasn't been vetoed
370 bool SendStopEvent();
373 void QueuePlayEvent();
376 void QueuePauseEvent();
378 // Queue stop event (no veto)
379 void QueueStopEvent();
382 // call this when the movie size has changed but not because it has just
383 // been loaded (in this case, call NotifyMovieLoaded() below)
384 void NotifyMovieSizeChanged();
386 // call this when the movie is fully loaded
387 void NotifyMovieLoaded();
390 wxMediaCtrl
*m_ctrl
; // parent control
393 // ----------------------------------------------------------------------------
394 // End compilation guard
395 // ----------------------------------------------------------------------------
396 #endif // wxUSE_MEDIACTRL
398 // ----------------------------------------------------------------------------
399 // End header guard and header itself
400 // ----------------------------------------------------------------------------
401 #endif // _WX_MEDIACTRL_H_