]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: mediactrl.h | |
3 | // Purpose: interface of wxMediaEvent, wxMediaCtrl | |
4 | // Author: wxWidgets team | |
5 | // Licence: wxWindows licence | |
6 | ///////////////////////////////////////////////////////////////////////////// | |
7 | ||
8 | ||
9 | enum wxMediaCtrlPlayerControls | |
10 | { | |
11 | /** No controls. return wxMediaCtrl to its default state. */ | |
12 | wxMEDIACTRLPLAYERCONTROLS_NONE = 0, | |
13 | ||
14 | /** Step controls like fastforward, step one frame etc. */ | |
15 | wxMEDIACTRLPLAYERCONTROLS_STEP = 1 << 0, | |
16 | ||
17 | /** Volume controls like the speaker icon, volume slider, etc. */ | |
18 | wxMEDIACTRLPLAYERCONTROLS_VOLUME = 1 << 1, | |
19 | ||
20 | /** Default controls for the toolkit. Currently a combination for | |
21 | @c wxMEDIACTRLPLAYERCONTROLS_STEP and @c wxMEDIACTRLPLAYERCONTROLS_VOLUME. */ | |
22 | wxMEDIACTRLPLAYERCONTROLS_DEFAULT = | |
23 | wxMEDIACTRLPLAYERCONTROLS_STEP | | |
24 | wxMEDIACTRLPLAYERCONTROLS_VOLUME | |
25 | }; | |
26 | ||
27 | /** | |
28 | @class wxMediaEvent | |
29 | ||
30 | Event wxMediaCtrl uses. | |
31 | ||
32 | @beginEventTable{wxMediaEvent} | |
33 | @event{EVT_MEDIA_LOADED(id\, func)} | |
34 | Sent when a media has loaded enough data that it can start playing. | |
35 | @event{EVT_MEDIA_STOP(id\, func)} | |
36 | Sent when a media has switched to the @c wxMEDIASTATE_STOPPED state. | |
37 | You may be able to Veto this event to prevent it from stopping, | |
38 | causing it to continue playing - even if it has reached that end of | |
39 | the media (note that this may not have the desired effect - if you | |
40 | want to loop the media, for example, catch the @c EVT_MEDIA_FINISHED | |
41 | and play there instead). | |
42 | @event{EVT_MEDIA_FINISHED(id\, func)} | |
43 | Sent when a media has finished playing in a wxMediaCtrl. | |
44 | @event{EVT_MEDIA_STATECHANGED(id\, func)} | |
45 | Sent when a media has switched its state (from any media state). | |
46 | @event{EVT_MEDIA_PLAY(id\, func)} | |
47 | Sent when a media has switched to the @c wxMEDIASTATE_PLAYING state. | |
48 | @event{EVT_MEDIA_PAUSE(id\, func)} | |
49 | Sent when a media has switched to the @c wxMEDIASTATE_PAUSED state. | |
50 | @endEventTable | |
51 | ||
52 | @library{wxmedia} | |
53 | @category{events} | |
54 | */ | |
55 | class wxMediaEvent : public wxNotifyEvent | |
56 | { | |
57 | public: | |
58 | /** Default ctor. */ | |
59 | wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0); | |
60 | }; | |
61 | ||
62 | ||
63 | ||
64 | /** | |
65 | @class wxMediaCtrl | |
66 | ||
67 | wxMediaCtrl is a class for displaying types of media, such as videos, audio | |
68 | files, natively through native codecs. | |
69 | ||
70 | wxMediaCtrl uses native backends to render media, for example on Windows | |
71 | there is a ActiveMovie/DirectShow backend, and on Macintosh there is a | |
72 | QuickTime backend. | |
73 | ||
74 | ||
75 | @section mediactrl_rendering_media Rendering media | |
76 | ||
77 | Depending upon the backend, wxMediaCtrl can render and display pretty much any | |
78 | kind of media that the native system can - such as an image, mpeg video, or mp3 | |
79 | (without license restrictions - since it relies on native system calls that may | |
80 | not technically have mp3 decoding available, for example, it falls outside | |
81 | the realm of licensing restrictions). | |
82 | ||
83 | For general operation, all you need to do is call Load() to load the file you | |
84 | want to render, catch the @c EVT_MEDIA_LOADED event, and then call Play() | |
85 | to show the video/audio of the media in that event. | |
86 | ||
87 | More complex operations are generally more heavily dependent on the capabilities | |
88 | of the backend. For example, QuickTime cannot set the playback rate of certain | |
89 | streaming media - while DirectShow is slightly more flexible in that regard. | |
90 | ||
91 | @section mediactrl_operation Operation | |
92 | ||
93 | When wxMediaCtrl plays a file, it plays until the stop position is reached | |
94 | (currently the end of the file/stream). Right before it hits the end of the stream, | |
95 | it fires off a @c EVT_MEDIA_STOP event to its parent window, at which point the event | |
96 | handler can choose to veto the event, preventing the stream from actually stopping. | |
97 | ||
98 | Example: | |
99 | ||
100 | @code | |
101 | //connect to the media event | |
102 | this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction) | |
103 | (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop); | |
104 | ||
105 | //... | |
106 | void MyFrame::OnMediaStop(const wxMediaEvent& evt) | |
107 | { | |
108 | if(bUserWantsToSeek) | |
109 | { | |
110 | m_mediactrl->SetPosition( | |
111 | m_mediactrl->GetDuration() << 1 | |
112 | ); | |
113 | evt.Veto(); | |
114 | } | |
115 | } | |
116 | @endcode | |
117 | ||
118 | When wxMediaCtrl stops, either by the @c EVT_MEDIA_STOP not being vetoed, or | |
119 | by manually calling Stop(), where it actually stops is not at the beginning, | |
120 | rather, but at the beginning of the stream. That is, when it stops and play | |
121 | is called, playback is guaranteed to start at the beginning of the media. | |
122 | This is because some streams are not seekable, and when stop is called on | |
123 | them they return to the beginning, thus wxMediaCtrl tries to keep consistent | |
124 | for all types of media. | |
125 | ||
126 | Note that when changing the state of the media through Play() and other methods, | |
127 | the media may not actually be in the @c wxMEDIASTATE_PLAYING, for example. | |
128 | If you are relying on the media being in certain state catch the event relevant | |
129 | to the state. See wxMediaEvent for the kinds of events that you can catch. | |
130 | ||
131 | ||
132 | @section mediactrl_video_size Video size | |
133 | ||
134 | By default, wxMediaCtrl will scale the size of the video to the requested | |
135 | amount passed to either its constructor or Create(). | |
136 | After calling wxMediaCtrl::Load or performing an equivalent operation, | |
137 | you can subsequently obtain the "real" size of the video (if there is any) | |
138 | by calling wxMediaCtrl::GetBestSize(). Note that the actual result on the | |
139 | display will be slightly different when wxMediaCtrl::ShowPlayerControls is | |
140 | activated and the actual video size will be less than specified due to the | |
141 | extra controls provided by the native toolkit. | |
142 | In addition, the backend may modify wxMediaCtrl::GetBestSize() to include | |
143 | the size of the extra controls - so if you want the real size of the video | |
144 | just disable wxMediaCtrl::ShowPlayerControls(). | |
145 | ||
146 | The idea with setting wxMediaCtrl::GetBestSize() to the size of the video is | |
147 | that GetBestSize() is a wxWindow-derived function that is called when sizers | |
148 | on a window recalculate. | |
149 | What this means is that if you use sizers by default the video will show in | |
150 | its original size without any extra assistance needed from the user. | |
151 | ||
152 | ||
153 | @section mediactrl_player_controls Player controls | |
154 | ||
155 | Normally, when you use wxMediaCtrl it is just a window for the video to play in. | |
156 | However, some toolkits have their own media player interface. | |
157 | For example, QuickTime generally has a bar below the video with a slider. | |
158 | A special feature available to wxMediaCtrl, you can use the toolkits interface | |
159 | instead of making your own by using the ShowPlayerControls() function. | |
160 | There are several options for the flags parameter, with the two general flags | |
161 | being @c wxMEDIACTRLPLAYERCONTROLS_NONE which turns off the native interface, | |
162 | and @c wxMEDIACTRLPLAYERCONTROLS_DEFAULT which lets wxMediaCtrl decide what | |
163 | native controls on the interface. | |
164 | Be sure to review the caveats outlined in @ref mediactrl_video_size before doing so. | |
165 | ||
166 | ||
167 | @section mediactrl_choosing_backend Choosing a backend | |
168 | ||
169 | Generally, you should almost certainly leave this part up to wxMediaCtrl - | |
170 | but if you need a certain backend for a particular reason, such as QuickTime | |
171 | for playing .mov files, all you need to do to choose a specific backend is | |
172 | to pass the name of the backend class to wxMediaCtrl::Create(). | |
173 | ||
174 | The following are valid backend identifiers: | |
175 | ||
176 | - @b wxMEDIABACKEND_DIRECTSHOW: Use ActiveMovie/DirectShow. | |
177 | Uses the native ActiveMovie (I.E. DirectShow) control. | |
178 | Default backend on Windows and supported by nearly all Windows versions, | |
179 | even some Windows CE versions. | |
180 | May display a windows media player logo while inactive. | |
181 | - @b wxMEDIABACKEND_QUICKTIME: Use QuickTime. Mac Only. | |
182 | WARNING: May not working correctly embedded in a wxNotebook. | |
183 | - @b wxMEDIABACKEND_GSTREAMER, Use GStreamer. Unix Only. | |
184 | Requires GStreamer 0.8 along with at the very least the xvimagesink, xoverlay, | |
185 | and gst-play modules of gstreamer to function. | |
186 | You need the correct modules to play the relevant files, for example the | |
187 | mad module to play mp3s, etc. | |
188 | - @b wxMEDIABACKEND_WMP10, Uses Windows Media Player 10 (Windows only) - | |
189 | works on mobile machines with Windows Media Player 10 and desktop machines | |
190 | with either Windows Media Player 9 or 10. | |
191 | ||
192 | Note that other backends such as wxMEDIABACKEND_MCI can now be found at | |
193 | wxCode (http://wxcode.sourceforge.net/). | |
194 | ||
195 | ||
196 | @section mediactrl_creating_backend Creating a backend | |
197 | ||
198 | Creating a backend for wxMediaCtrl is a rather simple process. | |
199 | Simply derive from wxMediaBackendCommonBase and implement the methods you want. | |
200 | The methods in wxMediaBackend correspond to those in wxMediaCtrl except for | |
201 | wxMediaCtrl::CreateControl which does the actual creation of the control, | |
202 | in cases where a custom control is not needed you may simply call wxControl::Create(). | |
203 | ||
204 | You need to make sure to use the @c DECLARE_CLASS and @c IMPLEMENT_CLASS macros. | |
205 | ||
206 | The only real tricky part is that you need to make sure the file in compiled in, | |
207 | which if there are just backends in there will not happen and you may need to | |
208 | use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI). | |
209 | ||
210 | This is a rather simple example of how to create a backend in the | |
211 | wxActiveXContainer documentation. | |
212 | ||
213 | ||
214 | @library{wxmedia} | |
215 | @category{media} | |
216 | ||
217 | @see wxMediaEvent | |
218 | */ | |
219 | class wxMediaCtrl : public wxControl | |
220 | { | |
221 | public: | |
222 | /** | |
223 | Default constructor - you MUST call Create() before calling any | |
224 | other methods of wxMediaCtrl. | |
225 | */ | |
226 | wxMediaCtrl(); | |
227 | ||
228 | /** | |
229 | Constructor that calls Create(). | |
230 | You may prefer to call Create() directly to check to see if | |
231 | wxMediaCtrl is available on the system. | |
232 | ||
233 | @param parent | |
234 | parent of this control. Must not be @NULL. | |
235 | @param id | |
236 | id to use for events | |
237 | @param fileName | |
238 | If not empty, the path of a file to open. | |
239 | @param pos | |
240 | Position to put control at. | |
241 | @param size | |
242 | Size to put the control at and to stretch movie to. | |
243 | @param style | |
244 | Optional styles. | |
245 | @param szBackend | |
246 | Name of backend you want to use, leave blank to make wxMediaCtrl figure it out. | |
247 | @param validator | |
248 | validator to use. | |
249 | @param name | |
250 | Window name. | |
251 | */ | |
252 | wxMediaCtrl(wxWindow* parent, wxWindowID id, const wxString& fileName = wxEmptyString, | |
253 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
254 | long style = 0, const wxString& szBackend = wxEmptyString, | |
255 | const wxValidator& validator = wxDefaultValidator, | |
256 | const wxString& name = "mediaCtrl"); | |
257 | ||
258 | /** | |
259 | Creates this control. | |
260 | Returns @false if it can't load the movie located at @a fileName | |
261 | or it cannot load one of its native backends. | |
262 | ||
263 | If you specify a file to open via @a fileName and you don't specify a | |
264 | backend to use, wxMediaCtrl tries each of its backends until one that | |
265 | can render the path referred to by @a fileName can be found. | |
266 | ||
267 | @param parent | |
268 | parent of this control. Must not be @NULL. | |
269 | @param id | |
270 | id to use for events | |
271 | @param fileName | |
272 | If not empty, the path of a file to open. | |
273 | @param pos | |
274 | Position to put control at. | |
275 | @param size | |
276 | Size to put the control at and to stretch movie to. | |
277 | @param style | |
278 | Optional styles. | |
279 | @param szBackend | |
280 | Name of backend you want to use, leave blank to make wxMediaCtrl figure it out. | |
281 | @param validator | |
282 | validator to use. | |
283 | @param name | |
284 | Window name. | |
285 | */ | |
286 | bool Create(wxWindow* parent, wxWindowID id, const wxString& fileName = wxEmptyString, | |
287 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
288 | long style = 0, const wxString& szBackend = wxEmptyString, | |
289 | const wxValidator& validator = wxDefaultValidator, | |
290 | const wxString& name = "mediaCtrl"); | |
291 | ||
292 | /** | |
293 | Obtains the best size relative to the original/natural size of the | |
294 | video, if there is any. | |
295 | See @ref mediactrl_video_size for more information. | |
296 | */ | |
297 | wxSize GetBestSize() const; | |
298 | ||
299 | /** | |
300 | Obtains the playback rate, or speed of the media. @c 1.0 represents normal | |
301 | speed, while @c 2.0 represents twice the normal speed of the media, for | |
302 | example. Not supported on the GStreamer (Unix) backend. | |
303 | ||
304 | @return zero on failure. | |
305 | */ | |
306 | double GetPlaybackRate(); | |
307 | ||
308 | /** | |
309 | Obtains the state the playback of the media is in - | |
310 | ||
311 | @beginTable | |
312 | @row2col{wxMEDIASTATE_STOPPED, The movie has stopped.} | |
313 | @row2col{wxMEDIASTATE_PAUSED, The movie is paused.} | |
314 | @row2col{wxMEDIASTATE_PLAYING, The movie is currently playing.} | |
315 | @endTable | |
316 | */ | |
317 | wxMediaState GetState(); | |
318 | ||
319 | /** | |
320 | Gets the volume of the media from a 0.0 to 1.0 range. | |
321 | ||
322 | @note Due to rounding and other errors the value returned may not be the | |
323 | exact value sent to SetVolume(). | |
324 | */ | |
325 | double GetVolume(); | |
326 | ||
327 | /** | |
328 | Obtains the length - the total amount of time the movie has in milliseconds. | |
329 | */ | |
330 | wxFileOffset Length(); | |
331 | ||
332 | /** | |
333 | Loads the file that fileName refers to. Returns @false if loading fails. | |
334 | */ | |
335 | bool Load(const wxString& fileName); | |
336 | ||
337 | /** | |
338 | Loads the location that uri refers to. Note that this is very | |
339 | implementation-dependent, although HTTP URI/URLs are generally | |
340 | supported, for example. Returns @false if loading fails. | |
341 | */ | |
342 | bool Load(const wxURI& uri); | |
343 | ||
344 | /** | |
345 | Loads the location that @c uri refers to with the proxy @c proxy. | |
346 | Not implemented on most backends so it should be called with caution. | |
347 | Returns @false if loading fails. | |
348 | */ | |
349 | bool Load(const wxURI& uri, const wxURI& proxy); | |
350 | ||
351 | /** | |
352 | Same as Load(const wxURI& uri). Kept for wxPython compatibility. | |
353 | */ | |
354 | bool LoadURI(const wxString& fileName); | |
355 | ||
356 | /** | |
357 | Same as Load(const wxURI& uri, const wxURI& proxy). | |
358 | Kept for wxPython compatibility. | |
359 | */ | |
360 | bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy); | |
361 | ||
362 | /** | |
363 | Pauses playback of the movie. | |
364 | */ | |
365 | bool Pause(); | |
366 | ||
367 | /** | |
368 | Resumes playback of the movie. | |
369 | */ | |
370 | bool Play(); | |
371 | ||
372 | /** | |
373 | Seeks to a position within the movie. | |
374 | ||
375 | @todo Document the wxSeekMode parameter @a mode, and perhaps also the | |
376 | wxFileOffset and wxSeekMode themselves. | |
377 | */ | |
378 | wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart); | |
379 | ||
380 | /** | |
381 | Sets the playback rate, or speed of the media, to that referred by @a dRate. | |
382 | @c 1.0 represents normal speed, while @c 2.0 represents twice the normal | |
383 | speed of the media, for example. Not supported on the GStreamer (Unix) backend. | |
384 | Returns @true if successful. | |
385 | */ | |
386 | bool SetPlaybackRate(double dRate); | |
387 | ||
388 | /** | |
389 | Sets the volume of the media from a 0.0 to 1.0 range to that referred | |
390 | by @c dVolume. @c 1.0 represents full volume, while @c 0.5 | |
391 | represents half (50 percent) volume, for example. | |
392 | ||
393 | @note The volume may not be exact due to conversion and rounding errors, | |
394 | although setting the volume to full or none is always exact. | |
395 | Returns @true if successful. | |
396 | */ | |
397 | bool SetVolume(double dVolume); | |
398 | ||
399 | /** | |
400 | A special feature to wxMediaCtrl. Applications using native toolkits such as | |
401 | QuickTime usually have a scrollbar, play button, and more provided to | |
402 | them by the toolkit. By default wxMediaCtrl does not do this. However, on | |
403 | the directshow and quicktime backends you can show or hide the native controls | |
404 | provided by the underlying toolkit at will using ShowPlayerControls(). Simply | |
405 | calling the function with default parameters tells wxMediaCtrl to use the | |
406 | default controls provided by the toolkit. The function takes a | |
407 | wxMediaCtrlPlayerControls enumeration, please see available show modes there. | |
408 | ||
409 | For more info see @ref mediactrl_player_controls. | |
410 | ||
411 | Currently only implemented on the QuickTime and DirectShow backends. | |
412 | The function returns @true on success. | |
413 | */ | |
414 | bool ShowPlayerControls(wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT); | |
415 | ||
416 | /** | |
417 | Stops the media. | |
418 | ||
419 | See @ref mediactrl_operation for an overview of how stopping works. | |
420 | */ | |
421 | bool Stop(); | |
422 | ||
423 | /** | |
424 | Obtains the current position in time within the movie in milliseconds. | |
425 | */ | |
426 | wxFileOffset Tell(); | |
427 | }; | |
428 |