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.
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 to load the file you want to render, catch the EVT_MEDIA_LOADED event, and then call 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.
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:
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, 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 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 for the kinds of events that you can catch.
By default, MediaCtrl will scale the size of the video to the requested amount passed to its constructor. After calling 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. Note that the actual result on the display will be slightly different when show_player_controls 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.
The idea with setting get_best_size to the size of the video is that
get_best_size is a function derived from Window that is
called when sizers 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.
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 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(Window parent,
Integer id,
String fileName = "",
Point pos = DEFAULT_POSITION,
Size size = DEFAULT_SIZE,
Integer style = 0,
String backend = "",
Validator validator = DEFAULT_VALIDATOR,
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.
Size get_best_size()
Obtains the best size relative to the original/natural size of the video, if there is any. See Video size for more information.
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.
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.
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. |
Integer length()
Obtains the length – the total amount of time the movie has in milliseconds.
Boolean load(String fileName)
Loads the file that fileName refers to. Returns false if loading fails.
Boolean load(URI 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.
Boolean load(URI uri, URI 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.
Boolean load_uri(URI uri)
Same as Load. Kept for Python compatability.
Boolean load_uri_with_proxy(URI uri, URI proxy)
Same as Load. Kept for Python compatability.
Boolean pause()
Pauses playback of the movie.
Boolean play()
Resumes playback of the movie.
Integer seek(FileOffset where, SeekMode mode)
Seeks to a position within the movie.
Boolean set_playback_rate(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.
Boolean set_volume(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.
Boolean show_player_controls(MediaCtrlPlayerControls 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. Currently only implemented on the QuickTime and DirectShow backends. The function returns true on success.
Boolean stop()
Stops the media.
See Operation for an overview of how stopping works.
Integer tell()
Obtains the current position in time within the movie in milliseconds.
[This page automatically generated from the Textile source at Thu May 01 00:50:41 +0100 2008]