]> git.saurik.com Git - wxWidgets.git/blob - interface/mediactrl.h
execute the usual cleanup code from EVT_END_SESSION handler under MSW, otherwise...
[wxWidgets.git] / interface / 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 @class wxMediaEvent
11 @wxheader{mediactrl.h}
12
13 Event wxMediaCtrl uses.
14
15 @library{wxmedia}
16 @category{FIXME}
17 */
18 class wxMediaEvent : public wxNotifyEvent
19 {
20 public:
21
22 };
23
24
25
26 /**
27 @class wxMediaCtrl
28 @wxheader{mediactrl.h}
29
30 wxMediaCtrl is a class for displaying types of
31 media, such as videos, audio files, natively through native codecs.
32
33 wxMediaCtrl uses native backends to render media, for example on Windows
34 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
35 QuickTime backend.
36
37 @library{wxmedia}
38 @category{media}
39
40 @see wxMediaEvent
41 */
42 class wxMediaCtrl : public wxControl
43 {
44 public:
45 //@{
46 /**
47 ,
48 wxPoint&
49
50 @param pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
52 long style = 0,
53 const wxString& szBackend = wxT(""),
54 const wxValidatorvalidator = wxDefaultValidator,
55 const wxString& name = wxPanelNameStr
56 )
57
58 Constructor that calls Create. You may prefer to call Create directly to check
59 to see if wxMediaCtrl is available on the system.
60
61 parent
62 parent of this control. Must not be @NULL.
63 @param id
64 id to use for events
65 @param fileName
66 If not empty, the path of a file to open.
67 @param pos
68 Position to put control at.
69 @param size
70 Size to put the control at and to stretch movie to.
71 @param style
72 Optional styles.
73 @param szBackend
74 Name of backend you want to use, leave blank to make
75 wxMediaCtrl figure it out.
76 @param validator
77 validator to use.
78 @param name
79 Window name.
80 */
81 wxMediaCtrl() const;
82 wxMediaCtrl(wxWindow* parent, wxWindowID id) const;
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
88 reason, such as QuickTime for playing .mov files, all you need
89 to do to choose a specific backend is to pass the
90 name of the backend class to
91 Create().
92 The following are valid backend identifiers -
93
94 @b wxMEDIABACKEND_DIRECTSHOW
95
96
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
101 logo while inactive.
102
103 @b wxMEDIABACKEND_QUICKTIME
104
105 Use QuickTime. Mac Only.
106 WARNING: May not working correctly embedded in a wxNotebook.
107
108 @b wxMEDIABACKEND_GSTREAMER
109
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.
115
116 @b wxMEDIABACKEND_WMP10
117
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
121
122 Note that other backends such as wxMEDIABACKEND_MCI can now be
123 found at wxCode.
124 */
125
126
127 /**
128 ,
129 wxPoint&
130
131 @param pos = wxDefaultPosition,
132 const wxSize& size = wxDefaultSize,
133 long style = 0,
134 const wxString& szBackend = wxT(""),
135 const wxValidatorvalidator = wxDefaultValidator,
136 const wxString& name = wxPanelNameStr
137 )
138
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.
141
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.
144
145 parent
146 parent of this control. Must not be @NULL.
147 @param id
148 id to use for events
149 @param fileName
150 If not empty, the path of a file to open.
151 @param pos
152 Position to put control at.
153 @param size
154 Size to put the control at and to stretch movie to.
155 @param style
156 Optional styles.
157 @param szBackend
158 Name of backend you want to use, leave blank to make
159 wxMediaCtrl figure it out.
160 @param validator
161 validator to use.
162 @param name
163 Window name.
164 */
165 bool Create(wxWindow* parent, wxWindowID id) const;
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.
173 You need to make sure to use the DECLARE_CLASS and IMPLEMENT_CLASS macros.
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).
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 -
199
200 @b wxMEDIASTATE_STOPPED
201
202 The movie has stopped.
203
204 @b wxMEDIASTATE_PAUSED
205
206 The movie is paused.
207
208 @b wxMEDIASTATE_PLAYING
209
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.
248 Example:
249
250 When wxMediaCtrl stops, either by the EVT_MEDIA_STOP not being
251 vetoed, or by manually calling
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
255 is gauranteed to start at the beginning of the media. This is
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.
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
296 and display pretty much any kind of media that the native system can -
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).
301 For general operation, all you need to do is call
302 Load() to load the file
303 you want to render, catch the EVT_MEDIA_LOADED event,
304 and then call Play()
305 to show the video/audio of the media in that event.
306 More complex operations are generally more heavily dependant on the
307 capabilities of the backend. For example, QuickTime cannot set
308 the playback rate of certain streaming media - while DirectShow is
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:
344
345 @b wxMEDIACTRLPLAYERCONTROLS_NONE
346
347 No controls. return wxMediaCtrl to it's default state.
348
349 @b wxMEDIACTRLPLAYERCONTROLS_STEP
350
351 Step controls like fastfoward, step one frame etc.
352
353 @b wxMEDIACTRLPLAYERCONTROLS_VOLUME
354
355 Volume controls like the speaker icon, volume slider, etc.
356
357 @b wxMEDIACTRLPLAYERCONTROLS_DEFAULT
358
359 Default controls for the toolkit. Currently a typedef for
360 wxMEDIACTRLPLAYERCONTROLS_STEP and wxMEDIACTRLPLAYERCONTROLS_VOLUME.
361
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.
371 See Operation() for an overview of how
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().
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 };
400