]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/mediactrl.tex
sorting support for generic version (patch 1765087 from Bo)
[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
29\wxheading{Include files}
30
31<wx/mediactrl.h>
32
33\wxheading{Library}
34
35\helpref{wxMedia}{librarieslist}
36
37\latexignore{\rtfignore{\wxheading{Members}}}
38
39
40\membersection{Rendering media}\label{renderingmediawxmediactrl}
41
42Depending upon the backend, wxMediaCtrl can render
43and display pretty much any kind of media that the native system can -
44such as an image, mpeg video, or mp3 (without license restrictions -
45since it relies on native system calls that may not technically
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
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.
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
60
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
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
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}}{
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. }
161\twocolitem{{\bf wxMEDIABACKEND\_QUICKTIME}}{
162Use QuickTime. Mac Only.
163WARNING: May not working correctly embedded in a wxNotebook.
164}
165\twocolitem{{\bf wxMEDIABACKEND\_GSTREAMER}}{
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}
176\end{twocollist}
177
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
198\membersection{wxMediaCtrl::wxMediaCtrl}\label{wxmediactrlwxmediactrl}
199
200\func{}{wxMediaCtrl}{\void}
201
202Default constructor - you \tt{must} call Create before calling any other methods
203of wxMediaCtrl.
204
205\func{}{wxMediaCtrl}{
206 \param{wxWindow* }{parent},
207 \param{wxWindowID }{id},
208 \param{const wxString\& }{fileName = wxT("")},
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 }
216
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.
218
219\docparam{parent}{parent of this control. Must not be NULL.}
220\docparam{id}{id to use for events}
221\docparam{fileName}{If not empty, the path of a file to open.}
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.}
225\docparam{szBackend}{Name of backend you want to use, leave blank to make
226wxMediaCtrl figure it out.}
227\docparam{validator}{validator to use.}
228\docparam{name}{Window name.}
229
230
231\membersection{wxMediaCtrl::Create}\label{wxmediactrlcreate}
232
233\func{bool}{Create}{
234 \param{wxWindow* }{parent},
235 \param{wxWindowID }{id},
236 \param{const wxString\& }{fileName = wxT("")},
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 }
244
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.
248
249\docparam{parent}{parent of this control. Must not be NULL.}
250\docparam{id}{id to use for events}
251\docparam{fileName}{If not empty, the path of a file to open.}
252\docparam{pos}{Position to put control at.}
253\docparam{size}{Size to put the control at and to stretch movie to.}
254\docparam{style}{Optional styles.}
255\docparam{szBackend}{Name of backend you want to use, leave blank to make
256wxMediaCtrl figure it out.}
257\docparam{validator}{validator to use.}
258\docparam{name}{Window name.}
259
260
261\membersection{wxMediaCtrl::GetBestSize}\label{wxmediactrlgetbestsize}
262
263\func{wxSize}{GetBestSize}{\void}
264
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.
268
269
270\membersection{wxMediaCtrl::GetPlaybackRate}\label{wxmediactrlgetplaybackrate}
271
272\func{double}{GetPlaybackrate}{\void}
273
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.
286
287
288\membersection{wxMediaCtrl::GetState}\label{wxmediactrlgetstate}
289
290\func{wxMediaCtrlState}{GetState}{\void}
291
292Obtains the state the playback of the media is in -
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
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
309\membersection{wxMediaCtrl::Load}\label{wxmediactrlload}
310
311\func{bool}{Load}{\param{const wxString\& }{fileName}}
312
313Loads the file that \tt{fileName} refers to. Returns false if loading fails.
314
315
316\membersection{wxMediaCtrl::Load}\label{wxmediactrlloaduri}
317
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.
342
343
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
358\membersection{wxMediaCtrl::Seek}\label{wxmediactrlsetposition}
359
360\func{wxFileOffset}{Seek}{\param{wxFileOffset }{where}, \param{wxSeekMode }{mode}}
361
362Seeks to a position within the movie.
363
364
365\membersection{wxMediaCtrl::SetPlaybackRate}\label{wxmediactrlsetplaybackrate}
366
367\func{bool}{SetPlaybackRate}{\param{double }{dRate}}
368
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.
373
374
375\membersection{wxMediaCtrl::SetVolume}\label{wxmediactrlsetvolume}
376
377\func{bool}{SetVolume}{\param{double }{dVolume}}
378
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.
384
385
386\membersection{wxMediaCtrl::ShowPlayerControls}\label{wxmediactrlshowplayercontrols}
387
388\func{bool}{ShowPlayerControls}{\param{wxMediaCtrlPlayerControls }{flags = wxMEDIACTRLPLAYERCONTROLS\_DEFAULT}}
389
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:
398
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}
406
407For more see \helpref{Player controls}{playercontrolswxmediactrl}. Currently
408only implemented on the QuickTime and DirectShow backends. The function
409returns true on success.
410
411
412\membersection{wxMediaCtrl::Stop}\label{wxmediactrlstop}
413
414\func{bool}{Stop}{\void}
415
416Stops the media.
417
418See \helpref{Operation}{operationwxmediactrl} for an overview of how
419stopping works.
420
421
422\membersection{wxMediaCtrl::Tell}\label{wxmediactrlgetposition}
423
424\func{wxFileOffset}{Tell}{\void}
425
426Obtains the current position in time within the movie in milliseconds.
427