1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMediaEvent
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 enum wxMediaCtrlPlayerControls
12 /** No controls. return wxMediaCtrl to its default state. */
13 wxMEDIACTRLPLAYERCONTROLS_NONE
= 0,
15 /** Step controls like fastfoward, step one frame etc. */
16 wxMEDIACTRLPLAYERCONTROLS_STEP
= 1 << 0,
18 /** Volume controls like the speaker icon, volume slider, etc. */
19 wxMEDIACTRLPLAYERCONTROLS_VOLUME
= 1 << 1,
21 /** Default controls for the toolkit. Currently a combination for
22 @c wxMEDIACTRLPLAYERCONTROLS_STEP and @c wxMEDIACTRLPLAYERCONTROLS_VOLUME. */
23 wxMEDIACTRLPLAYERCONTROLS_DEFAULT
=
24 wxMEDIACTRLPLAYERCONTROLS_STEP
|
25 wxMEDIACTRLPLAYERCONTROLS_VOLUME
31 Event wxMediaCtrl uses.
33 @beginEventTable{wxMediaEvent}
34 @event{EVT_MEDIA_LOADED(id\, func)}
35 Sent when a media has loaded enough data that it can start playing.
36 @event{EVT_MEDIA_STOP(id\, func)}
37 Sent when a media has switched to the @c wxMEDIASTATE_STOPPED state.
38 You may be able to Veto this event to prevent it from stopping,
39 causing it to continue playing - even if it has reached that end of
40 the media (note that this may not have the desired effect - if you
41 want to loop the media, for example, catch the @c EVT_MEDIA_FINISHED
42 and play there instead).
43 @event{EVT_MEDIA_FINISHED(id\, func)}
44 Sent when a media has finished playing in a wxMediaCtrl.
45 @event{EVT_MEDIA_STATECHANGED(id\, func)}
46 Sent when a media has switched its state (from any media state).
47 @event{EVT_MEDIA_PLAY(id\, func)}
48 Sent when a media has switched to the @c wxMEDIASTATE_PLAYING state.
49 @event{EVT_MEDIA_PAUSE(id\, func)}
50 Sent when a media has switched to the @c wxMEDIASTATE_PAUSED state.
56 class wxMediaEvent
: public wxNotifyEvent
60 wxMediaEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0);
68 wxMediaCtrl is a class for displaying types of
69 media, such as videos, audio files, natively through native codecs.
71 wxMediaCtrl uses native backends to render media, for example on Windows
72 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
80 @section class_mediactrl_rendering_media Rendering media
82 Depending upon the backend, wxMediaCtrl can render and display pretty much any
83 kind of media that the native system can - such as an image, mpeg video, or mp3
84 (without license restrictions - since it relies on native system calls that may
85 not technically have mp3 decoding available, for example, it falls outside
86 the realm of licensing restrictions).
88 For general operation, all you need to do is call Load() to load the file you
89 want to render, catch the @c EVT_MEDIA_LOADED event, and then call Play()
90 to show the video/audio of the media in that event.
92 More complex operations are generally more heavily dependant on the capabilities
93 of the backend. For example, QuickTime cannot set the playback rate of certain
94 streaming media - while DirectShow is slightly more flexible in that regard.
96 @section class_mediactrl_operation Operation
98 When wxMediaCtrl plays a file, it plays until the stop position is reached
99 (currently the end of the file/stream). Right before it hits the end of the stream,
100 it fires off a @c EVT_MEDIA_STOP event to its parent window, at which point the event
101 handler can choose to veto the event, preventing the stream from actually stopping.
106 //connect to the media event
107 this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction)
108 (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop);
111 void MyFrame::OnMediaStop(const wxMediaEvent& evt)
115 m_mediactrl->SetPosition(
116 m_mediactrl->GetDuration() << 1
123 When wxMediaCtrl stops, either by the @c EVT_MEDIA_STOP not being vetoed, or by manually
124 calling Stop(), where it actually stops is not at the beginning, rather, but at the beginning
125 of the stream. That is, when it stops and play is called, playback is gauranteed to start at
126 the beginning of the media. This is because some streams are not seekable, and when stop is
127 called on them they return to the beginning, thus wxMediaCtrl tries to keep consistant for all types
130 Note that when changing the state of the media through Play() and other methods, the media may not
131 actually be in the @c wxMEDIASTATE_PLAYING, for example. If you are relying on the media being in
132 certain state catch the event relevant to the state. See wxMediaEvent for the kinds of events that
135 @section class_mediactrl_video_size Video size
137 By default, wxMediaCtrl will scale the size of the video to the requested amount passed to either
138 its constructor or Create(). After calling Load or performing an equivilant operation, you can
139 subsequently obtain the "real" size of the video (if there is any) by calling GetBestSize().
140 Note that the actual result on the display will be slightly different when ShowPlayerControls is
141 activated and the actual video size will be less then specified due to the extra controls provided
142 by the native toolkit. In addition, the backend may modify GetBestSize() to include the size of
143 the extra controls - so if you want the real size of the video just disable ShowPlayerControls().
145 The idea with setting GetBestSize() to the size of the video is that GetBestSize() is a wxWindow-derived
146 function that is called when sizers on a window recalculate. What this means is that if you use sizers
147 by default the video will show in its original size without any extra assistance needed from the user.
149 @section class_mediactrl_player_controls Player controls
151 Normally, when you use wxMediaCtrl it is just a window for the video to play in. However, some toolkits
152 have their own media player interface. For example, QuickTime generally has a bar below the video with
153 a slider. A special feature available to wxMediaCtrl, you can use the toolkits interface instead of making
154 your own by using the ShowPlayerControls() function. There are several options for the flags parameter,
155 with the two general flags being @c wxMEDIACTRLPLAYERCONTROLS_NONE which turns off the native interface,
156 and @c wxMEDIACTRLPLAYERCONTROLS_DEFAULT which lets wxMediaCtrl decide what native controls on the interface.
157 Be sure to review the caveats outlined in Video size before doing so.
159 @section class_mediactrl_choosing_backend Choosing a backend
161 Generally, you should almost certainly leave this part up to wxMediaCtrl - but if you need a certain backend
162 for a particular reason, such as QuickTime for playing .mov files, all you need to do to choose a specific
163 backend is to pass the name of the backend class to Create().
165 The following are valid backend identifiers:
168 @row2col{@b wxMEDIABACKEND_DIRECTSHOW, Use ActiveMovie/DirectShow. Uses the native ActiveMovie (I.E. DirectShow) control. Default backend on Windows and supported by nearly all Windows versions, even some Windows CE versions. May display a windows media player logo while inactive.}
169 @row2col{@b wxMEDIABACKEND_QUICKTIME, Use QuickTime. Mac Only. WARNING: May not working correctly embedded in a wxNotebook.}
170 @row2col{@b wxMEDIABACKEND_GSTREAMER, Use GStreamer. Unix Only. Requires GStreamer 0.8 along with at the very least the xvimagesink, xoverlay, and gst-play modules of gstreamer to function. You need the correct modules to play the relavant files, for example the mad module to play mp3s, etc.}
171 @row2col{@b wxMEDIABACKEND_WMP10, Uses Windows Media Player 10 (Windows only) - works on mobile machines with Windows Media Player 10 and desktop machines with either Windows Media Player 9 or 10}
174 Note that other backends such as wxMEDIABACKEND_MCI can now be found at wxCode(http://wxcode.sourceforge.net/).
176 @section class_mediactrl_creating_backend Creating a backend
178 Creating a backend for wxMediaCtrl is a rather simple process. Simply derive from wxMediaBackendCommonBase
179 and implement the methods you want. The methods in wxMediaBackend correspond to those in wxMediaCtrl except
180 for CreateControl which does the actual creation of the control, in cases where a custom control is not
181 needed you may simply call wxControl::Create().
183 You need to make sure to use the @c DECLARE_CLASS and @c IMPLEMENT_CLASS macros.
185 The only real tricky part is that you need to make sure the file in compiled in, which if there are
186 just backends in there will not happen and you may need to use a force link hack
187 (see http://www.wxwidgets.org/wiki/index.php/RTTI).
189 This is a rather simple example of how to create a backend in the wxActiveXContainer documentation.
191 class wxMediaCtrl
: public wxControl
195 Default constructor - you MUST call Create before calling any other methods of wxMediaCtrl.
200 Constructor that calls Create(). You may prefer to call Create() directly to check
201 to see if wxMediaCtrl is available on the system.
204 parent of this control. Must not be @NULL.
208 If not empty, the path of a file to open.
210 Position to put control at.
212 Size to put the control at and to stretch movie to.
216 Name of backend you want to use, leave blank to make
217 wxMediaCtrl figure it out.
223 wxMediaCtrl(wxWindow
* parent
, wxWindowID id
, const wxString
& fileName
= wxT(""),
224 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
225 long style
= 0, const wxString
& szBackend
= wxT(""),
226 const wxValidator
& validator
= wxDefaultValidator
,
227 const wxString
& name
= wxPanelNameStr
);
231 Creates this control. Returns @false if it can't load the movie located at @a fileName
232 or it cannot load one of its native backends.
234 If you specify a file to open via @a fileName and you don't specify a backend to
235 use, wxMediaCtrl tries each of its backends until one that can render the path referred to
236 by @a fileName can be found.
239 parent of this control. Must not be @NULL.
243 If not empty, the path of a file to open.
245 Position to put control at.
247 Size to put the control at and to stretch movie to.
251 Name of backend you want to use, leave blank to make
252 wxMediaCtrl figure it out.
258 bool Create(wxWindow
* parent
, wxWindowID id
, const wxString
& fileName
= wxT(""),
259 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
260 long style
= 0, const wxString
& szBackend
= wxT(""),
261 const wxValidator
& validator
= wxDefaultValidator
,
262 const wxString
& name
= wxPanelNameStr
);
265 Obtains the best size relative to the original/natural size of the
266 video, if there is any. See @ref class_mediactrl_video_size for more information.
268 wxSize
GetBestSize();
271 Obtains the playback rate, or speed of the media. @c 1.0 represents normal
272 speed, while @c 2.0 represents twice the normal speed of the media, for
273 example. Not supported on the GStreamer (Unix) backend.
275 @return zero on failure.
277 double GetPlaybackrate();
280 Obtains the state the playback of the media is in -
283 @row2col{wxMEDIASTATE_STOPPED, The movie has stopped.}
284 @row2col{wxMEDIASTATE_PAUSED, The movie is paused.}
285 @row2col{wxMEDIASTATE_PLAYING, The movie is currently playing.}
288 wxMediaCtrlState
GetState();
291 Gets the volume of the media from a 0.0 to 1.0 range.
293 @note Due to rounding and other errors the value returned may not be the exact value
299 Obtains the length - the total amount of time the movie has in milliseconds.
301 wxFileOffset
Length();
304 Loads the file that fileName refers to. Returns @false if loading fails.
306 bool Load(const wxString
& fileName
);
309 Loads the location that uri refers to. Note that this is very implementation-dependant,
310 although HTTP URI/URLs are generally supported, for example. Returns @false if loading fails.
312 bool Load(const wxURI
& uri
);
315 Loads the location that @c uri refers to with the proxy @c proxy.
316 Not implemented on most backends so it should be called with caution.
317 Returns @false if loading fails.
319 bool Load(const wxURI
& uri
, const wxURI
& proxy
);
322 Same as Load(const wxURI& uri). Kept for wxPython compatibility.
324 bool LoadURI(const wxURI
& uri
);
327 Same as Load(const wxURI& uri, const wxURI& proxy). Kept for wxPython compatibility.
329 bool LoadURIWithProxy(const wxURI
& uri
, const wxURI
& proxy
);
332 Pauses playback of the movie.
337 Resumes playback of the movie.
342 Seeks to a position within the movie.
344 @todo Document the wxSeekMode parameter @a mode, and perhaps also the
345 wxFileOffset and wxSeekMode themselves.
347 wxFileOffset
Seek(wxFileOffset where
, wxSeekMode mode
);
350 Sets the playback rate, or speed of the media, to that referred by @a dRate.
351 @c 1.0 represents normal speed, while @c 2.0 represents twice the normal
352 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
353 Returns @true if successful.
355 bool SetPlaybackRate(double dRate
);
358 Sets the volume of the media from a 0.0 to 1.0 range to that referred
359 by @c dVolume. @c 1.0 represents full volume, while @c 0.5
360 represents half (50 percent) volume, for example.
362 @note The volume may not be exact due to conversion and rounding errors,
363 although setting the volume to full or none is always exact.
364 Returns @true if successful.
366 bool SetVolume(double dVolume
);
369 A special feature to wxMediaCtrl. Applications using native toolkits such as
370 QuickTime usually have a scrollbar, play button, and more provided to
371 them by the toolkit. By default wxMediaCtrl does not do this. However, on
372 the directshow and quicktime backends you can show or hide the native controls
373 provided by the underlying toolkit at will using ShowPlayerControls(). Simply
374 calling the function with default parameters tells wxMediaCtrl to use the
375 default controls provided by the toolkit. The function takes a
376 wxMediaCtrlPlayerControls enumeration, please see available show modes there.
378 For more see @ref class_mediactrl_player_controls.
380 Currently only implemented on the QuickTime and DirectShow backends.
381 The function returns @true on success.
383 bool ShowPlayerControls(wxMediaCtrlPlayerControls flags
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
);
388 See @ref class_mediactrl_operation for an overview of how stopping works.
393 Obtains the current position in time within the movie in milliseconds.