]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/mediactrl.tex
added the mention of library in which each class is defined to the documentation...
[wxWidgets.git] / docs / latex / wx / mediactrl.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %% Name: mediactrl.tex
3 %% Purpose: wxMediaCtrl docs
4 %% Author: Ryan Norton <wxprojects@comcast.net>
5 %% Modified by:
6 %% Created: 11/7/2004
7 %% RCS-ID: $Id$
8 %% Copyright: (c) Ryan Norton
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \section{\class{wxMediaCtrl}}\label{wxmediactrl}
13
14 wxMediaCtrl is a class for displaying types of
15 media, such as videos, audio files, natively through native codecs.
16
17 wxMediaCtrl uses native backends to render media, for example on Windows
18 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
19 QuickTime backend.
20
21 \wxheading{See also}
22
23 \helpref{wxMediaEvent}{wxmediaevent}
24
25 \wxheading{Derived from}
26
27 \helpref{wxControl}{wxcontrol}
28
29 \wxheading{Include files}
30
31 <wx/mediactrl.h>
32
33 \wxheading{Library}
34
35 \helpref{wxMedia}{librarieslist}
36
37 \latexignore{\rtfignore{\wxheading{Members}}}
38
39
40 \membersection{Rendering media}\label{renderingmediawxmediactrl}
41
42 Depending upon the backend, wxMediaCtrl can render
43 and display pretty much any kind of media that the native system can -
44 such as an image, mpeg video, or mp3 (without license restrictions -
45 since it relies on native system calls that may not technically
46 have mp3 decoding available, for example, it falls outside the
47 realm of licensing restrictions).
48
49 For general operation, all you need to do is call
50 \helpref{wxMediaCtrl::Load}{wxmediactrlload} to load the file
51 you want to render, catch the EVT\_MEDIA\_LOADED event,
52 and then call \helpref{wxMediaCtrl::Play}{wxmediactrlplay}
53 to show the video/audio of the media in that event.
54
55 More complex operations are generally more heavily dependant on the
56 capabilities of the backend. For example, QuickTime cannot set
57 the playback rate of certain streaming media - while DirectShow is
58 slightly more flexible in that regard.
59
60
61 \membersection{Operation}\label{operationwxmediactrl}
62
63 When wxMediaCtrl plays a file, it plays until the stop position
64 is reached (currently the end of the file/stream). Right before
65 it hits the end of the stream, it fires off a EVT\_MEDIA\_STOP
66 event to its parent window, at which point the event handler
67 can choose to veto the event, preventing the stream from actually
68 stopping.
69
70 Example:
71 \begin{verbatim}
72 //connect to the media event
73 this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction)
74 (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop);
75
76 //...
77 void MyFrame::OnMediaStop(const wxMediaEvent& evt)
78 {
79 if(bUserWantsToSeek)
80 {
81 m_mediactrl->SetPosition(
82 m_mediactrl->GetDuration() << 1
83 );
84 evt.Veto();
85 }
86 }
87 \end{verbatim}
88
89 When wxMediaCtrl stops, either by the EVT\_MEDIA\_STOP not being
90 vetoed, or by manually calling
91 \helpref{wxMediaCtrl::Stop}{wxmediactrlstop}, where it actually
92 stops is not at the beginning, rather, but at the beginning of
93 the stream. That is, when it stops and play is called, playback
94 is gauranteed to start at the beginning of the media. This is
95 because some streams are not seekable, and when stop is called
96 on them they return to the beginning, thus wxMediaCtrl tries
97 to keep consistant for all types of media.
98
99 Note that when changing the state of the media through Play()
100 and other methods, the media may not actually be in the
101 wxMEDIASTATE\_PLAYING, for example. If you are relying on the
102 media being in certain state catch the event relevant to the state.
103 See \helpref{wxMediaEvent}{wxmediaevent} for the kinds of events
104 that you can catch.
105
106
107 \membersection{Video size}\label{videosizewxmediactrl}
108
109 By default, wxMediaCtrl will scale the size of the video to the
110 requested amount passed to either it's constructor or Create().
111 After calling Load or performing an equivilant operation, you
112 can subsequently obtain the "real" size of the video (if there
113 is any) by calling GetBestSize(). Note that the actual result
114 on the display will be slightly different when ShowPlayerControls
115 is activated and the actual video size will be less then
116 specified due to the extra controls provided by the native toolkit.
117 In addition, the backend may modify GetBestSize() to include the
118 size of the extra controls - so if you want the real size of the
119 video just disable ShowPlayerControls().
120
121 The idea with setting GetBestSize to the size of the video is
122 that GetBestSize is a wxWindow-derived function that is called
123 when sizers on a window recalculate. What this means is that
124 if you use sizers by default the video will show in it's
125 original size without any extra assistance needed from the user.
126
127
128 \membersection{Player controls}\label{playercontrolswxmediactrl}
129
130 Normally, when you use wxMediaCtrl it is just a window for the video to
131 play in. However, some toolkits have their own media player interface.
132 For example, QuickTime generally has a bar below the video with a slider.
133 A special feature available to wxMediaCtrl, you can use the toolkit's interface instead of
134 making your own by using the \helpref{ShowPlayerControls()}{wxmediactrlshowplayercontrols}
135 function. There are several options for the flags parameter, with
136 the two general flags being wxMEDIACTRLPLAYERCONTROLS\_NONE which turns off
137 the native interface, and wxMEDIACTRLPLAYERCONTROLS\_DEFAULT which lets
138 wxMediaCtrl decide what native controls on the interface. Be sure to review
139 the caveats outlined in \helpref{Video size}{videosizewxmediactrl} before
140 doing so.
141
142
143 \membersection{Choosing a backend}\label{choosingbackendwxmediactrl}
144
145 Generally, you should almost certainly leave this part up to
146 wxMediaCtrl - but if you need a certain backend for a particular
147 reason, such as QuickTime for playing .mov files, all you need
148 to do to choose a specific backend is to pass the
149 name of the backend class to
150 \helpref{wxMediaCtrl::Create}{wxmediactrlcreate}.
151
152 The following are valid backend identifiers -
153 \twocolwidtha{7cm}
154 \begin{twocollist}\itemsep=0pt
155 \twocolitem{{\bf wxMEDIABACKEND\_DIRECTSHOW}}{
156 Use ActiveMovie/DirectShow. Uses the native ActiveMovie
157 (I.E. DirectShow) control. Default backend on Windows and
158 supported by nearly all Windows versions, even some
159 Windows CE versions. May display a windows media player
160 logo while inactive. }
161 \twocolitem{{\bf wxMEDIABACKEND\_QUICKTIME}}{
162 Use QuickTime. Mac Only.
163 WARNING: May not working correctly embedded in a wxNotebook.
164 }
165 \twocolitem{{\bf wxMEDIABACKEND\_GSTREAMER}}{
166 Use GStreamer. Unix Only. Requires GStreamer 0.8 along
167 with at the very least the xvimagesink, xoverlay, and
168 gst-play modules of gstreamer to function. You need the correct
169 modules to play the relavant files, for example the mad module
170 to play mp3s, etc.}
171 \twocolitem{{\bf wxMEDIABACKEND\_WMP10}}{
172 Uses Windows Media Player 10 (Windows only) - works on mobile
173 machines with Windows Media Player 10 and desktop machines with
174 either Windows Media Player 9 or 10
175 }
176 \end{twocollist}
177
178 Note that other backends such as wxMEDIABACKEND\_MCI can now be
179 found at wxCode.
180
181 \membersection{Creating a backend}\label{creatingabackendwxmediactrl}
182
183 Creating a backend for wxMediaCtrl is a rather simple process. Simply derive
184 from wxMediaBackendCommonBase and implement the methods you want. The methods
185 in wxMediaBackend correspond to those in wxMediaCtrl except for CreateControl
186 which does the actual creation of the control, in cases where a custom control
187 is not needed you may simply call wxControl::Create.
188
189 You need to make sure to use the DECLARE\_CLASS and IMPLEMENT\_CLASS macros.
190
191 The only real tricky part is that you need to make sure the file in compiled
192 in, which if there are just backends in there will not happen and you may need
193 to use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI).
194
195 This is a rather simple example of how to create a backend in the
196 \helpref{wxActiveXContainer}{wxactivexcontainer} documentation.
197
198 \membersection{wxMediaCtrl::wxMediaCtrl}\label{wxmediactrlwxmediactrl}
199
200 \func{}{wxMediaCtrl}{\void}
201
202 Default constructor - you \tt{must} call Create before calling any other methods
203 of wxMediaCtrl.
204
205 \func{}{wxMediaCtrl}{
206 \param{wxWindow* }{parent},
207 \param{wxWindowID }{id},
208 \param{const wxString\& }{fileName = wxT("")},
209 \param{const wxPoint\& }{pos = wxDefaultPosition},
210 \param{const wxSize\& }{size = wxDefaultSize},
211 \param{long }{style = 0},
212 \param{const wxString\& }{szBackend = wxT("")},
213 \param{const wxValidator& }{validator = wxDefaultValidator},
214 \param{const wxString\& }{name = wxPanelNameStr}
215 }
216
217 Constructor that calls \helpref{Create}{wxmediactrlcreate}. You may prefer to call \helpref{Create}{wxmediactrlcreate} directly to check to see if wxMediaCtrl is available on the system.
218
219 \docparam{parent}{parent of this control. Must not be NULL.}
220 \docparam{id}{id to use for events}
221 \docparam{fileName}{If not empty, the path of a file to open.}
222 \docparam{pos}{Position to put control at.}
223 \docparam{size}{Size to put the control at and to stretch movie to.}
224 \docparam{style}{Optional styles.}
225 \docparam{szBackend}{Name of backend you want to use, leave blank to make
226 wxMediaCtrl figure it out.}
227 \docparam{validator}{validator to use.}
228 \docparam{name}{Window name.}
229
230
231 \membersection{wxMediaCtrl::Create}\label{wxmediactrlcreate}
232
233 \func{bool}{Create}{
234 \param{wxWindow* }{parent},
235 \param{wxWindowID }{id},
236 \param{const wxString\& }{fileName = wxT("")},
237 \param{const wxPoint\& }{pos = wxDefaultPosition},
238 \param{const wxSize\& }{size = wxDefaultSize},
239 \param{long }{style = 0},
240 \param{const wxString\& }{szBackend = wxT("")},
241 \param{const wxValidator& }{validator = wxDefaultValidator},
242 \param{const wxString\& }{name = wxPanelNameStr}
243 }
244
245 Creates this control. Returns \tt{false} if it can't load the movie located at \tt{fileName} or it cannot load one of its native backends.
246
247 If you specify a file to open via \tt{fileName} and you don't specify a backend to use, wxMediaCtrl tries each of its backends until one that can render the path referred to by \tt{fileName} can be found.
248
249 \docparam{parent}{parent of this control. Must not be NULL.}
250 \docparam{id}{id to use for events}
251 \docparam{fileName}{If not empty, the path of a file to open.}
252 \docparam{pos}{Position to put control at.}
253 \docparam{size}{Size to put the control at and to stretch movie to.}
254 \docparam{style}{Optional styles.}
255 \docparam{szBackend}{Name of backend you want to use, leave blank to make
256 wxMediaCtrl figure it out.}
257 \docparam{validator}{validator to use.}
258 \docparam{name}{Window name.}
259
260
261 \membersection{wxMediaCtrl::GetBestSize}\label{wxmediactrlgetbestsize}
262
263 \func{wxSize}{GetBestSize}{\void}
264
265 Obtains the best size relative to the original/natural size of the
266 video, if there is any. See \helpref{Video size}{videosizewxmediactrl}
267 for more information.
268
269
270 \membersection{wxMediaCtrl::GetPlaybackRate}\label{wxmediactrlgetplaybackrate}
271
272 \func{double}{GetPlaybackrate}{\void}
273
274 Obtains the playback rate, or speed of the media. \tt{1.0} represents normal
275 speed, while \tt{2.0} represents twice the normal speed of the media, for
276 example. Not supported on the GStreamer (Unix) backend.
277 Returns 0 on failure.
278
279
280 \membersection{wxMediaCtrl::GetVolume}\label{wxmediactrlgetvolume}
281
282 \func{double}{GetVolume}{\void}
283
284 Gets the volume of the media from a 0.0 to 1.0 range. Note that due to rounding
285 and other errors this may not be the exact value sent to SetVolume.
286
287
288 \membersection{wxMediaCtrl::GetState}\label{wxmediactrlgetstate}
289
290 \func{wxMediaCtrlState}{GetState}{\void}
291
292 Obtains the state the playback of the media is in -
293
294 \twocolwidtha{7cm}
295 \begin{twocollist}\itemsep=0pt
296 \twocolitem{{\bf wxMEDIASTATE\_STOPPED}}{The movie has stopped.}
297 \twocolitem{{\bf wxMEDIASTATE\_PAUSED}}{The movie is paused.}
298 \twocolitem{{\bf wxMEDIASTATE\_PLAYING}}{The movie is currently playing.}
299 \end{twocollist}
300
301
302 \membersection{wxMediaCtrl::Length}\label{wxmediactrllength}
303
304 \func{wxFileOffset}{Length}{\void}
305
306 Obtains the length - the total amount of time the movie has in milliseconds.
307
308
309 \membersection{wxMediaCtrl::Load}\label{wxmediactrlload}
310
311 \func{bool}{Load}{\param{const wxString\& }{fileName}}
312
313 Loads the file that \tt{fileName} refers to. Returns false if loading fails.
314
315
316 \membersection{wxMediaCtrl::Load}\label{wxmediactrlloaduri}
317
318 \func{bool}{Load}{\param{const wxURI\& }{uri}}
319
320 Loads the location that \tt{uri} refers to. Note that this is very implementation-dependant, although HTTP URI/URLs are generally supported, for example. Returns false if loading fails.
321
322
323 \membersection{wxMediaCtrl::Load}\label{wxmediactrlloaduriwithproxy}
324
325 \func{bool}{Load}{\param{const wxURI\& }{uri}, \param{const wxURI\& }{proxy}}
326
327 Loads the location that \tt{uri} refers to with the proxy \tt{proxy}. Not implemented on most backends so it should be called with caution. Returns false if loading fails.
328
329
330 \membersection{wxMediaCtrl::LoadURI}\label{wxmediactrlloaduriliteral}
331
332 \func{bool}{LoadURI}{\param{const wxURI\& }{uri}}
333
334 Same as \helpref{Load}{wxmediactrlloaduri}. Kept for wxPython compatability.
335
336
337 \membersection{wxMediaCtrl::LoadURIWithProxy}\label{wxmediactrlloaduriwithproxyliteral}
338
339 \func{bool}{LoadURIWithProxy}{\param{const wxURI\& }{uri}, \param{const wxURI\& }{proxy}}
340
341 Same as \helpref{Load}{wxmediactrlloaduriwithproxy}. Kept for wxPython compatability.
342
343
344 \membersection{wxMediaCtrl::Pause}\label{wxmediactrlpause}
345
346 \func{bool}{Pause}{\void}
347
348 Pauses playback of the movie.
349
350
351 \membersection{wxMediaCtrl::Play}\label{wxmediactrlplay}
352
353 \func{bool}{Play}{\void}
354
355 Resumes playback of the movie.
356
357
358 \membersection{wxMediaCtrl::Seek}\label{wxmediactrlsetposition}
359
360 \func{wxFileOffset}{Seek}{\param{wxFileOffset }{where}, \param{wxSeekMode }{mode}}
361
362 Seeks to a position within the movie.
363
364
365 \membersection{wxMediaCtrl::SetPlaybackRate}\label{wxmediactrlsetplaybackrate}
366
367 \func{bool}{SetPlaybackRate}{\param{double }{dRate}}
368
369 Sets the playback rate, or speed of the media, to that referred by \tt{dRate}.
370 \tt{1.0} represents normal speed, while \tt{2.0} represents twice the normal
371 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
372 Returns true if successful.
373
374
375 \membersection{wxMediaCtrl::SetVolume}\label{wxmediactrlsetvolume}
376
377 \func{bool}{SetVolume}{\param{double }{dVolume}}
378
379 Sets the volume of the media from a 0.0 to 1.0 range to that referred
380 by \tt{dVolume}. \tt{1.0} represents full volume, while \tt{0.5}
381 represents half (50 percent) volume, for example. Note that this may not be
382 exact due to conversion and rounding errors, although setting the volume to
383 full or none is always exact. Returns true if successful.
384
385
386 \membersection{wxMediaCtrl::ShowPlayerControls}\label{wxmediactrlshowplayercontrols}
387
388 \func{bool}{ShowPlayerControls}{\param{wxMediaCtrlPlayerControls }{flags = wxMEDIACTRLPLAYERCONTROLS\_DEFAULT}}
389
390 A special feature to wxMediaCtrl. Applications using native toolkits such as
391 QuickTime usually have a scrollbar, play button, and more provided to
392 them by the toolkit. By default wxMediaCtrl does not do this. However, on
393 the directshow and quicktime backends you can show or hide the native controls
394 provided by the underlying toolkit at will using ShowPlayerControls. Simply
395 calling the function with default parameters tells wxMediaCtrl to use the
396 default controls provided by the toolkit. The function takes a
397 \tt{wxMediaCtrlPlayerControls} enumeration as follows:
398
399 \twocolwidtha{7cm}
400 \begin{twocollist}\itemsep=0pt
401 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS\_NONE}}{No controls. return wxMediaCtrl to it's default state.}
402 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS\_STEP}}{Step controls like fastfoward, step one frame etc.}
403 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS\_VOLUME}}{Volume controls like the speaker icon, volume slider, etc.}
404 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS\_DEFAULT}}{Default controls for the toolkit. Currently a typedef for wxMEDIACTRLPLAYERCONTROLS\_STEP and wxMEDIACTRLPLAYERCONTROLS\_VOLUME.}
405 \end{twocollist}
406
407 For more see \helpref{Player controls}{playercontrolswxmediactrl}. Currently
408 only implemented on the QuickTime and DirectShow backends. The function
409 returns true on success.
410
411
412 \membersection{wxMediaCtrl::Stop}\label{wxmediactrlstop}
413
414 \func{bool}{Stop}{\void}
415
416 Stops the media.
417
418 See \helpref{Operation}{operationwxmediactrl} for an overview of how
419 stopping works.
420
421
422 \membersection{wxMediaCtrl::Tell}\label{wxmediactrlgetposition}
423
424 \func{wxFileOffset}{Tell}{\void}
425
426 Obtains the current position in time within the movie in milliseconds.
427