revisions by Utensil Candel
[wxWidgets.git] / interface / wx / mediactrl.h
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(""), const wxValidatorvalidator = wxDefaultValidator,
226 const wxString& name = wxPanelNameStr );
227
228
229 /**
230 Creates this control. Returns @false if it can't load the movie located at @a fileName
231 or it cannot load one of its native backends.
232
233 If you specify a file to open via @a fileName and you don't specify a backend to
234 use, wxMediaCtrl tries each of its backends until one that can render the path referred to
235 by @a fileName can be found.
236
237 @param parent
238 parent of this control. Must not be @NULL.
239 @param id
240 id to use for events
241 @param fileName
242 If not empty, the path of a file to open.
243 @param pos
244 Position to put control at.
245 @param size
246 Size to put the control at and to stretch movie to.
247 @param style
248 Optional styles.
249 @param szBackend
250 Name of backend you want to use, leave blank to make
251 wxMediaCtrl figure it out.
252 @param validator
253 validator to use.
254 @param name
255 Window name.
256 */
257 bool Create( wxWindow* parent, wxWindowID id, const wxString& fileName = wxT(""),
258 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
259 long style = 0, const wxString& szBackend = wxT(""), const wxValidatorvalidator = wxDefaultValidator,
260 const wxString& name = wxPanelNameStr );
261
262 /**
263 Obtains the best size relative to the original/natural size of the
264 video, if there is any. See @ref class_mediactrl_video_size for more information.
265 */
266 wxSize GetBestSize();
267
268 /**
269 Obtains the playback rate, or speed of the media. @c 1.0 represents normal
270 speed, while @c 2.0 represents twice the normal speed of the media, for
271 example. Not supported on the GStreamer (Unix) backend.
272
273 @return zero on failure.
274 */
275 double GetPlaybackrate();
276
277 /**
278 Obtains the state the playback of the media is in -
279
280 @beginTable
281 @row2col{wxMEDIASTATE_STOPPED, The movie has stopped.}
282 @row2col{wxMEDIASTATE_PAUSED, The movie is paused.}
283 @row2col{wxMEDIASTATE_PLAYING, The movie is currently playing.}
284 @endTable
285 */
286 wxMediaCtrlState GetState();
287
288 /**
289 Gets the volume of the media from a 0.0 to 1.0 range.
290
291 @note Due to rounding and other errors the value returned may not be the exact value
292 sent to SetVolume().
293 */
294 double GetVolume();
295
296 /**
297 Obtains the length - the total amount of time the movie has in milliseconds.
298 */
299 wxFileOffset Length();
300
301 /**
302 Loads the file that fileName refers to. Returns @false if loading fails.
303 */
304 bool Load(const wxString& fileName);
305
306 /**
307 Loads the location that uri refers to. Note that this is very implementation-dependant,
308 although HTTP URI/URLs are generally supported, for example. Returns @false if loading fails.
309 */
310 bool Load(const wxURI& uri);
311
312 /**
313 Loads the location that @c uri refers to with the proxy @c proxy.
314 Not implemented on most backends so it should be called with caution.
315 Returns @false if loading fails.
316 */
317 bool Load(const wxURI& uri, const wxURI& proxy);
318
319 /**
320 Same as Load(const wxURI& uri). Kept for wxPython compatibility.
321 */
322 bool LoadURI(const wxURI& uri);
323
324 /**
325 Same as Load(const wxURI& uri, const wxURI& proxy). Kept for wxPython compatibility.
326 */
327 bool LoadURIWithProxy(const wxURI& uri, const wxURI& proxy);
328
329 /**
330 Pauses playback of the movie.
331 */
332 bool Pause();
333
334 /**
335 Resumes playback of the movie.
336 */
337 bool Play();
338
339 /**
340 Seeks to a position within the movie.
341
342 @todo Document the wxSeekMode parameter @a mode, and perhaps also the
343 wxFileOffset and wxSeekMode themselves.
344 */
345 wxFileOffset Seek(wxFileOffset where, wxSeekMode mode);
346
347 /**
348 Sets the playback rate, or speed of the media, to that referred by @a dRate.
349 @c 1.0 represents normal speed, while @c 2.0 represents twice the normal
350 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
351 Returns @true if successful.
352 */
353 bool SetPlaybackRate(double dRate);
354
355 /**
356 Sets the volume of the media from a 0.0 to 1.0 range to that referred
357 by @c dVolume. @c 1.0 represents full volume, while @c 0.5
358 represents half (50 percent) volume, for example.
359
360 @note The volume may not be exact due to conversion and rounding errors,
361 although setting the volume to full or none is always exact.
362 Returns @true if successful.
363 */
364 bool SetVolume(double dVolume);
365
366 /**
367 A special feature to wxMediaCtrl. Applications using native toolkits such as
368 QuickTime usually have a scrollbar, play button, and more provided to
369 them by the toolkit. By default wxMediaCtrl does not do this. However, on
370 the directshow and quicktime backends you can show or hide the native controls
371 provided by the underlying toolkit at will using ShowPlayerControls(). Simply
372 calling the function with default parameters tells wxMediaCtrl to use the
373 default controls provided by the toolkit. The function takes a
374 wxMediaCtrlPlayerControls enumeration, please see available show modes there.
375
376 For more see @ref class_mediactrl_player_controls.
377
378 Currently only implemented on the QuickTime and DirectShow backends.
379 The function returns @true on success.
380 */
381 bool ShowPlayerControls(wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT);
382
383 /**
384 Stops the media.
385
386 See @ref class_mediactrl_operation for an overview of how stopping works.
387 */
388 bool Stop();
389
390 /**
391 Obtains the current position in time within the movie in milliseconds.
392 */
393 wxFileOffset Tell();
394 };
395