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