]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mediactrl.h | |
336aecf1 | 3 | // Purpose: interface of wxMediaEvent, wxMediaCtrl |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
5c3a762d FM |
8 | |
9 | enum wxMediaCtrlPlayerControls | |
10 | { | |
11 | /** No controls. return wxMediaCtrl to its default state. */ | |
12 | wxMEDIACTRLPLAYERCONTROLS_NONE = 0, | |
13 | ||
57ab6f23 | 14 | /** Step controls like fastforward, step one frame etc. */ |
5c3a762d FM |
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 | ||
23324ae1 FM |
27 | /** |
28 | @class wxMediaEvent | |
7c913512 | 29 | |
23324ae1 | 30 | Event wxMediaCtrl uses. |
7c913512 | 31 | |
5c3a762d FM |
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 | ||
23324ae1 | 52 | @library{wxmedia} |
5c3a762d | 53 | @category{events} |
23324ae1 FM |
54 | */ |
55 | class wxMediaEvent : public wxNotifyEvent | |
56 | { | |
57 | public: | |
5c3a762d FM |
58 | /** Default ctor. */ |
59 | wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0); | |
23324ae1 FM |
60 | }; |
61 | ||
62 | ||
e54c96f1 | 63 | |
23324ae1 FM |
64 | /** |
65 | @class wxMediaCtrl | |
7c913512 | 66 | |
ba1d7a6c FM |
67 | wxMediaCtrl is a class for displaying types of media, such as videos, audio |
68 | files, natively through native codecs. | |
7c913512 | 69 | |
23324ae1 | 70 | wxMediaCtrl uses native backends to render media, for example on Windows |
7c913512 | 71 | there is a ActiveMovie/DirectShow backend, and on Macintosh there is a |
23324ae1 | 72 | QuickTime backend. |
7c913512 | 73 | |
7c913512 | 74 | |
ba1d7a6c | 75 | @section mediactrl_rendering_media Rendering media |
5c3a762d FM |
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 | ||
8cddee2d | 87 | More complex operations are generally more heavily dependent on the capabilities |
5c3a762d FM |
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 | ||
ba1d7a6c | 91 | @section mediactrl_operation Operation |
5c3a762d FM |
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 | ||
ba1d7a6c FM |
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 | |
57ab6f23 | 121 | is called, playback is guaranteed to start at the beginning of the media. |
ba1d7a6c | 122 | This is because some streams are not seekable, and when stop is called on |
57ab6f23 | 123 | them they return to the beginning, thus wxMediaCtrl tries to keep consistent |
ba1d7a6c FM |
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(). | |
57ab6f23 | 136 | After calling wxMediaCtrl::Load or performing an equivalent operation, |
ba1d7a6c FM |
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 | |
57ab6f23 | 140 | activated and the actual video size will be less than specified due to the |
ba1d7a6c FM |
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(). | |
5c3a762d FM |
173 | |
174 | The following are valid backend identifiers: | |
175 | ||
ba1d7a6c FM |
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. | |
57ab6f23 | 186 | You need the correct modules to play the relevant files, for example the |
ba1d7a6c FM |
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(). | |
5c3a762d | 203 | |
ba1d7a6c | 204 | You need to make sure to use the @c DECLARE_CLASS and @c IMPLEMENT_CLASS macros. |
5c3a762d | 205 | |
ba1d7a6c FM |
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). | |
5c3a762d | 209 | |
ba1d7a6c FM |
210 | This is a rather simple example of how to create a backend in the |
211 | wxActiveXContainer documentation. | |
5c3a762d | 212 | |
5c3a762d | 213 | |
ba1d7a6c FM |
214 | @library{wxmedia} |
215 | @category{media} | |
5c3a762d | 216 | |
ba1d7a6c | 217 | @see wxMediaEvent |
23324ae1 FM |
218 | */ |
219 | class wxMediaCtrl : public wxControl | |
220 | { | |
221 | public: | |
23324ae1 | 222 | /** |
ba1d7a6c FM |
223 | Default constructor - you MUST call Create() before calling any |
224 | other methods of wxMediaCtrl. | |
5c3a762d FM |
225 | */ |
226 | wxMediaCtrl(); | |
227 | ||
228 | /** | |
ba1d7a6c FM |
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. | |
3c4f71cc | 232 | |
5c3a762d | 233 | @param parent |
4cc4bfaf | 234 | parent of this control. Must not be @NULL. |
7c913512 | 235 | @param id |
4cc4bfaf | 236 | id to use for events |
7c913512 | 237 | @param fileName |
4cc4bfaf | 238 | If not empty, the path of a file to open. |
7c913512 | 239 | @param pos |
4cc4bfaf | 240 | Position to put control at. |
7c913512 | 241 | @param size |
4cc4bfaf | 242 | Size to put the control at and to stretch movie to. |
7c913512 | 243 | @param style |
4cc4bfaf | 244 | Optional styles. |
7c913512 | 245 | @param szBackend |
ba1d7a6c | 246 | Name of backend you want to use, leave blank to make wxMediaCtrl figure it out. |
7c913512 | 247 | @param validator |
4cc4bfaf | 248 | validator to use. |
7c913512 | 249 | @param name |
4cc4bfaf | 250 | Window name. |
23324ae1 | 251 | */ |
0a98423e | 252 | wxMediaCtrl(wxWindow* parent, wxWindowID id, const wxString& fileName = wxEmptyString, |
5c3a762d | 253 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
0a98423e | 254 | long style = 0, const wxString& szBackend = wxEmptyString, |
adaaa686 | 255 | const wxValidator& validator = wxDefaultValidator, |
0a98423e | 256 | const wxString& name = "mediaCtrl"); |
23324ae1 | 257 | |
23324ae1 | 258 | /** |
ba1d7a6c FM |
259 | Creates this control. |
260 | Returns @false if it can't load the movie located at @a fileName | |
5c3a762d | 261 | or it cannot load one of its native backends. |
3c4f71cc | 262 | |
ba1d7a6c FM |
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. | |
3c4f71cc | 266 | |
5c3a762d | 267 | @param parent |
4cc4bfaf | 268 | parent of this control. Must not be @NULL. |
7c913512 | 269 | @param id |
4cc4bfaf | 270 | id to use for events |
7c913512 | 271 | @param fileName |
4cc4bfaf | 272 | If not empty, the path of a file to open. |
7c913512 | 273 | @param pos |
4cc4bfaf | 274 | Position to put control at. |
7c913512 | 275 | @param size |
4cc4bfaf | 276 | Size to put the control at and to stretch movie to. |
7c913512 | 277 | @param style |
4cc4bfaf | 278 | Optional styles. |
7c913512 | 279 | @param szBackend |
ba1d7a6c | 280 | Name of backend you want to use, leave blank to make wxMediaCtrl figure it out. |
7c913512 | 281 | @param validator |
4cc4bfaf | 282 | validator to use. |
7c913512 | 283 | @param name |
4cc4bfaf | 284 | Window name. |
23324ae1 | 285 | */ |
0a98423e | 286 | bool Create(wxWindow* parent, wxWindowID id, const wxString& fileName = wxEmptyString, |
5c3a762d | 287 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
0a98423e | 288 | long style = 0, const wxString& szBackend = wxEmptyString, |
adaaa686 | 289 | const wxValidator& validator = wxDefaultValidator, |
0a98423e | 290 | const wxString& name = "mediaCtrl"); |
23324ae1 FM |
291 | |
292 | /** | |
293 | Obtains the best size relative to the original/natural size of the | |
ba1d7a6c FM |
294 | video, if there is any. |
295 | See @ref mediactrl_video_size for more information. | |
23324ae1 | 296 | */ |
da1ed74c | 297 | wxSize GetBestSize() const; |
23324ae1 FM |
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. | |
5c3a762d FM |
303 | |
304 | @return zero on failure. | |
23324ae1 | 305 | */ |
16205a28 | 306 | double GetPlaybackRate(); |
23324ae1 FM |
307 | |
308 | /** | |
309 | Obtains the state the playback of the media is in - | |
3c4f71cc | 310 | |
5c3a762d FM |
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 | |
23324ae1 | 316 | */ |
43c48e1e | 317 | wxMediaState GetState(); |
23324ae1 FM |
318 | |
319 | /** | |
5c3a762d FM |
320 | Gets the volume of the media from a 0.0 to 1.0 range. |
321 | ||
ba1d7a6c FM |
322 | @note Due to rounding and other errors the value returned may not be the |
323 | exact value sent to SetVolume(). | |
23324ae1 FM |
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 | /** | |
5c3a762d | 333 | Loads the file that fileName refers to. Returns @false if loading fails. |
23324ae1 | 334 | */ |
5c3a762d | 335 | bool Load(const wxString& fileName); |
23324ae1 FM |
336 | |
337 | /** | |
ba1d7a6c | 338 | Loads the location that uri refers to. Note that this is very |
8cddee2d | 339 | implementation-dependent, although HTTP URI/URLs are generally |
ba1d7a6c | 340 | supported, for example. Returns @false if loading fails. |
23324ae1 | 341 | */ |
5c3a762d | 342 | bool Load(const wxURI& uri); |
23324ae1 FM |
343 | |
344 | /** | |
5c3a762d FM |
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. | |
23324ae1 | 348 | */ |
5c3a762d | 349 | bool Load(const wxURI& uri, const wxURI& proxy); |
23324ae1 FM |
350 | |
351 | /** | |
5c3a762d | 352 | Same as Load(const wxURI& uri). Kept for wxPython compatibility. |
23324ae1 | 353 | */ |
43c48e1e | 354 | bool LoadURI(const wxString& fileName); |
23324ae1 | 355 | |
5c3a762d | 356 | /** |
ba1d7a6c FM |
357 | Same as Load(const wxURI& uri, const wxURI& proxy). |
358 | Kept for wxPython compatibility. | |
5c3a762d | 359 | */ |
43c48e1e | 360 | bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy); |
23324ae1 FM |
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 | ||
23324ae1 FM |
372 | /** |
373 | Seeks to a position within the movie. | |
5c3a762d FM |
374 | |
375 | @todo Document the wxSeekMode parameter @a mode, and perhaps also the | |
376 | wxFileOffset and wxSeekMode themselves. | |
23324ae1 | 377 | */ |
43c48e1e | 378 | wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart); |
23324ae1 FM |
379 | |
380 | /** | |
5c3a762d | 381 | Sets the playback rate, or speed of the media, to that referred by @a dRate. |
23324ae1 FM |
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 | |
5c3a762d FM |
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. | |
23324ae1 FM |
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 | |
5c3a762d | 404 | provided by the underlying toolkit at will using ShowPlayerControls(). Simply |
23324ae1 FM |
405 | calling the function with default parameters tells wxMediaCtrl to use the |
406 | default controls provided by the toolkit. The function takes a | |
5c3a762d | 407 | wxMediaCtrlPlayerControls enumeration, please see available show modes there. |
3c4f71cc | 408 | |
ea53cb4a | 409 | For more info see @ref mediactrl_player_controls. |
3c4f71cc | 410 | |
5c3a762d FM |
411 | Currently only implemented on the QuickTime and DirectShow backends. |
412 | The function returns @true on success. | |
23324ae1 FM |
413 | */ |
414 | bool ShowPlayerControls(wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT); | |
415 | ||
416 | /** | |
417 | Stops the media. | |
5c3a762d | 418 | |
ba1d7a6c | 419 | See @ref mediactrl_operation for an overview of how stopping works. |
23324ae1 FM |
420 | */ |
421 | bool Stop(); | |
422 | ||
423 | /** | |
424 | Obtains the current position in time within the movie in milliseconds. | |
425 | */ | |
426 | wxFileOffset Tell(); | |
23324ae1 | 427 | }; |
e54c96f1 | 428 |