h1(#wxmediactrl). Wx::MediaCtrl
MediaCtrl is a class for displaying types of media, such as videos,
audio files, natively through native codecs. MediaCtrl uses native
backends to render media, for example on Windows there is a
ActiveMovie/DirectShow backend, and on Macintosh there is a QuickTime
backend.
h2. See also
"MediaEvent":mediaevent.html
h2. Derived from
"Control":control.html
h2. Methods
* "Rendering media":#MediaCtrl_media
* "Operation":#MediaCtrl_Operation
* "Video size":#MediaCtrl_size
* "Player controls":#MediaCtrl_controls
* "Choosing a backend":#MediaCtrl_backend
* "Creating a backend":#MediaCtrl_backend
* "MediaCtrl.new":#MediaCtrl_new
* "MediaCtrl#create":#MediaCtrl_create
* "MediaCtrl#get_best_size":#MediaCtrl_getbestsize
* "MediaCtrl#get_playback_rate":#MediaCtrl_getplaybackrate
* "MediaCtrl#get_volume":#MediaCtrl_getvolume
* "MediaCtrl#get_state":#MediaCtrl_getstate
* "MediaCtrl#length":#MediaCtrl_length
* "MediaCtrl#load":#MediaCtrl_load
* "MediaCtrl#load":#MediaCtrl_load
* "MediaCtrl#load":#MediaCtrl_load
* "MediaCtrl#load_uri":#MediaCtrl_loaduri
* "MediaCtrl#load_uri_with_proxy":#MediaCtrl_loaduriwithproxy
* "MediaCtrl#pause":#MediaCtrl_pause
* "MediaCtrl#play":#MediaCtrl_play
* "MediaCtrl#seek":#MediaCtrl_seek
* "MediaCtrl#set_playback_rate":#MediaCtrl_setplaybackrate
* "MediaCtrl#set_volume":#MediaCtrl_setvolume
* "MediaCtrl#show_player_controls":#MediaCtrl_showplayercontrols
* "MediaCtrl#stop":#MediaCtrl_stop
* "MediaCtrl#tell":#MediaCtrl_tell
h3(#renderingmediawxmediactrl). Rendering media
Depending upon the backend, MediaCtrl can render
and display pretty much any kind of media that the native system can -
such as an image, mpeg video, or mp3 (without license restrictions -
since it relies on native system calls that may not technically
have mp3 decoding available, for example, it falls outside the
realm of licensing restrictions).
For general operation, all you need to do is call
"MediaCtrl#load":mediactrl.html#MediaCtrl_load to load the file
you want to render, catch the EVT_MEDIA_LOADED event,
and then call "MediaCtrl#play":mediactrl.html#MediaCtrl_play
to show the video/audio of the media in that event.
More complex operations are generally more heavily dependant on the
capabilities of the backend. For example, QuickTime cannot set
the playback rate of certain streaming media - while DirectShow is
slightly more flexible in that regard.
h3(#operationwxmediactrl). Operation
When MediaCtrl plays a file, it plays until the stop position
is reached (currently the end of the file/stream). Right before
it hits the end of the stream, it fires off a EVT_MEDIA_STOP
event to its parent window, at which point the event handler
can choose to veto the event, preventing the stream from actually
stopping.
Example:
# connect to the media event
evt_media_stop mediactrl, :on_media_stop
def on_media_stop(evt)
if user_wants_to_seek
mediactrl.position = mediactrl.duration << 1
evt.veto
end
end
When MediaCtrl stops, either by the EVT_MEDIA_STOP not being vetoed, or
by manually calling "MediaCtrl#stop":mediactrl.html#MediaCtrl_stop,
where it actually stops is not at the beginning, rather, but at the
beginning of the stream. That is, when it stops and play is called,
playback is gauranteed to start at the beginning of the media. This is
because some streams are not seekable, and when stop is called on them
they return to the beginning, thus MediaCtrl tries to keep consistant
for all types of media.
Note that when changing the state of the media through
"play":#Mediactrl_play and other methods, the media may not actually be
in the MEDIASTATE_PLAYING, for example. If you are relying on the media
being in certain state catch the event relevant to the state. See
"MediaEvent":mediaevent.html for the kinds of events that you can catch.
h3(#videosizewxmediactrl). Video size
By default, MediaCtrl will scale the size of the video to the requested
amount passed to its constructor. After calling "load":#MediaCtrl_load
or performing an equivalent operation, you can subsequently obtain the
"real" size of the video (if there is any) by calling
"get_best_size":#MediaCtrl_getbestsize. Note that the actual result on
the display will be slightly different when
"show_player_controls":#MediaCtrl_showplayercontrols is activated and
the actual video size will be less then specified due to the extra
controls provided by the native toolkit. In addition, the backend may
modify get_best_size() to include the size of the extra controls - so if
you want the real size of the video just disable
"show_player_controls":#MediaCtrl_showplayercontrols.
The idea with setting @get_best_size@ to the size of the video is that
@get_best_size@ is a function derived from "Window":window.html that is
called when "sizers":sizer.html on a window recalculate. What this means
is that if you use sizers by default the video will show in it's
original size without any extra assistance needed from the user.
h3(#playercontrolswxmediactrl). Player controls
Normally, when you use MediaCtrl it is just a window for the video to
play in. However, some toolkits have their own media player interface.
For example, QuickTime generally has a bar below the video with a
slider. A special feature available to MediaCtrl, you can use the
toolkit's interface instead of making your own by using the
"show_player_controls":#MediaCtrl_showplayercontrols method.
There are several options for the flags parameter, with the two general
flags being MEDIACTRLPLAYERCONTROLS_NONE which turns off the native
interface, and MEDIACTRLPLAYERCONTROLS_DEFAULT which lets MediaCtrl
decide what native controls on the interface.
h3(#MediaCtrl_wxmediactrl). MediaCtrl.new
MediaCtrl *new*(%(arg-type)"Window":window.html% parent,
%(arg-type)Integer% id,
%(arg-type)String% fileName = "",
%(arg-type)"Point":point.html% pos = DEFAULT_POSITION,
%(arg-type)"Size":size.html% size = DEFAULT_SIZE,
%(arg-type)Integer% style = 0,
%(arg-type)String% backend = "",
%(arg-type)"Validator":validator.html% validator = DEFAULT_VALIDATOR,
%(arg-type)String% name = PanelNameStr )
Creates this control. Returns @false@ if it can't load the movie
located at @fileName@ or it cannot load one of its native backends. Note
that the @backend@ argument is ignore.
If you specify a file to open via @fileName@ and you don't specify a
backend to use, MediaCtrl tries each of its backends until one that can
render the path referred to by @fileName@ can be found.
* _parent_ parent of this control. Must not be NULL.
* _id_ id to use for events
* _fileName_ If not empty, the path of a file to open.
* _pos_ Position to put control at.
* _size_ Size to put the control at and to stretch movie to.
* _style_ Optional styles.
* _backend_ Not used
* _validator_ validator to use.
* _name_ Window name.
h3(#MediaCtrl_getbestsize). MediaCtrl#get_best_size
"Size":size.html *get_best_size*()
Obtains the best size relative to the original/natural size of the
video, if there is any. See "Video size":#videosizewxmediactrl for more
information.
h3(#MediaCtrl_getplaybackrate). MediaCtrl#get_playback_rate
Float *get_playbackrate*()
Obtains the playback rate, or speed of the media. @1.0@ represents normal
speed, while @2.0@ represents twice the normal speed of the media, for
example. Not supported on the GStreamer (Unix) backend.
Returns 0 on failure.
h3(#MediaCtrl_getvolume). MediaCtrl#get_volume
double *get_volume*()
Gets the volume of the media from a 0.0 to 1.0 range. Note that due to rounding
and other errors this may not be the exact value sent to SetVolume.
h3(#MediaCtrl_getstate). MediaCtrl#get_state
Integer *get_state*()
Obtains the state the playback of the media is in; the return value will
be one of the following constants:
|*Wx::MEDIASTATE_STOPPED*|The movie has stopped.|
|*Wx::MEDIASTATE_PAUSED*|The movie is paused.|
|*Wx::MEDIASTATE_PLAYING*|The movie is currently playing.|
h3(#MediaCtrl_length). MediaCtrl#length
Integer *length*()
Obtains the length - the total amount of time the movie has in milliseconds.
h3(#MediaCtrl_load). MediaCtrl#load
Boolean *load*(%(arg-type)String% fileName)
Loads the file that @fileName@ refers to. Returns false if loading fails.
h3(#MediaCtrl_loaduri). MediaCtrl#load
Boolean *load*(%(arg-type)"URI":uri.html% uri)
Loads the location that @uri@ refers to. Note that this is very implementation-dependant, although HTTP URI/URLs are generally supported, for example. Returns false if loading fails.
h3(#MediaCtrl_loaduriwithproxy). MediaCtrl#load
Boolean *load*(%(arg-type)"URI":uri.html% uri, %(arg-type)"URI":uri.html% proxy)
Loads the location that @uri@ refers to with the proxy @proxy@. Not implemented on most backends so it should be called with caution. Returns false if loading fails.
h3(#MediaCtrl_loaduriliteral). MediaCtrl#load_uri
Boolean *load_uri*(%(arg-type)"URI":uri.html% uri)
Same as "Load":mediactrlloaduri.html. Kept for Python compatability.
h3(#MediaCtrl_loaduriwithproxyliteral). MediaCtrl#load_uri_with_proxy
Boolean *load_uri_with_proxy*(%(arg-type)"URI":uri.html% uri, %(arg-type)"URI":uri.html% proxy)
Same as "Load":mediactrlloaduriwithproxy.html. Kept for Python compatability.
h3(#MediaCtrl_pause). MediaCtrl#pause
Boolean *pause*()
Pauses playback of the movie.
h3(#MediaCtrl_play). MediaCtrl#play
Boolean *play*()
Resumes playback of the movie.
h3(#MediaCtrl_setposition). MediaCtrl#seek
Integer *seek*(%(arg-type)"FileOffset":fileoffset.html% where, %(arg-type)"SeekMode":seekmode.html% mode)
Seeks to a position within the movie.
h3(#MediaCtrl_setplaybackrate). MediaCtrl#set_playback_rate
Boolean *set_playback_rate*(%(arg-type)Float% dRate)
Sets the playback rate, or speed of the media, to that referred by @dRate@.
@1.0@ represents normal speed, while @2.0@ represents twice the normal
speed of the media, for example. Not supported on the GStreamer (Unix) backend.
Returns true if successful.
h3(#MediaCtrl_setvolume). MediaCtrl#set_volume
Boolean *set_volume*(%(arg-type)Float% dVolume)
Sets the volume of the media from a 0.0 to 1.0 range to that referred
by @dVolume@. @1.0@ represents full volume, while @0.5@
represents half (50 percent) volume, for example. Note that this may not be
exact due to conversion and rounding errors, although setting the volume to
full or none is always exact. Returns true if successful.
h3(#MediaCtrl_showplayercontrols). MediaCtrl#show_player_controls
Boolean *show_player_controls*(%(arg-type)"MediaCtrlPlayerControls":mediactrlplayercontrols.html% flags = MEDIACTRLPLAYERCONTROLS_DEFAULT)
A special feature to MediaCtrl. Applications using native toolkits such as
QuickTime usually have a scrollbar, play button, and more provided to
them by the toolkit. By default MediaCtrl does not do this. However, on
the directshow and quicktime backends you can show or hide the native controls
provided by the underlying toolkit at will using ShowPlayerControls. Simply
calling the function with default parameters tells MediaCtrl to use the
default controls provided by the toolkit. The function takes a
@MediaCtrlPlayerControls@ enumeration as follows:
|*MEDIACTRLPLAYERCONTROLS_NONE*|No controls. return MediaCtrl to it's default state.|
|*MEDIACTRLPLAYERCONTROLS_STEP*|Step controls like fastfoward, step one frame etc.|
|*MEDIACTRLPLAYERCONTROLS_VOLUME*|Volume controls like the speaker icon, volume slider, etc.|
|*MEDIACTRLPLAYERCONTROLS_DEFAULT*|Default controls for the toolkit. Currently a typedef for MEDIACTRLPLAYERCONTROLS_STEP and MEDIACTRLPLAYERCONTROLS_VOLUME.|
For more see "Player controls":playercontrolswxmediactrl.html. Currently
only implemented on the QuickTime and DirectShow backends. The function
returns true on success.
h3(#MediaCtrl_stop). MediaCtrl#stop
Boolean *stop*()
Stops the media.
See "Operation":operationwxmediactrl.html for an overview of how
stopping works.
h3(#MediaCtrl_getposition). MediaCtrl#tell
Integer *tell*()
Obtains the current position in time within the movie in milliseconds.