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