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
}
29 \wxheading{Include files
}
35 \helpref{wxMedia
}{librarieslist
}
37 \latexignore{\rtfignore{\wxheading{Members
}}}
40 \membersection{Rendering media
}\label{renderingmediawxmediactrl
}
42 Depending upon the backend, wxMediaCtrl can render
43 and display pretty much any kind of media that the native system can -
44 such as an image, mpeg video, or mp3 (without license restrictions -
45 since it relies on native system calls that may not technically
46 have mp3 decoding available, for example, it falls outside the
47 realm of licensing restrictions).
49 For general operation, all you need to do is call
50 \helpref{wxMediaCtrl::Load
}{wxmediactrlload
} to load the file
51 you want to render, catch the EVT
\_MEDIA\_LOADED event,
52 and then call
\helpref{wxMediaCtrl::Play
}{wxmediactrlplay
}
53 to show the video/audio of the media in that event.
55 More complex operations are generally more heavily dependant on the
56 capabilities of the backend. For example, QuickTime cannot set
57 the playback rate of certain streaming media - while DirectShow is
58 slightly more flexible in that regard.
61 \membersection{Operation
}\label{operationwxmediactrl
}
63 When wxMediaCtrl plays a file, it plays until the stop position
64 is reached (currently the end of the file/stream). Right before
65 it hits the end of the stream, it fires off a EVT
\_MEDIA\_STOP
66 event to its parent window, at which point the event handler
67 can choose to veto the event, preventing the stream from actually
72 //connect to the media event
73 this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction)
74 (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop);
77 void MyFrame::OnMediaStop(const wxMediaEvent& evt)
81 m_mediactrl->SetPosition(
82 m_mediactrl->GetDuration() <<
1
89 When wxMediaCtrl stops, either by the EVT
\_MEDIA\_STOP not being
90 vetoed, or by manually calling
91 \helpref{wxMediaCtrl::Stop
}{wxmediactrlstop
}, where it actually
92 stops is not at the beginning, rather, but at the beginning of
93 the stream. That is, when it stops and play is called, playback
94 is gauranteed to start at the beginning of the media. This is
95 because some streams are not seekable, and when stop is called
96 on them they return to the beginning, thus wxMediaCtrl tries
97 to keep consistant for all types of media.
99 Note that when changing the state of the media through Play()
100 and other methods, the media may not actually be in the
101 wxMEDIASTATE
\_PLAYING, for example. If you are relying on the
102 media being in certain state catch the event relevant to the state.
103 See
\helpref{wxMediaEvent
}{wxmediaevent
} for the kinds of events
107 \membersection{Video size
}\label{videosizewxmediactrl
}
109 By default, wxMediaCtrl will scale the size of the video to the
110 requested amount passed to either it's constructor or Create().
111 After calling Load or performing an equivilant operation, you
112 can subsequently obtain the "real" size of the video (if there
113 is any) by calling GetBestSize(). Note that the actual result
114 on the display will be slightly different when ShowPlayerControls
115 is activated and the actual video size will be less then
116 specified due to the extra controls provided by the native toolkit.
117 In addition, the backend may modify GetBestSize() to include the
118 size of the extra controls - so if you want the real size of the
119 video just disable ShowPlayerControls().
121 The idea with setting GetBestSize to the size of the video is
122 that GetBestSize is a wxWindow-derived function that is called
123 when sizers on a window recalculate. What this means is that
124 if you use sizers by default the video will show in it's
125 original size without any extra assistance needed from the user.
128 \membersection{Player controls
}\label{playercontrolswxmediactrl
}
130 Normally, when you use wxMediaCtrl it is just a window for the video to
131 play in. However, some toolkits have their own media player interface.
132 For example, QuickTime generally has a bar below the video with a slider.
133 A special feature available to wxMediaCtrl, you can use the toolkit's interface instead of
134 making your own by using the
\helpref{ShowPlayerControls()
}{wxmediactrlshowplayercontrols
}
135 function. There are several options for the flags parameter, with
136 the two general flags being wxMEDIACTRLPLAYERCONTROLS
\_NONE which turns off
137 the native interface, and wxMEDIACTRLPLAYERCONTROLS
\_DEFAULT which lets
138 wxMediaCtrl decide what native controls on the interface. Be sure to review
139 the caveats outlined in
\helpref{Video size
}{videosizewxmediactrl
} before
143 \membersection{Choosing a backend
}\label{choosingbackendwxmediactrl
}
145 Generally, you should almost certainly leave this part up to
146 wxMediaCtrl - but if you need a certain backend for a particular
147 reason, such as QuickTime for playing .mov files, all you need
148 to do to choose a specific backend is to pass the
149 name of the backend class to
150 \helpref{wxMediaCtrl::Create
}{wxmediactrlcreate
}.
152 The following are valid backend identifiers -
154 \begin{twocollist
}\itemsep=
0pt
155 \twocolitem{{\bf wxMEDIABACKEND
\_DIRECTSHOW}}{
156 Use ActiveMovie/DirectShow. Uses the native ActiveMovie
157 (I.E. DirectShow) control. Default backend on Windows and
158 supported by nearly all Windows versions, even some
159 Windows CE versions. May display a windows media player
160 logo while inactive.
}
161 \twocolitem{{\bf wxMEDIABACKEND
\_QUICKTIME}}{
162 Use QuickTime. Mac Only.
163 WARNING: May not working correctly embedded in a wxNotebook.
165 \twocolitem{{\bf wxMEDIABACKEND
\_GSTREAMER}}{
166 Use GStreamer. Unix Only. Requires GStreamer
0.8 along
167 with at the very least the xvimagesink, xoverlay, and
168 gst-play modules of gstreamer to function. You need the correct
169 modules to play the relavant files, for example the mad module
171 \twocolitem{{\bf wxMEDIABACKEND
\_WMP10}}{
172 Uses Windows Media Player
10 (Windows only) - works on mobile
173 machines with Windows Media Player
10 and desktop machines with
174 either Windows Media Player
9 or
10
178 Note that other backends such as wxMEDIABACKEND
\_MCI can now be
181 \membersection{Creating a backend
}\label{creatingabackendwxmediactrl
}
183 Creating a backend for wxMediaCtrl is a rather simple process. Simply derive
184 from wxMediaBackendCommonBase and implement the methods you want. The methods
185 in wxMediaBackend correspond to those in wxMediaCtrl except for CreateControl
186 which does the actual creation of the control, in cases where a custom control
187 is not needed you may simply call wxControl::Create.
189 You need to make sure to use the DECLARE
\_CLASS and IMPLEMENT
\_CLASS macros.
191 The only real tricky part is that you need to make sure the file in compiled
192 in, which if there are just backends in there will not happen and you may need
193 to use a force link hack (see http://www.wxwidgets.org/wiki/index.php/RTTI).
195 This is a rather simple example of how to create a backend in the
196 \helpref{wxActiveXContainer
}{wxactivexcontainer
} documentation.
198 \membersection{wxMediaCtrl::wxMediaCtrl
}\label{wxmediactrlwxmediactrl
}
200 \func{}{wxMediaCtrl
}{\void}
202 Default constructor - you
\tt{must
} call Create before calling any other methods
205 \func{}{wxMediaCtrl
}{
206 \param{wxWindow*
}{parent
},
207 \param{wxWindowID
}{id
},
208 \param{const wxString\&
}{fileName = wxT("")
},
209 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
210 \param{const wxSize\&
}{size = wxDefaultSize
},
211 \param{long
}{style =
0},
212 \param{const wxString\&
}{szBackend = wxT("")
},
213 \param{const wxValidator&
}{validator = wxDefaultValidator
},
214 \param{const wxString\&
}{name = wxPanelNameStr
}
217 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.
219 \docparam{parent
}{parent of this control. Must not be NULL.
}
220 \docparam{id
}{id to use for events
}
221 \docparam{fileName
}{If not empty, the path of a file to open.
}
222 \docparam{pos
}{Position to put control at.
}
223 \docparam{size
}{Size to put the control at and to stretch movie to.
}
224 \docparam{style
}{Optional styles.
}
225 \docparam{szBackend
}{Name of backend you want to use, leave blank to make
226 wxMediaCtrl figure it out.
}
227 \docparam{validator
}{validator to use.
}
228 \docparam{name
}{Window name.
}
231 \membersection{wxMediaCtrl::Create
}\label{wxmediactrlcreate
}
234 \param{wxWindow*
}{parent
},
235 \param{wxWindowID
}{id
},
236 \param{const wxString\&
}{fileName = wxT("")
},
237 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
238 \param{const wxSize\&
}{size = wxDefaultSize
},
239 \param{long
}{style =
0},
240 \param{const wxString\&
}{szBackend = wxT("")
},
241 \param{const wxValidator&
}{validator = wxDefaultValidator
},
242 \param{const wxString\&
}{name = wxPanelNameStr
}
245 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.
247 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.
249 \docparam{parent
}{parent of this control. Must not be NULL.
}
250 \docparam{id
}{id to use for events
}
251 \docparam{fileName
}{If not empty, the path of a file to open.
}
252 \docparam{pos
}{Position to put control at.
}
253 \docparam{size
}{Size to put the control at and to stretch movie to.
}
254 \docparam{style
}{Optional styles.
}
255 \docparam{szBackend
}{Name of backend you want to use, leave blank to make
256 wxMediaCtrl figure it out.
}
257 \docparam{validator
}{validator to use.
}
258 \docparam{name
}{Window name.
}
261 \membersection{wxMediaCtrl::GetBestSize
}\label{wxmediactrlgetbestsize
}
263 \func{wxSize
}{GetBestSize
}{\void}
265 Obtains the best size relative to the original/natural size of the
266 video, if there is any. See
\helpref{Video size
}{videosizewxmediactrl
}
267 for more information.
270 \membersection{wxMediaCtrl::GetPlaybackRate
}\label{wxmediactrlgetplaybackrate
}
272 \func{double
}{GetPlaybackrate
}{\void}
274 Obtains the playback rate, or speed of the media.
\tt{1.0} represents normal
275 speed, while
\tt{2.0} represents twice the normal speed of the media, for
276 example. Not supported on the GStreamer (Unix) backend.
277 Returns
0 on failure.
280 \membersection{wxMediaCtrl::GetVolume
}\label{wxmediactrlgetvolume
}
282 \func{double
}{GetVolume
}{\void}
284 Gets the volume of the media from a
0.0 to
1.0 range. Note that due to rounding
285 and other errors this may not be the exact value sent to SetVolume.
288 \membersection{wxMediaCtrl::GetState
}\label{wxmediactrlgetstate
}
290 \func{wxMediaCtrlState
}{GetState
}{\void}
292 Obtains the state the playback of the media is in -
295 \begin{twocollist
}\itemsep=
0pt
296 \twocolitem{{\bf wxMEDIASTATE
\_STOPPED}}{The movie has stopped.
}
297 \twocolitem{{\bf wxMEDIASTATE
\_PAUSED}}{The movie is paused.
}
298 \twocolitem{{\bf wxMEDIASTATE
\_PLAYING}}{The movie is currently playing.
}
302 \membersection{wxMediaCtrl::Length
}\label{wxmediactrllength
}
304 \func{wxFileOffset
}{Length
}{\void}
306 Obtains the length - the total amount of time the movie has in milliseconds.
309 \membersection{wxMediaCtrl::Load
}\label{wxmediactrlload
}
311 \func{bool
}{Load
}{\param{const wxString\&
}{fileName
}}
313 Loads the file that
\tt{fileName
} refers to. Returns false if loading fails.
316 \membersection{wxMediaCtrl::Load
}\label{wxmediactrlloaduri
}
318 \func{bool
}{Load
}{\param{const wxURI\&
}{uri
}}
320 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.
323 \membersection{wxMediaCtrl::Load
}\label{wxmediactrlloaduriwithproxy
}
325 \func{bool
}{Load
}{\param{const wxURI\&
}{uri
},
\param{const wxURI\&
}{proxy
}}
327 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.
330 \membersection{wxMediaCtrl::LoadURI
}\label{wxmediactrlloaduriliteral
}
332 \func{bool
}{LoadURI
}{\param{const wxURI\&
}{uri
}}
334 Same as
\helpref{Load
}{wxmediactrlloaduri
}. Kept for wxPython compatability.
337 \membersection{wxMediaCtrl::LoadURIWithProxy
}\label{wxmediactrlloaduriwithproxyliteral
}
339 \func{bool
}{LoadURIWithProxy
}{\param{const wxURI\&
}{uri
},
\param{const wxURI\&
}{proxy
}}
341 Same as
\helpref{Load
}{wxmediactrlloaduriwithproxy
}. Kept for wxPython compatability.
344 \membersection{wxMediaCtrl::Pause
}\label{wxmediactrlpause
}
346 \func{bool
}{Pause
}{\void}
348 Pauses playback of the movie.
351 \membersection{wxMediaCtrl::Play
}\label{wxmediactrlplay
}
353 \func{bool
}{Play
}{\void}
355 Resumes playback of the movie.
358 \membersection{wxMediaCtrl::Seek
}\label{wxmediactrlsetposition
}
360 \func{wxFileOffset
}{Seek
}{\param{wxFileOffset
}{where
},
\param{wxSeekMode
}{mode
}}
362 Seeks to a position within the movie.
365 \membersection{wxMediaCtrl::SetPlaybackRate
}\label{wxmediactrlsetplaybackrate
}
367 \func{bool
}{SetPlaybackRate
}{\param{double
}{dRate
}}
369 Sets the playback rate, or speed of the media, to that referred by
\tt{dRate
}.
370 \tt{1.0} represents normal speed, while
\tt{2.0} represents twice the normal
371 speed of the media, for example. Not supported on the GStreamer (Unix) backend.
372 Returns true if successful.
375 \membersection{wxMediaCtrl::SetVolume
}\label{wxmediactrlsetvolume
}
377 \func{bool
}{SetVolume
}{\param{double
}{dVolume
}}
379 Sets the volume of the media from a
0.0 to
1.0 range to that referred
380 by
\tt{dVolume
}.
\tt{1.0} represents full volume, while
\tt{0.5}
381 represents half (
50 percent) volume, for example. Note that this may not be
382 exact due to conversion and rounding errors, although setting the volume to
383 full or none is always exact. Returns true if successful.
386 \membersection{wxMediaCtrl::ShowPlayerControls
}\label{wxmediactrlshowplayercontrols
}
388 \func{bool
}{ShowPlayerControls
}{\param{wxMediaCtrlPlayerControls
}{flags = wxMEDIACTRLPLAYERCONTROLS
\_DEFAULT}}
390 A special feature to wxMediaCtrl. Applications using native toolkits such as
391 QuickTime usually have a scrollbar, play button, and more provided to
392 them by the toolkit. By default wxMediaCtrl does not do this. However, on
393 the directshow and quicktime backends you can show or hide the native controls
394 provided by the underlying toolkit at will using ShowPlayerControls. Simply
395 calling the function with default parameters tells wxMediaCtrl to use the
396 default controls provided by the toolkit. The function takes a
397 \tt{wxMediaCtrlPlayerControls
} enumeration as follows:
400 \begin{twocollist
}\itemsep=
0pt
401 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_NONE}}{No controls. return wxMediaCtrl to it's default state.
}
402 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_STEP}}{Step controls like fastfoward, step one frame etc.
}
403 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_VOLUME}}{Volume controls like the speaker icon, volume slider, etc.
}
404 \twocolitem{{\bf wxMEDIACTRLPLAYERCONTROLS
\_DEFAULT}}{Default controls for the toolkit. Currently a typedef for wxMEDIACTRLPLAYERCONTROLS
\_STEP and wxMEDIACTRLPLAYERCONTROLS
\_VOLUME.
}
407 For more see
\helpref{Player controls
}{playercontrolswxmediactrl
}. Currently
408 only implemented on the QuickTime and DirectShow backends. The function
409 returns true on success.
412 \membersection{wxMediaCtrl::Stop
}\label{wxmediactrlstop
}
414 \func{bool
}{Stop
}{\void}
418 See
\helpref{Operation
}{operationwxmediactrl
} for an overview of how
422 \membersection{wxMediaCtrl::Tell
}\label{wxmediactrlgetposition
}
424 \func{wxFileOffset
}{Tell
}{\void}
426 Obtains the current position in time within the movie in milliseconds.