1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxMediaCtrl docs
4 %% Author: Ryan Norton <wxprojects@comcast.net>
8 %% Copyright: (c) Ryan Norton
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxMediaCtrl
}}\label{wxmediactrl
}
14 wxMediaCtrl is a class for displaying types of
15 media, such as videos, audio files, natively through native codecs.
17 wxMediaCtrl uses native backends to render media, for example on Windows
18 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
23 \helpref{wxMediaEvent
}{wxmediaevent
}
25 \wxheading{Derived from
}
27 \helpref{wxControl
}{wxcontrol
}\\
28 \helpref{wxWindow
}{wxwindow
}\\
29 \helpref{wxEvtHandler
}{wxevthandler
}\\
30 \helpref{wxObject
}{wxobject
}
32 \wxheading{Include files
}
38 \helpref{wxMedia
}{librarieslist
}
40 \latexignore{\rtfignore{\wxheading{Members
}}}
43 \membersection{Rendering media
}\label{renderingmediawxmediactrl
}
45 Depending upon the backend, wxMediaCtrl can render
46 and display pretty much any kind of media that the native system can -
47 such as an image, mpeg video, or mp3 (without license restrictions -
48 since it relies on native system calls that may not technically
49 have mp3 decoding available, for example, it falls outside the
50 realm of licensing restrictions).
52 For general operation, all you need to do is call
53 \helpref{wxMediaCtrl::Load
}{wxmediactrlload
} to load the file
54 you want to render, catch the EVT
\_MEDIA\_LOADED event,
55 and then call
\helpref{wxMediaCtrl::Play
}{wxmediactrlplay
}
56 to show the video/audio of the media in that event.
58 More complex operations are generally more heavily dependant on the
59 capabilities of the backend. For example, QuickTime cannot set
60 the playback rate of certain streaming media - while DirectShow is
61 slightly more flexible in that regard.
64 \membersection{Operation
}\label{operationwxmediactrl
}
66 When wxMediaCtrl plays a file, it plays until the stop position
67 is reached (currently the end of the file/stream). Right before
68 it hits the end of the stream, it fires off a EVT
\_MEDIA\_STOP
69 event to its parent window, at which point the event handler
70 can choose to veto the event, preventing the stream from actually
75 //connect to the media event
76 this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction)
77 (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop);
80 void MyFrame::OnMediaStop(const wxMediaEvent& evt)
84 m_mediactrl->SetPosition(
85 m_mediactrl->GetDuration() <<
1
92 When wxMediaCtrl stops, either by the EVT
\_MEDIA\_STOP not being
93 vetoed, or by manually calling
94 \helpref{wxMediaCtrl::Stop
}{wxmediactrlstop
}, where it actually
95 stops is not at the beginning, rather, but at the beginning of
96 the stream. That is, when it stops and play is called, playback
97 is gauranteed to start at the beginning of the media. This is
98 because some streams are not seekable, and when stop is called
99 on them they return to the beginning, thus wxMediaCtrl tries
100 to keep consistant for all types of media.
102 Note that when changing the state of the media through Play()
103 and other methods, the media may not actually be in the
104 wxMEDIASTATE
\_PLAYING, for example. If you are relying on the
105 media being in certain state catch the event relevant to the state.
106 See
\helpref{wxMediaEvent
}{wxmediaevent
} for the kinds of events
110 \membersection{Video size
}\label{videosizewxmediactrl
}
112 By default, wxMediaCtrl will scale the size of the video to the
113 requested amount passed to either it's constructor or Create().
114 After calling Load or performing an equivilant operation, you
115 can subsequently obtain the "real" size of the video (if there
116 is any) by calling GetBestSize(). Note that the actual result
117 on the display will be slightly different when ShowPlayerControls
118 is activated and the actual video size will be less then
119 specified due to the extra controls provided by the native toolkit.
120 In addition, the backend may modify GetBestSize() to include the
121 size of the extra controls - so if you want the real size of the
122 video just disable ShowPlayerControls().
124 The idea with setting GetBestSize to the size of the video is
125 that GetBestSize is a wxWindow-derived function that is called
126 when sizers on a window recalculate. What this means is that
127 if you use sizers by default the video will show in it's
128 original size without any extra assistance needed from the user.
131 \membersection{Player controls
}\label{playercontrolswxmediactrl
}
133 Normally, when you use wxMediaCtrl it is just a window for the video to
134 play in. However, some toolkits have their own media player interface.
135 For example, QuickTime generally has a bar below the video with a slider.
136 A special feature available to wxMediaCtrl, you can use the toolkit's interface instead of
137 making your own by using the
\helpref{ShowPlayerControls()
}{wxmediactrlshowplayercontrols
}
138 function. There are several options for the flags parameter, with
139 the two general flags being wxMEDIACTRLPLAYERCONTROLS
\_NONE which turns off
140 the native interface, and wxMEDIACTRLPLAYERCONTROLS
\_DEFAULT which lets
141 wxMediaCtrl decide what native controls on the interface. Be sure to review
142 the caveats outlined in
\helpref{Video size
}{videosizewxmediactrl
} before
146 \membersection{Choosing a backend
}\label{choosingbackendwxmediactrl
}
148 Generally, you should almost certainly leave this part up to
149 wxMediaCtrl - but if you need a certain backend for a particular
150 reason, such as QuickTime for playing .mov files, all you need
151 to do to choose a specific backend is to pass the
152 name of the backend class to
153 \helpref{wxMediaCtrl::Create
}{wxmediactrlcreate
}.
155 The following are valid backend identifiers -
157 \begin{twocollist
}\itemsep=
0pt
158 \twocolitem{{\bf wxMEDIABACKEND
\_DIRECTSHOW}}{
159 Use ActiveMovie/DirectShow. Uses the native ActiveMovie
160 (I.E. DirectShow) control. Default backend on Windows and
161 supported by nearly all Windows versions, even some
162 Windows CE versions. May display a windows media player
163 logo while inactive.
}
164 \twocolitem{{\bf wxMEDIABACKEND
\_QUICKTIME}}{
165 Use QuickTime. Mac Only.
166 WARNING: May not working correctly embedded in a wxNotebook.
168 \twocolitem{{\bf wxMEDIABACKEND
\_GSTREAMER}}{
169 Use GStreamer. Unix Only. Requires GStreamer
0.8 along
170 with at the very least the xvimagesink, xoverlay, and
171 gst-play modules of gstreamer to function. You need the correct
172 modules to play the relavant files, for example the mad module
174 \twocolitem{{\bf wxMEDIABACKEND
\_WMP10}}{
175 Uses Windows Media Player
10 (Windows only) - works on mobile
176 machines with Windows Media Player
10 and desktop machines with
177 either Windows Media Player
9 or
10
181 Note that other backends such as wxMEDIABACKEND
\_MCI can now be
184 \membersection{Creating a backend
}\label{creatingabackendwxmediactrl
}
186 Creating a backend for wxMediaCtrl is a rather simple process. Simply derive
187 from wxMediaBackendCommonBase and implement the methods you want. The methods
188 in wxMediaBackend correspond to those in wxMediaCtrl except for CreateControl
189 which does the actual creation of the control, in cases where a custom control
190 is not needed you may simply call wxControl::Create.
192 You need to make sure to use the DECLARE
\_CLASS and IMPLEMENT
\_CLASS macros.
194 The only real tricky part is that you need to make sure the file in compiled
195 in, which if there are just backends in there will not happen and you may need
196 to use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI).
198 This is a rather simple example of how to create a backend in the
199 \helpref{wxActiveXContainer
}{wxactivexcontainer
} documentation.
201 \membersection{wxMediaCtrl::wxMediaCtrl
}\label{wxmediactrlwxmediactrl
}
203 \func{}{wxMediaCtrl
}{\void}
205 Default constructor - you
\tt{must
} call Create before calling any other methods
208 \func{}{wxMediaCtrl
}{
209 \param{wxWindow*
}{parent
},
210 \param{wxWindowID
}{id
},
211 \param{const wxString\&
}{fileName = wxT("")
},
212 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
213 \param{const wxSize\&
}{size = wxDefaultSize
},
214 \param{long
}{style =
0},
215 \param{const wxString\&
}{szBackend = wxT("")
},
216 \param{const wxValidator&
}{validator = wxDefaultValidator
},
217 \param{const wxString\&
}{name = wxPanelNameStr
}
220 Constructor that calls
\helpref{Create
}{wxmediactrlcreate
}. You may prefer to call
\helpref{Create
}{wxmediactrlcreate
} directly to check to see if wxMediaCtrl is available on the system.
222 \docparam{parent
}{parent of this control. Must not be NULL.
}
223 \docparam{id
}{id to use for events
}
224 \docparam{fileName
}{If not empty, the path of a file to open.
}
225 \docparam{pos
}{Position to put control at.
}
226 \docparam{size
}{Size to put the control at and to stretch movie to.
}
227 \docparam{style
}{Optional styles.
}
228 \docparam{szBackend
}{Name of backend you want to use, leave blank to make
229 wxMediaCtrl figure it out.
}
230 \docparam{validator
}{validator to use.
}
231 \docparam{name
}{Window name.
}
234 \membersection{wxMediaCtrl::Create
}\label{wxmediactrlcreate
}
237 \param{wxWindow*
}{parent
},
238 \param{wxWindowID
}{id
},
239 \param{const wxString\&
}{fileName = wxT("")
},
240 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
241 \param{const wxSize\&
}{size = wxDefaultSize
},
242 \param{long
}{style =
0},
243 \param{const wxString\&
}{szBackend = wxT("")
},
244 \param{const wxValidator&
}{validator = wxDefaultValidator
},
245 \param{const wxString\&
}{name = wxPanelNameStr
}
248 Creates this control. Returns
\tt{false
} if it can't load the movie located at
\tt{fileName
} or it cannot load one of its native backends.
250 If you specify a file to open via
\tt{fileName
} and you don't specify a backend to use, wxMediaCtrl tries each of its backends until one that can render the path referred to by
\tt{fileName
} can be found.
252 \docparam{parent
}{parent of this control. Must not be NULL.
}
253 \docparam{id
}{id to use for events
}
254 \docparam{fileName
}{If not empty, the path of a file to open.
}
255 \docparam{pos
}{Position to put control at.
}
256 \docparam{size
}{Size to put the control at and to stretch movie to.
}
257 \docparam{style
}{Optional styles.
}
258 \docparam{szBackend
}{Name of backend you want to use, leave blank to make
259 wxMediaCtrl figure it out.
}
260 \docparam{validator
}{validator to use.
}
261 \docparam{name
}{Window name.
}
264 \membersection{wxMediaCtrl::GetBestSize
}\label{wxmediactrlgetbestsize
}
266 \func{wxSize
}{GetBestSize
}{\void}
268 Obtains the best size relative to the original/natural size of the
269 video, if there is any. See
\helpref{Video size
}{videosizewxmediactrl
}
270 for more information.
273 \membersection{wxMediaCtrl::GetPlaybackRate
}\label{wxmediactrlgetplaybackrate
}
275 \func{double
}{GetPlaybackrate
}{\void}
277 Obtains the playback rate, or speed of the media.
\tt{1.0} represents normal
278 speed, while
\tt{2.0} represents twice the normal speed of the media, for
279 example. Not supported on the GStreamer (Unix) backend.
280 Returns
0 on failure.
283 \membersection{wxMediaCtrl::GetVolume
}\label{wxmediactrlgetvolume
}
285 \func{double
}{GetVolume
}{\void}
287 Gets the volume of the media from a
0.0 to
1.0 range. Note that due to rounding
288 and other errors this may not be the exact value sent to SetVolume.
291 \membersection{wxMediaCtrl::GetState
}\label{wxmediactrlgetstate
}
293 \func{wxMediaCtrlState
}{GetState
}{\void}
295 Obtains the state the playback of the media is in -
298 \begin{twocollist
}\itemsep=
0pt
299 \twocolitem{{\bf wxMEDIASTATE
\_STOPPED}}{The movie has stopped.
}
300 \twocolitem{{\bf wxMEDIASTATE
\_PAUSED}}{The movie is paused.
}
301 \twocolitem{{\bf wxMEDIASTATE
\_PLAYING}}{The movie is currently playing.
}
305 \membersection{wxMediaCtrl::Length
}\label{wxmediactrllength
}
307 \func{wxFileOffset
}{Length
}{\void}
309 Obtains the length - the total amount of time the movie has in milliseconds.
312 \membersection{wxMediaCtrl::Load
}\label{wxmediactrlload
}
314 \func{bool
}{Load
}{\param{const wxString\&
}{fileName
}}
316 Loads the file that
\tt{fileName
} refers to. Returns false if loading fails.
319 \membersection{wxMediaCtrl::Load
}\label{wxmediactrlloaduri
}
321 \func{bool
}{Load
}{\param{const wxURI\&
}{uri
}}
323 Loads the location that
\tt{uri
} refers to. Note that this is very implementation-dependant, although HTTP URI/URLs are generally supported, for example. Returns false if loading fails.
326 \membersection{wxMediaCtrl::Load
}\label{wxmediactrlloaduriwithproxy
}
328 \func{bool
}{Load
}{\param{const wxURI\&
}{uri
},
\param{const wxURI\&
}{proxy
}}
330 Loads the location that
\tt{uri
} refers to with the proxy
\tt{proxy
}. Not implemented on most backends so it should be called with caution. Returns false if loading fails.
333 \membersection{wxMediaCtrl::LoadURI
}\label{wxmediactrlloaduriliteral
}
335 \func{bool
}{LoadURI
}{\param{const wxURI\&
}{uri
}}
337 Same as
\helpref{Load
}{wxmediactrlloaduri
}. Kept for wxPython compatability.
340 \membersection{wxMediaCtrl::LoadURIWithProxy
}\label{wxmediactrlloaduriwithproxyliteral
}
342 \func{bool
}{LoadURIWithProxy
}{\param{const wxURI\&
}{uri
},
\param{const wxURI\&
}{proxy
}}
344 Same as
\helpref{Load
}{wxmediactrlloaduriwithproxy
}. Kept for wxPython compatability.
347 \membersection{wxMediaCtrl::Pause
}\label{wxmediactrlpause
}
349 \func{bool
}{Pause
}{\void}
351 Pauses playback of the movie.
354 \membersection{wxMediaCtrl::Play
}\label{wxmediactrlplay
}
356 \func{bool
}{Play
}{\void}
358 Resumes playback of the movie.
361 \membersection{wxMediaCtrl::Seek
}\label{wxmediactrlsetposition
}
363 \func{wxFileOffset
}{Seek
}{\param{wxFileOffset
}{where
},
\param{wxSeekMode
}{mode
}}
365 Seeks to a position within the movie.
368 \membersection{wxMediaCtrl::SetPlaybackRate
}\label{wxmediactrlsetplaybackrate
}
370 \func{bool
}{SetPlaybackRate
}{\param{double
}{dRate
}}
372 Sets the playback rate, or speed of the media, to that referred by
\tt{dRate
}.
373 \tt{1.0} represents normal speed, while
\tt{2.0} represents twice the normal
374 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
375 Returns true if successful.
378 \membersection{wxMediaCtrl::SetVolume
}\label{wxmediactrlsetvolume
}
380 \func{bool
}{SetVolume
}{\param{double
}{dVolume
}}
382 Sets the volume of the media from a
0.0 to
1.0 range to that referred
383 by
\tt{dVolume
}.
\tt{1.0} represents full volume, while
\tt{0.5}
384 represents half (
50 percent) volume, for example. Note that this may not be
385 exact due to conversion and rounding errors, although setting the volume to
386 full or none is always exact. Returns true if successful.
389 \membersection{wxMediaCtrl::ShowPlayerControls
}\label{wxmediactrlshowplayercontrols
}
391 \func{bool
}{ShowPlayerControls
}{\param{wxMediaCtrlPlayerControls
}{flags = wxMEDIACTRLPLAYERCONTROLS
\_DEFAULT}}
393 A special feature to wxMediaCtrl. Applications using native toolkits such as
394 QuickTime usually have a scrollbar, play button, and more provided to
395 them by the toolkit. By default wxMediaCtrl does not do this. However, on
396 the directshow and quicktime backends you can show or hide the native controls
397 provided by the underlying toolkit at will using ShowPlayerControls. Simply
398 calling the function with default parameters tells wxMediaCtrl to use the
399 default controls provided by the toolkit. The function takes a
400 \tt{wxMediaCtrlPlayerControls
} enumeration as follows:
403 \begin{twocollist
}\itemsep=
0pt
404 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_NONE}}{No controls. return wxMediaCtrl to it's default state.
}
405 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_STEP}}{Step controls like fastfoward, step one frame etc.
}
406 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_VOLUME}}{Volume controls like the speaker icon, volume slider, etc.
}
407 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_DEFAULT}}{Default controls for the toolkit. Currently a typedef for wxMEDIACTRLPLAYERCONTROLS
\_STEP and wxMEDIACTRLPLAYERCONTROLS
\_VOLUME.
}
410 For more see
\helpref{Player controls
}{playercontrolswxmediactrl
}. Currently
411 only implemented on the QuickTime and DirectShow backends. The function
412 returns true on success.
415 \membersection{wxMediaCtrl::Stop
}\label{wxmediactrlstop
}
417 \func{bool
}{Stop
}{\void}
421 See
\helpref{Operation
}{operationwxmediactrl
} for an overview of how
425 \membersection{wxMediaCtrl::Tell
}\label{wxmediactrlgetposition
}
427 \func{wxFileOffset
}{Tell
}{\void}
429 Obtains the current position in time within the movie in milliseconds.