]>
Commit | Line | Data |
---|---|---|
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 | ||
14 | wxMediaCtrl is a class for displaying types of | |
15 | media, such as videos, audio files, natively through native codecs. | |
16 | ||
17 | wxMediaCtrl uses native backends to render media, for example on Windows | |
18 | there is a ActiveMovie/DirectShow backend, and on Macintosh there is a | |
19 | QuickTime 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 | ||
45 | Depending upon the backend, wxMediaCtrl can render | |
46 | and display pretty much any kind of media that the native system can - | |
47 | such as an image, mpeg video, or mp3 (without license restrictions - | |
48 | since it relies on native system calls that may not technically | |
49 | have mp3 decoding available, for example, it falls outside the | |
50 | realm of licensing restrictions). | |
51 | ||
52 | For general operation, all you need to do is call | |
53 | \helpref{wxMediaCtrl::Load}{wxmediactrlload} to load the file | |
54 | you want to render, catch the EVT\_MEDIA\_LOADED event, | |
55 | and then call \helpref{wxMediaCtrl::Play}{wxmediactrlplay} | |
56 | to show the video/audio of the media in that event. | |
57 | ||
58 | More complex operations are generally more heavily dependant on the | |
59 | capabilities of the backend. For example, QuickTime cannot set | |
60 | the playback rate of certain streaming media - while DirectShow is | |
61 | slightly more flexible in that regard. | |
62 | ||
63 | ||
64 | \membersection{Operation}\label{operationwxmediactrl} | |
65 | ||
66 | When wxMediaCtrl plays a file, it plays until the stop position | |
67 | is reached (currently the end of the file/stream). Right before | |
68 | it hits the end of the stream, it fires off a EVT\_MEDIA\_STOP | |
69 | event to its parent window, at which point the event handler | |
70 | can choose to veto the event, preventing the stream from actually | |
71 | stopping. | |
72 | ||
73 | Example: | |
74 | \begin{verbatim} | |
75 | //connect to the media event | |
76 | this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction) | |
77 | (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop); | |
78 | ||
79 | //... | |
80 | void 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 | ||
92 | When wxMediaCtrl stops, either by the EVT\_MEDIA\_STOP not being | |
93 | vetoed, or by manually calling | |
94 | \helpref{wxMediaCtrl::Stop}{wxmediactrlstop}, where it actually | |
95 | stops is not at the beginning, rather, but at the beginning of | |
96 | the stream. That is, when it stops and play is called, playback | |
97 | is gauranteed to start at the beginning of the media. This is | |
98 | because some streams are not seekable, and when stop is called | |
99 | on them they return to the beginning, thus wxMediaCtrl tries | |
100 | to keep consistant for all types of media. | |
101 | ||
102 | Note that when changing the state of the media through Play() | |
103 | and other methods, the media may not actually be in the | |
104 | wxMEDIASTATE\_PLAYING, for example. If you are relying on the | |
105 | media being in certain state catch the event relevant to the state. | |
106 | See \helpref{wxMediaEvent}{wxmediaevent} for the kinds of events | |
107 | that you can catch. | |
108 | ||
109 | ||
110 | \membersection{Video size}\label{videosizewxmediactrl} | |
111 | ||
112 | By default, wxMediaCtrl will scale the size of the video to the | |
113 | requested amount passed to either it's constructor or Create(). | |
114 | After calling Load or performing an equivilant operation, you | |
115 | can subsequently obtain the "real" size of the video (if there | |
116 | is any) by calling GetBestSize(). Note that the actual result | |
117 | on the display will be slightly different when ShowPlayerControls | |
118 | is activated and the actual video size will be less then | |
119 | specified due to the extra controls provided by the native toolkit. | |
120 | In addition, the backend may modify GetBestSize() to include the | |
121 | size of the extra controls - so if you want the real size of the | |
122 | video just disable ShowPlayerControls(). | |
123 | ||
124 | The idea with setting GetBestSize to the size of the video is | |
125 | that GetBestSize is a wxWindow-derived function that is called | |
126 | when sizers on a window recalculate. What this means is that | |
127 | if you use sizers by default the video will show in it's | |
128 | original size without any extra assistance needed from the user. | |
129 | ||
130 | ||
131 | \membersection{Player controls}\label{playercontrolswxmediactrl} | |
132 | ||
133 | Normally, when you use wxMediaCtrl it is just a window for the video to | |
134 | play in. However, some toolkits have their own media player interface. | |
135 | For example, QuickTime generally has a bar below the video with a slider. | |
136 | A special feature available to wxMediaCtrl, you can use the toolkit's interface instead of | |
137 | making your own by using the \helpref{ShowPlayerControls()}{wxmediactrlshowplayercontrols} | |
138 | function. There are several options for the flags parameter, with | |
139 | the two general flags being wxMEDIACTRLPLAYERCONTROLS\_NONE which turns off | |
140 | the native interface, and wxMEDIACTRLPLAYERCONTROLS\_DEFAULT which lets | |
141 | wxMediaCtrl decide what native controls on the interface. Be sure to review | |
142 | the caveats outlined in \helpref{Video size}{videosizewxmediactrl} before | |
143 | doing so. | |
144 | ||
145 | ||
146 | \membersection{Choosing a backend}\label{choosingbackendwxmediactrl} | |
147 | ||
148 | Generally, you should almost certainly leave this part up to | |
149 | wxMediaCtrl - but if you need a certain backend for a particular | |
150 | reason, such as QuickTime for playing .mov files, all you need | |
151 | to do to choose a specific backend is to pass the | |
152 | name of the backend class to | |
153 | \helpref{wxMediaCtrl::Create}{wxmediactrlcreate}. | |
154 | ||
155 | The following are valid backend identifiers - | |
156 | \twocolwidtha{7cm} | |
157 | \begin{twocollist}\itemsep=0pt | |
158 | \twocolitem{{\bf wxMEDIABACKEND\_DIRECTSHOW}}{ | |
159 | Use ActiveMovie/DirectShow. Uses the native ActiveMovie | |
160 | (I.E. DirectShow) control. Default backend on Windows and | |
161 | supported by nearly all Windows versions, even some | |
162 | Windows CE versions. May display a windows media player | |
163 | logo while inactive. } | |
164 | \twocolitem{{\bf wxMEDIABACKEND\_QUICKTIME}}{ | |
165 | Use QuickTime. Mac Only. | |
166 | WARNING: May not working correctly embedded in a wxNotebook. | |
167 | } | |
168 | \twocolitem{{\bf wxMEDIABACKEND\_GSTREAMER}}{ | |
169 | Use GStreamer. Unix Only. Requires GStreamer 0.8 along | |
170 | with at the very least the xvimagesink, xoverlay, and | |
171 | gst-play modules of gstreamer to function. You need the correct | |
172 | modules to play the relavant files, for example the mad module | |
173 | to play mp3s, etc.} | |
174 | \twocolitem{{\bf wxMEDIABACKEND\_WMP10}}{ | |
175 | Uses Windows Media Player 10 (Windows only) - works on mobile | |
176 | machines with Windows Media Player 10 and desktop machines with | |
177 | either Windows Media Player 9 or 10 | |
178 | } | |
179 | \end{twocollist} | |
180 | ||
181 | Note that other backends such as wxMEDIABACKEND\_MCI can now be | |
182 | found at wxCode. | |
183 | ||
184 | \membersection{Creating a backend}\label{creatingabackendwxmediactrl} | |
185 | ||
186 | Creating a backend for wxMediaCtrl is a rather simple process. Simply derive | |
187 | from wxMediaBackendCommonBase and implement the methods you want. The methods | |
188 | in wxMediaBackend correspond to those in wxMediaCtrl except for CreateControl | |
189 | which does the actual creation of the control, in cases where a custom control | |
190 | is not needed you may simply call wxControl::Create. | |
191 | ||
192 | You need to make sure to use the DECLARE\_CLASS and IMPLEMENT\_CLASS macros. | |
193 | ||
194 | The only real tricky part is that you need to make sure the file in compiled | |
195 | in, which if there are just backends in there will not happen and you may need | |
196 | to use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI). | |
197 | ||
198 | This 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 | ||
205 | Default constructor - you \tt{must} call Create before calling any other methods | |
206 | of 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 | ||
220 | Constructor 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 | |
229 | wxMediaCtrl 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 | ||
248 | Creates 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 | ||
250 | If 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 | |
259 | wxMediaCtrl 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 | ||
268 | Obtains the best size relative to the original/natural size of the | |
269 | video, if there is any. See \helpref{Video size}{videosizewxmediactrl} | |
270 | for more information. | |
271 | ||
272 | ||
273 | \membersection{wxMediaCtrl::GetPlaybackRate}\label{wxmediactrlgetplaybackrate} | |
274 | ||
275 | \func{double}{GetPlaybackrate}{\void} | |
276 | ||
277 | Obtains the playback rate, or speed of the media. \tt{1.0} represents normal | |
278 | speed, while \tt{2.0} represents twice the normal speed of the media, for | |
279 | example. Not supported on the GStreamer (Unix) backend. | |
280 | Returns 0 on failure. | |
281 | ||
282 | ||
283 | \membersection{wxMediaCtrl::GetVolume}\label{wxmediactrlgetvolume} | |
284 | ||
285 | \func{double}{GetVolume}{\void} | |
286 | ||
287 | Gets the volume of the media from a 0.0 to 1.0 range. Note that due to rounding | |
288 | and 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 | ||
295 | Obtains 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 | ||
309 | Obtains 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 | ||
316 | Loads 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 | ||
323 | Loads 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 | ||
330 | Loads 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 | ||
337 | Same 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 | ||
344 | Same as \helpref{Load}{wxmediactrlloaduriwithproxy}. Kept for wxPython compatability. | |
345 | ||
346 | ||
347 | \membersection{wxMediaCtrl::Pause}\label{wxmediactrlpause} | |
348 | ||
349 | \func{bool}{Pause}{\void} | |
350 | ||
351 | Pauses playback of the movie. | |
352 | ||
353 | ||
354 | \membersection{wxMediaCtrl::Play}\label{wxmediactrlplay} | |
355 | ||
356 | \func{bool}{Play}{\void} | |
357 | ||
358 | Resumes playback of the movie. | |
359 | ||
360 | ||
361 | \membersection{wxMediaCtrl::Seek}\label{wxmediactrlsetposition} | |
362 | ||
363 | \func{wxFileOffset}{Seek}{\param{wxFileOffset }{where}, \param{wxSeekMode }{mode}} | |
364 | ||
365 | Seeks to a position within the movie. | |
366 | ||
367 | ||
368 | \membersection{wxMediaCtrl::SetPlaybackRate}\label{wxmediactrlsetplaybackrate} | |
369 | ||
370 | \func{bool}{SetPlaybackRate}{\param{double }{dRate}} | |
371 | ||
372 | Sets 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 | |
374 | speed of the media, for example. Not supported on the GStreamer (Unix) backend. | |
375 | Returns true if successful. | |
376 | ||
377 | ||
378 | \membersection{wxMediaCtrl::SetVolume}\label{wxmediactrlsetvolume} | |
379 | ||
380 | \func{bool}{SetVolume}{\param{double }{dVolume}} | |
381 | ||
382 | Sets the volume of the media from a 0.0 to 1.0 range to that referred | |
383 | by \tt{dVolume}. \tt{1.0} represents full volume, while \tt{0.5} | |
384 | represents half (50 percent) volume, for example. Note that this may not be | |
385 | exact due to conversion and rounding errors, although setting the volume to | |
386 | full 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 | ||
393 | A special feature to wxMediaCtrl. Applications using native toolkits such as | |
394 | QuickTime usually have a scrollbar, play button, and more provided to | |
395 | them by the toolkit. By default wxMediaCtrl does not do this. However, on | |
396 | the directshow and quicktime backends you can show or hide the native controls | |
397 | provided by the underlying toolkit at will using ShowPlayerControls. Simply | |
398 | calling the function with default parameters tells wxMediaCtrl to use the | |
399 | default 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 | ||
410 | For more see \helpref{Player controls}{playercontrolswxmediactrl}. Currently | |
411 | only implemented on the QuickTime and DirectShow backends. The function | |
412 | returns true on success. | |
413 | ||
414 | ||
415 | \membersection{wxMediaCtrl::Stop}\label{wxmediactrlstop} | |
416 | ||
417 | \func{bool}{Stop}{\void} | |
418 | ||
419 | Stops the media. | |
420 | ||
421 | See \helpref{Operation}{operationwxmediactrl} for an overview of how | |
422 | stopping works. | |
423 | ||
424 | ||
425 | \membersection{wxMediaCtrl::Tell}\label{wxmediactrlgetposition} | |
426 | ||
427 | \func{wxFileOffset}{Tell}{\void} | |
428 | ||
429 | Obtains the current position in time within the movie in milliseconds. | |
430 |