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