]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/mediactrl.tex
no changes, just come cleanup and more comments
[wxWidgets.git] / docs / latex / wx / mediactrl.tex
... / ...
CommitLineData
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
14wxMediaCtrl is a class for displaying types of
15media, such as videos, audio files, natively through native codecs.
16
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.
20
21\wxheading{See also}
22
23\helpref{wxMediaEvent}{wxmediaevent}
24
25\wxheading{Derived from}
26
27\helpref{wxControl}{wxcontrol}\\
28\helpref{wxWindow}{wxwindow}\\
29\helpref{wxEvtHandler}{wxevthandler}\\
30\helpref{wxObject}{wxobject}
31
32\wxheading{Include files}
33
34<wx/mediactrl.h>
35
36\wxheading{Library}
37
38\helpref{wxMedia}{librarieslist}
39
40\latexignore{\rtfignore{\wxheading{Members}}}
41
42
43\membersection{Rendering media}\label{renderingmediawxmediactrl}
44
45Depending upon the backend, wxMediaCtrl can render
46and display pretty much any kind of media that the native system can -
47such as an image, mpeg video, or mp3 (without license restrictions -
48since it relies on native system calls that may not technically
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
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.
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
63
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
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
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}}{
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. }
164\twocolitem{{\bf wxMEDIABACKEND\_QUICKTIME}}{
165Use QuickTime. Mac Only.
166WARNING: May not working correctly embedded in a wxNotebook.
167}
168\twocolitem{{\bf wxMEDIABACKEND\_GSTREAMER}}{
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}
179\end{twocollist}
180
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
201\membersection{wxMediaCtrl::wxMediaCtrl}\label{wxmediactrlwxmediactrl}
202
203\func{}{wxMediaCtrl}{\void}
204
205Default constructor - you \tt{must} call Create before calling any other methods
206of wxMediaCtrl.
207
208\func{}{wxMediaCtrl}{
209 \param{wxWindow* }{parent},
210 \param{wxWindowID }{id},
211 \param{const wxString\& }{fileName = wxT("")},
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 }
219
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.
221
222\docparam{parent}{parent of this control. Must not be NULL.}
223\docparam{id}{id to use for events}
224\docparam{fileName}{If not empty, the path of a file to open.}
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.}
228\docparam{szBackend}{Name of backend you want to use, leave blank to make
229wxMediaCtrl figure it out.}
230\docparam{validator}{validator to use.}
231\docparam{name}{Window name.}
232
233
234\membersection{wxMediaCtrl::Create}\label{wxmediactrlcreate}
235
236\func{bool}{Create}{
237 \param{wxWindow* }{parent},
238 \param{wxWindowID }{id},
239 \param{const wxString\& }{fileName = wxT("")},
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 }
247
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.
251
252\docparam{parent}{parent of this control. Must not be NULL.}
253\docparam{id}{id to use for events}
254\docparam{fileName}{If not empty, the path of a file to open.}
255\docparam{pos}{Position to put control at.}
256\docparam{size}{Size to put the control at and to stretch movie to.}
257\docparam{style}{Optional styles.}
258\docparam{szBackend}{Name of backend you want to use, leave blank to make
259wxMediaCtrl figure it out.}
260\docparam{validator}{validator to use.}
261\docparam{name}{Window name.}
262
263
264\membersection{wxMediaCtrl::GetBestSize}\label{wxmediactrlgetbestsize}
265
266\func{wxSize}{GetBestSize}{\void}
267
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.
271
272
273\membersection{wxMediaCtrl::GetPlaybackRate}\label{wxmediactrlgetplaybackrate}
274
275\func{double}{GetPlaybackrate}{\void}
276
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.
289
290
291\membersection{wxMediaCtrl::GetState}\label{wxmediactrlgetstate}
292
293\func{wxMediaCtrlState}{GetState}{\void}
294
295Obtains the state the playback of the media is in -
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
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
312\membersection{wxMediaCtrl::Load}\label{wxmediactrlload}
313
314\func{bool}{Load}{\param{const wxString\& }{fileName}}
315
316Loads the file that \tt{fileName} refers to. Returns false if loading fails.
317
318
319\membersection{wxMediaCtrl::Load}\label{wxmediactrlloaduri}
320
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.
345
346
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
361\membersection{wxMediaCtrl::Seek}\label{wxmediactrlsetposition}
362
363\func{wxFileOffset}{Seek}{\param{wxFileOffset }{where}, \param{wxSeekMode }{mode}}
364
365Seeks to a position within the movie.
366
367
368\membersection{wxMediaCtrl::SetPlaybackRate}\label{wxmediactrlsetplaybackrate}
369
370\func{bool}{SetPlaybackRate}{\param{double }{dRate}}
371
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.
376
377
378\membersection{wxMediaCtrl::SetVolume}\label{wxmediactrlsetvolume}
379
380\func{bool}{SetVolume}{\param{double }{dVolume}}
381
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.
387
388
389\membersection{wxMediaCtrl::ShowPlayerControls}\label{wxmediactrlshowplayercontrols}
390
391\func{bool}{ShowPlayerControls}{\param{wxMediaCtrlPlayerControls }{flags = wxMEDIACTRLPLAYERCONTROLS\_DEFAULT}}
392
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:
401
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}
409
410For more see \helpref{Player controls}{playercontrolswxmediactrl}. Currently
411only implemented on the QuickTime and DirectShow backends. The function
412returns true on success.
413
414
415\membersection{wxMediaCtrl::Stop}\label{wxmediactrlstop}
416
417\func{bool}{Stop}{\void}
418
419Stops the media.
420
421See \helpref{Operation}{operationwxmediactrl} for an overview of how
422stopping works.
423
424
425\membersection{wxMediaCtrl::Tell}\label{wxmediactrlgetposition}
426
427\func{wxFileOffset}{Tell}{\void}
428
429Obtains the current position in time within the movie in milliseconds.
430