1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxMediaEvent class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 @wxheader{mediactrl.h}
13 Event wxMediaCtrl uses.
18 class wxMediaEvent
: public wxNotifyEvent
27 @wxheader{mediactrl.h}
29 wxMediaCtrl is a class for displaying types of
30 media, such as videos, audio files, natively through native codecs.
32 wxMediaCtrl uses native backends to render media, for example on Windows
33 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
42 class wxMediaCtrl
: public wxControl
50 @param pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
53 const wxString& szBackend = wxT(""),
54 const wxValidatorvalidator = wxDefaultValidator,
55 const wxString& name = wxPanelNameStr
58 Constructor that calls Create. You may prefer to call Create directly to check
59 to see if wxMediaCtrl is available on the system.
62 parent of this control. Must not be @NULL.
68 If not empty, the path of a file to open.
71 Position to put control at.
74 Size to put the control at and to stretch movie to.
80 Name of backend you want to use, leave blank to make
81 wxMediaCtrl figure it out.
90 wxMediaCtrl(wxWindow
* parent
, wxWindowID id
);
94 Generally, you should almost certainly leave this part up to
95 wxMediaCtrl - but if you need a certain backend for a particular
96 reason, such as QuickTime for playing .mov files, all you need
97 to do to choose a specific backend is to pass the
98 name of the backend class to
101 The following are valid backend identifiers -
103 @b wxMEDIABACKEND_DIRECTSHOW
107 Use ActiveMovie/DirectShow. Uses the native ActiveMovie
108 (I.E. DirectShow) control. Default backend on Windows and
109 supported by nearly all Windows versions, even some
110 Windows CE versions. May display a windows media player
113 @b wxMEDIABACKEND_QUICKTIME
116 Use QuickTime. Mac Only.
117 WARNING: May not working correctly embedded in a wxNotebook.
120 @b wxMEDIABACKEND_GSTREAMER
123 Use GStreamer. Unix Only. Requires GStreamer 0.8 along
124 with at the very least the xvimagesink, xoverlay, and
125 gst-play modules of gstreamer to function. You need the correct
126 modules to play the relavant files, for example the mad module
129 @b wxMEDIABACKEND_WMP10
132 Uses Windows Media Player 10 (Windows only) - works on mobile
133 machines with Windows Media Player 10 and desktop machines with
134 either Windows Media Player 9 or 10
136 Note that other backends such as wxMEDIABACKEND_MCI can now be
145 @param pos = wxDefaultPosition,
146 const wxSize& size = wxDefaultSize,
148 const wxString& szBackend = wxT(""),
149 const wxValidatorvalidator = wxDefaultValidator,
150 const wxString& name = wxPanelNameStr
153 Creates this control. Returns @false if it can't load the movie located at
154 fileName or it cannot load one of its native backends.
156 If you specify a file to open via fileName and you don't specify a backend to
157 use, wxMediaCtrl tries each of its backends until one that can render the path referred to by fileName can be found.
160 parent of this control. Must not be @NULL.
166 If not empty, the path of a file to open.
169 Position to put control at.
172 Size to put the control at and to stretch movie to.
178 Name of backend you want to use, leave blank to make
179 wxMediaCtrl figure it out.
187 bool Create(wxWindow
* parent
, wxWindowID id
);
190 Creating a backend for wxMediaCtrl is a rather simple process. Simply derive
191 from wxMediaBackendCommonBase and implement the methods you want. The methods
192 in wxMediaBackend correspond to those in wxMediaCtrl except for CreateControl
193 which does the actual creation of the control, in cases where a custom control
194 is not needed you may simply call wxControl::Create.
196 You need to make sure to use the DECLARE_CLASS and IMPLEMENT_CLASS macros.
198 The only real tricky part is that you need to make sure the file in compiled
199 in, which if there are just backends in there will not happen and you may need
200 to use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI).
202 This is a rather simple example of how to create a backend in the
203 wxActiveXContainer documentation.
208 Obtains the best size relative to the original/natural size of the
209 video, if there is any. See @ref overview_videosizewxmediactrl "Video size"
210 for more information.
212 wxSize
GetBestSize();
215 Obtains the playback rate, or speed of the media. @c 1.0 represents normal
216 speed, while @c 2.0 represents twice the normal speed of the media, for
217 example. Not supported on the GStreamer (Unix) backend.
218 Returns 0 on failure.
220 double GetPlaybackrate();
223 Obtains the state the playback of the media is in -
226 @b wxMEDIASTATE_STOPPED
229 The movie has stopped.
231 @b wxMEDIASTATE_PAUSED
236 @b wxMEDIASTATE_PLAYING
239 The movie is currently playing.
241 wxMediaCtrlState
GetState();
244 Gets the volume of the media from a 0.0 to 1.0 range. Note that due to rounding
245 and other errors this may not be the exact value sent to SetVolume.
250 Obtains the length - the total amount of time the movie has in milliseconds.
252 wxFileOffset
Length();
255 Loads the location that @c uri refers to with the proxy @c proxy. Not
256 implemented on most backends so it should be called with caution. Returns @false if loading fails.
258 bool Load(const wxURI
& uri
, const wxURI
& proxy
);
261 Same as @ref loaduri() Load. Kept for wxPython compatability.
263 bool LoadURI(const wxURI
& uri
);
266 Same as @ref loaduriwithproxy() Load. Kept for wxPython compatability.
268 bool LoadURIWithProxy(const wxURI
& uri
, const wxURI
& proxy
);
271 When wxMediaCtrl plays a file, it plays until the stop position
272 is reached (currently the end of the file/stream). Right before
273 it hits the end of the stream, it fires off a EVT_MEDIA_STOP
274 event to its parent window, at which point the event handler
275 can choose to veto the event, preventing the stream from actually
280 When wxMediaCtrl stops, either by the EVT_MEDIA_STOP not being
281 vetoed, or by manually calling
282 Stop(), where it actually
283 stops is not at the beginning, rather, but at the beginning of
284 the stream. That is, when it stops and play is called, playback
285 is gauranteed to start at the beginning of the media. This is
286 because some streams are not seekable, and when stop is called
287 on them they return to the beginning, thus wxMediaCtrl tries
288 to keep consistant for all types of media.
290 Note that when changing the state of the media through Play()
291 and other methods, the media may not actually be in the
292 wxMEDIASTATE_PLAYING, for example. If you are relying on the
293 media being in certain state catch the event relevant to the state.
294 See wxMediaEvent for the kinds of events
300 Pauses playback of the movie.
305 Resumes playback of the movie.
310 Normally, when you use wxMediaCtrl it is just a window for the video to
311 play in. However, some toolkits have their own media player interface.
312 For example, QuickTime generally has a bar below the video with a slider.
313 A special feature available to wxMediaCtrl, you can use the toolkit's interface
315 making your own by using the ShowPlayerControls()
316 function. There are several options for the flags parameter, with
317 the two general flags being wxMEDIACTRLPLAYERCONTROLS_NONE which turns off
318 the native interface, and wxMEDIACTRLPLAYERCONTROLS_DEFAULT which lets
319 wxMediaCtrl decide what native controls on the interface. Be sure to review
320 the caveats outlined in @ref overview_videosizewxmediactrl "Video size" before
326 Depending upon the backend, wxMediaCtrl can render
327 and display pretty much any kind of media that the native system can -
328 such as an image, mpeg video, or mp3 (without license restrictions -
329 since it relies on native system calls that may not technically
330 have mp3 decoding available, for example, it falls outside the
331 realm of licensing restrictions).
333 For general operation, all you need to do is call
334 Load() to load the file
335 you want to render, catch the EVT_MEDIA_LOADED event,
337 to show the video/audio of the media in that event.
339 More complex operations are generally more heavily dependant on the
340 capabilities of the backend. For example, QuickTime cannot set
341 the playback rate of certain streaming media - while DirectShow is
342 slightly more flexible in that regard.
347 Seeks to a position within the movie.
349 wxFileOffset
Seek(wxFileOffset where
, wxSeekMode mode
);
352 Sets the playback rate, or speed of the media, to that referred by @c dRate.
353 @c 1.0 represents normal speed, while @c 2.0 represents twice the normal
354 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
355 Returns @true if successful.
357 bool SetPlaybackRate(double dRate
);
360 Sets the volume of the media from a 0.0 to 1.0 range to that referred
361 by @c dVolume. @c 1.0 represents full volume, while @c 0.5
362 represents half (50 percent) volume, for example. Note that this may not be
363 exact due to conversion and rounding errors, although setting the volume to
364 full or none is always exact. 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 @c wxMediaCtrlPlayerControls enumeration as follows:
379 @b wxMEDIACTRLPLAYERCONTROLS_NONE
382 No controls. return wxMediaCtrl to it's default state.
384 @b wxMEDIACTRLPLAYERCONTROLS_STEP
387 Step controls like fastfoward, step one frame etc.
389 @b wxMEDIACTRLPLAYERCONTROLS_VOLUME
392 Volume controls like the speaker icon, volume slider, etc.
394 @b wxMEDIACTRLPLAYERCONTROLS_DEFAULT
397 Default controls for the toolkit. Currently a typedef for
398 wxMEDIACTRLPLAYERCONTROLS_STEP and wxMEDIACTRLPLAYERCONTROLS_VOLUME.
400 For more see @ref overview_playercontrolswxmediactrl "Player controls".
402 only implemented on the QuickTime and DirectShow backends. The function
403 returns @true on success.
405 bool ShowPlayerControls(wxMediaCtrlPlayerControls flags
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
);
410 See Operation for an overview of how
416 Obtains the current position in time within the movie in milliseconds.
421 By default, wxMediaCtrl will scale the size of the video to the
422 requested amount passed to either it's constructor or Create().
423 After calling Load or performing an equivilant operation, you
424 can subsequently obtain the "real" size of the video (if there
425 is any) by calling GetBestSize(). Note that the actual result
426 on the display will be slightly different when ShowPlayerControls
427 is activated and the actual video size will be less then
428 specified due to the extra controls provided by the native toolkit.
429 In addition, the backend may modify GetBestSize() to include the
430 size of the extra controls - so if you want the real size of the
431 video just disable ShowPlayerControls().
433 The idea with setting GetBestSize to the size of the video is
434 that GetBestSize is a wxWindow-derived function that is called
435 when sizers on a window recalculate. What this means is that
436 if you use sizers by default the video will show in it's
437 original size without any extra assistance needed from the user.