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