]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/mediactrl.h
even more interface fixes
[wxWidgets.git] / interface / wx / mediactrl.h
CommitLineData
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
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
FM
67
68 wxMediaCtrl is a class for displaying types of
23324ae1 69 media, such as videos, audio 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
23324ae1
FM
75 @library{wxmedia}
76 @category{media}
7c913512 77
e54c96f1 78 @see wxMediaEvent
5c3a762d
FM
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.
23324ae1
FM
190*/
191class wxMediaCtrl : public wxControl
192{
193public:
23324ae1 194 /**
5c3a762d
FM
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
23324ae1 201 to see if wxMediaCtrl is available on the system.
3c4f71cc 202
5c3a762d 203 @param parent
4cc4bfaf 204 parent of this control. Must not be @NULL.
7c913512 205 @param id
4cc4bfaf 206 id to use for events
7c913512 207 @param fileName
4cc4bfaf 208 If not empty, the path of a file to open.
7c913512 209 @param pos
4cc4bfaf 210 Position to put control at.
7c913512 211 @param size
4cc4bfaf 212 Size to put the control at and to stretch movie to.
7c913512 213 @param style
4cc4bfaf 214 Optional styles.
7c913512 215 @param szBackend
4cc4bfaf
FM
216 Name of backend you want to use, leave blank to make
217 wxMediaCtrl figure it out.
7c913512 218 @param validator
4cc4bfaf 219 validator to use.
7c913512 220 @param name
4cc4bfaf 221 Window name.
23324ae1 222 */
adaaa686 223 wxMediaCtrl(wxWindow* parent, wxWindowID id, const wxString& fileName = wxT(""),
5c3a762d 224 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
adaaa686
FM
225 long style = 0, const wxString& szBackend = wxT(""),
226 const wxValidator& validator = wxDefaultValidator,
227 const wxString& name = wxPanelNameStr);
23324ae1
FM
228
229
230 /**
5c3a762d
FM
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.
3c4f71cc 233
5c3a762d
FM
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.
3c4f71cc 237
5c3a762d 238 @param parent
4cc4bfaf 239 parent of this control. Must not be @NULL.
7c913512 240 @param id
4cc4bfaf 241 id to use for events
7c913512 242 @param fileName
4cc4bfaf 243 If not empty, the path of a file to open.
7c913512 244 @param pos
4cc4bfaf 245 Position to put control at.
7c913512 246 @param size
4cc4bfaf 247 Size to put the control at and to stretch movie to.
7c913512 248 @param style
4cc4bfaf 249 Optional styles.
7c913512 250 @param szBackend
4cc4bfaf
FM
251 Name of backend you want to use, leave blank to make
252 wxMediaCtrl figure it out.
7c913512 253 @param validator
4cc4bfaf 254 validator to use.
7c913512 255 @param name
4cc4bfaf 256 Window name.
23324ae1 257 */
adaaa686 258 bool Create(wxWindow* parent, wxWindowID id, const wxString& fileName = wxT(""),
5c3a762d 259 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
adaaa686
FM
260 long style = 0, const wxString& szBackend = wxT(""),
261 const wxValidator& validator = wxDefaultValidator,
262 const wxString& name = wxPanelNameStr);
23324ae1
FM
263
264 /**
265 Obtains the best size relative to the original/natural size of the
5c3a762d 266 video, if there is any. See @ref class_mediactrl_video_size for more information.
23324ae1
FM
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.
5c3a762d
FM
274
275 @return zero on failure.
23324ae1
FM
276 */
277 double GetPlaybackrate();
278
279 /**
280 Obtains the state the playback of the media is in -
3c4f71cc 281
5c3a762d
FM
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
23324ae1
FM
287 */
288 wxMediaCtrlState GetState();
289
290 /**
5c3a762d
FM
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().
23324ae1
FM
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 /**
5c3a762d 304 Loads the file that fileName refers to. Returns @false if loading fails.
23324ae1 305 */
5c3a762d 306 bool Load(const wxString& fileName);
23324ae1
FM
307
308 /**
5c3a762d
FM
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.
23324ae1 311 */
5c3a762d 312 bool Load(const wxURI& uri);
23324ae1
FM
313
314 /**
5c3a762d
FM
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.
23324ae1 318 */
5c3a762d 319 bool Load(const wxURI& uri, const wxURI& proxy);
23324ae1
FM
320
321 /**
5c3a762d 322 Same as Load(const wxURI& uri). Kept for wxPython compatibility.
23324ae1 323 */
5c3a762d 324 bool LoadURI(const wxURI& uri);
23324ae1 325
5c3a762d
FM
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);
23324ae1
FM
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
23324ae1
FM
341 /**
342 Seeks to a position within the movie.
5c3a762d
FM
343
344 @todo Document the wxSeekMode parameter @a mode, and perhaps also the
345 wxFileOffset and wxSeekMode themselves.
23324ae1
FM
346 */
347 wxFileOffset Seek(wxFileOffset where, wxSeekMode mode);
348
349 /**
5c3a762d 350 Sets the playback rate, or speed of the media, to that referred by @a dRate.
23324ae1
FM
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
5c3a762d
FM
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.
23324ae1
FM
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
5c3a762d 373 provided by the underlying toolkit at will using ShowPlayerControls(). Simply
23324ae1
FM
374 calling the function with default parameters tells wxMediaCtrl to use the
375 default controls provided by the toolkit. The function takes a
5c3a762d 376 wxMediaCtrlPlayerControls enumeration, please see available show modes there.
3c4f71cc 377
5c3a762d 378 For more see @ref class_mediactrl_player_controls.
3c4f71cc 379
5c3a762d
FM
380 Currently only implemented on the QuickTime and DirectShow backends.
381 The function returns @true on success.
23324ae1
FM
382 */
383 bool ShowPlayerControls(wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT);
384
385 /**
386 Stops the media.
5c3a762d
FM
387
388 See @ref class_mediactrl_operation for an overview of how stopping works.
23324ae1
FM
389 */
390 bool Stop();
391
392 /**
393 Obtains the current position in time within the movie in milliseconds.
394 */
395 wxFileOffset Tell();
23324ae1 396};
e54c96f1 397