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