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