1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMediaEvent
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 Event wxMediaCtrl uses.
17 class wxMediaEvent
: public wxNotifyEvent
28 wxMediaCtrl is a class for displaying types of
29 media, such as videos, audio files, natively through native codecs.
31 wxMediaCtrl uses native backends to render media, for example on Windows
32 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
40 class wxMediaCtrl
: public wxControl
48 @param pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
51 const wxString& szBackend = wxT(""),
52 const wxValidatorvalidator = wxDefaultValidator,
53 const wxString& name = wxPanelNameStr
56 Constructor that calls Create. You may prefer to call Create directly to check
57 to see if wxMediaCtrl is available on the system.
60 parent of this control. Must not be @NULL.
64 If not empty, the path of a file to open.
66 Position to put control at.
68 Size to put the control at and to stretch movie to.
72 Name of backend you want to use, leave blank to make
73 wxMediaCtrl figure it out.
80 wxMediaCtrl(wxWindow
* parent
, wxWindowID id
) const;
84 Generally, you should almost certainly leave this part up to
85 wxMediaCtrl - but if you need a certain backend for a particular
86 reason, such as QuickTime for playing .mov files, all you need
87 to do to choose a specific backend is to pass the
88 name of the backend class to
90 The following are valid backend identifiers -
92 @b wxMEDIABACKEND_DIRECTSHOW
95 Use ActiveMovie/DirectShow. Uses the native ActiveMovie
96 (I.E. DirectShow) control. Default backend on Windows and
97 supported by nearly all Windows versions, even some
98 Windows CE versions. May display a windows media player
101 @b wxMEDIABACKEND_QUICKTIME
103 Use QuickTime. Mac Only.
104 WARNING: May not working correctly embedded in a wxNotebook.
106 @b wxMEDIABACKEND_GSTREAMER
108 Use GStreamer. Unix Only. Requires GStreamer 0.8 along
109 with at the very least the xvimagesink, xoverlay, and
110 gst-play modules of gstreamer to function. You need the correct
111 modules to play the relavant files, for example the mad module
114 @b wxMEDIABACKEND_WMP10
116 Uses Windows Media Player 10 (Windows only) - works on mobile
117 machines with Windows Media Player 10 and desktop machines with
118 either Windows Media Player 9 or 10
120 Note that other backends such as wxMEDIABACKEND_MCI can now be
129 @param pos = wxDefaultPosition,
130 const wxSize& size = wxDefaultSize,
132 const wxString& szBackend = wxT(""),
133 const wxValidatorvalidator = wxDefaultValidator,
134 const wxString& name = wxPanelNameStr
137 Creates this control. Returns @false if it can't load the movie located at
138 fileName or it cannot load one of its native backends.
140 If you specify a file to open via fileName and you don't specify a backend to
141 use, wxMediaCtrl tries each of its backends until one that can render the path referred to by fileName can be found.
144 parent of this control. Must not be @NULL.
148 If not empty, the path of a file to open.
150 Position to put control at.
152 Size to put the control at and to stretch movie to.
156 Name of backend you want to use, leave blank to make
157 wxMediaCtrl figure it out.
163 bool Create(wxWindow
* parent
, wxWindowID id
) const;
166 Creating a backend for wxMediaCtrl is a rather simple process. Simply derive
167 from wxMediaBackendCommonBase and implement the methods you want. The methods
168 in wxMediaBackend correspond to those in wxMediaCtrl except for CreateControl
169 which does the actual creation of the control, in cases where a custom control
170 is not needed you may simply call wxControl::Create.
171 You need to make sure to use the DECLARE_CLASS and IMPLEMENT_CLASS macros.
172 The only real tricky part is that you need to make sure the file in compiled
173 in, which if there are just backends in there will not happen and you may need
174 to use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI).
175 This is a rather simple example of how to create a backend in the
176 wxActiveXContainer documentation.
181 Obtains the best size relative to the original/natural size of the
182 video, if there is any. See @ref overview_videosizewxmediactrl "Video size"
183 for more information.
185 wxSize
GetBestSize();
188 Obtains the playback rate, or speed of the media. @c 1.0 represents normal
189 speed, while @c 2.0 represents twice the normal speed of the media, for
190 example. Not supported on the GStreamer (Unix) backend.
191 Returns 0 on failure.
193 double GetPlaybackrate();
196 Obtains the state the playback of the media is in -
198 @b wxMEDIASTATE_STOPPED
200 The movie has stopped.
202 @b wxMEDIASTATE_PAUSED
206 @b wxMEDIASTATE_PLAYING
208 The movie is currently playing.
210 wxMediaCtrlState
GetState();
213 Gets the volume of the media from a 0.0 to 1.0 range. Note that due to rounding
214 and other errors this may not be the exact value sent to SetVolume.
219 Obtains the length - the total amount of time the movie has in milliseconds.
221 wxFileOffset
Length();
224 Loads the location that @c uri refers to with the proxy @c proxy. Not
225 implemented on most backends so it should be called with caution. Returns @false if loading fails.
227 bool Load(const wxURI
& uri
, const wxURI
& proxy
);
230 Same as @ref loaduri() Load. Kept for wxPython compatability.
232 bool LoadURI(const wxURI
& uri
);
235 Same as @ref loaduriwithproxy() Load. Kept for wxPython compatability.
237 bool LoadURIWithProxy(const wxURI
& uri
, const wxURI
& proxy
);
240 When wxMediaCtrl plays a file, it plays until the stop position
241 is reached (currently the end of the file/stream). Right before
242 it hits the end of the stream, it fires off a EVT_MEDIA_STOP
243 event to its parent window, at which point the event handler
244 can choose to veto the event, preventing the stream from actually
248 When wxMediaCtrl stops, either by the EVT_MEDIA_STOP not being
249 vetoed, or by manually calling
250 Stop(), where it actually
251 stops is not at the beginning, rather, but at the beginning of
252 the stream. That is, when it stops and play is called, playback
253 is gauranteed to start at the beginning of the media. This is
254 because some streams are not seekable, and when stop is called
255 on them they return to the beginning, thus wxMediaCtrl tries
256 to keep consistant for all types of media.
257 Note that when changing the state of the media through Play()
258 and other methods, the media may not actually be in the
259 wxMEDIASTATE_PLAYING, for example. If you are relying on the
260 media being in certain state catch the event relevant to the state.
261 See wxMediaEvent for the kinds of events
267 Pauses playback of the movie.
272 Resumes playback of the movie.
277 Normally, when you use wxMediaCtrl it is just a window for the video to
278 play in. However, some toolkits have their own media player interface.
279 For example, QuickTime generally has a bar below the video with a slider.
280 A special feature available to wxMediaCtrl, you can use the toolkit's interface
282 making your own by using the ShowPlayerControls()
283 function. There are several options for the flags parameter, with
284 the two general flags being wxMEDIACTRLPLAYERCONTROLS_NONE which turns off
285 the native interface, and wxMEDIACTRLPLAYERCONTROLS_DEFAULT which lets
286 wxMediaCtrl decide what native controls on the interface. Be sure to review
287 the caveats outlined in @ref overview_videosizewxmediactrl "Video size" before
293 Depending upon the backend, wxMediaCtrl can render
294 and display pretty much any kind of media that the native system can -
295 such as an image, mpeg video, or mp3 (without license restrictions -
296 since it relies on native system calls that may not technically
297 have mp3 decoding available, for example, it falls outside the
298 realm of licensing restrictions).
299 For general operation, all you need to do is call
300 Load() to load the file
301 you want to render, catch the EVT_MEDIA_LOADED event,
303 to show the video/audio of the media in that event.
304 More complex operations are generally more heavily dependant on the
305 capabilities of the backend. For example, QuickTime cannot set
306 the playback rate of certain streaming media - while DirectShow is
307 slightly more flexible in that regard.
312 Seeks to a position within the movie.
314 wxFileOffset
Seek(wxFileOffset where
, wxSeekMode mode
);
317 Sets the playback rate, or speed of the media, to that referred by @c dRate.
318 @c 1.0 represents normal speed, while @c 2.0 represents twice the normal
319 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
320 Returns @true if successful.
322 bool SetPlaybackRate(double dRate
);
325 Sets the volume of the media from a 0.0 to 1.0 range to that referred
326 by @c dVolume. @c 1.0 represents full volume, while @c 0.5
327 represents half (50 percent) volume, for example. Note that this may not be
328 exact due to conversion and rounding errors, although setting the volume to
329 full or none is always exact. Returns @true if successful.
331 bool SetVolume(double dVolume
);
334 A special feature to wxMediaCtrl. Applications using native toolkits such as
335 QuickTime usually have a scrollbar, play button, and more provided to
336 them by the toolkit. By default wxMediaCtrl does not do this. However, on
337 the directshow and quicktime backends you can show or hide the native controls
338 provided by the underlying toolkit at will using ShowPlayerControls. Simply
339 calling the function with default parameters tells wxMediaCtrl to use the
340 default controls provided by the toolkit. The function takes a
341 @c wxMediaCtrlPlayerControls enumeration as follows:
343 @b wxMEDIACTRLPLAYERCONTROLS_NONE
345 No controls. return wxMediaCtrl to it's default state.
347 @b wxMEDIACTRLPLAYERCONTROLS_STEP
349 Step controls like fastfoward, step one frame etc.
351 @b wxMEDIACTRLPLAYERCONTROLS_VOLUME
353 Volume controls like the speaker icon, volume slider, etc.
355 @b wxMEDIACTRLPLAYERCONTROLS_DEFAULT
357 Default controls for the toolkit. Currently a typedef for
358 wxMEDIACTRLPLAYERCONTROLS_STEP and wxMEDIACTRLPLAYERCONTROLS_VOLUME.
360 For more see @ref overview_playercontrolswxmediactrl "Player controls".
362 only implemented on the QuickTime and DirectShow backends. The function
363 returns @true on success.
365 bool ShowPlayerControls(wxMediaCtrlPlayerControls flags
= wxMEDIACTRLPLAYERCONTROLS_DEFAULT
);
369 See Operation() for an overview of how
375 Obtains the current position in time within the movie in milliseconds.
380 By default, wxMediaCtrl will scale the size of the video to the
381 requested amount passed to either it's constructor or Create().
382 After calling Load or performing an equivilant operation, you
383 can subsequently obtain the "real" size of the video (if there
384 is any) by calling GetBestSize(). Note that the actual result
385 on the display will be slightly different when ShowPlayerControls
386 is activated and the actual video size will be less then
387 specified due to the extra controls provided by the native toolkit.
388 In addition, the backend may modify GetBestSize() to include the
389 size of the extra controls - so if you want the real size of the
390 video just disable ShowPlayerControls().
391 The idea with setting GetBestSize to the size of the video is
392 that GetBestSize is a wxWindow-derived function that is called
393 when sizers on a window recalculate. What this means is that
394 if you use sizers by default the video will show in it's
395 original size without any extra assistance needed from the user.