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