Wt
3.2.0
|
Abstract baseclass for native media elements. More...
#include <Wt/WAbstractMedia>
Public Types | |
enum | Options { Autoplay = 1, Loop = 2, Controls = 4 } |
Enumeration for playback options. More... | |
enum | PreloadMode { PreloadNone, PreloadAuto, PreloadMetadata } |
Enumeration for preload strategy. More... | |
enum | ReadyState { HaveNothing = 0, HaveMetaData = 1, HaveCurrentData = 2, HaveFutureData = 3, HaveEnoughData = 4 } |
The HTML5 media ReadyState flag indicates how much of the media is loaded. More... | |
Public Member Functions | |
WAbstractMedia (WContainerWidget *parent=0) | |
Consctructor for a media widget. | |
void | setOptions (const WFlags< Options > &flags) |
Set the media element options. | |
WFlags< Options > | getOptions () const |
Retrieve the configured options. | |
void | setPreloadMode (PreloadMode mode) |
Set the preload mode. | |
PreloadMode | preloadMode () const |
Retrieve the preload mode. | |
void | clearSources () |
Removes all source elements. | |
void | addSource (const WLink &source, const std::string &type="", const std::string &media="") |
Add a media source. | |
void | setAlternativeContent (WWidget *alternative) |
Content to be shown when media cannot be played. | |
void | play () |
Invoke play() on the media element. | |
void | pause () |
Invoke pause() on the media element. | |
bool | playing () const |
Returns whether the media is playing. | |
ReadyState | readyState () const |
Returns the media's readyState. | |
EventSignal & | playbackStarted () |
Event signal emitted when playback has begun. | |
EventSignal & | playbackPaused () |
Event signal emitted when the playback has paused. | |
EventSignal & | ended () |
Event signal emitted when the playback stopped because the end of the media was reached. | |
EventSignal & | timeUpdated () |
Event signal emitted when the current playback position has changed. | |
EventSignal & | volumeChanged () |
Event signal emitted when the playback volume has changed. | |
std::string | jsMediaRef () const |
Returns the JavaScript reference to the media object, or null. |
Abstract baseclass for native media elements.
This class is an abstract base class for HTML5 media elements (<audio>, <video>).
The HTML5 media ReadyState flag indicates how much of the media is loaded.
This is often used in conjunction with the > operator, e.g. readyState() > HaveCurrentData
WAbstractMedia::WAbstractMedia | ( | WContainerWidget * | parent = 0 | ) |
Consctructor for a media widget.
A freshly constructed media widget has no options set, no media sources, and has preload mode set to PreloadAuto.
void WAbstractMedia::addSource | ( | const WLink & | source, |
const std::string & | type = "" , |
||
const std::string & | media = "" |
||
) |
Add a media source.
This method specifies a media source (which may be a URL or dynamic resource). You may add as many media sources as you want. The browser will select the appropriate media stream to display to the user.
This method specifies a media source using the URL, the mime type, and the media attribute. HTML allows for empty type and media attributes.
void WAbstractMedia::clearSources | ( | ) |
Removes all source elements.
This method can be used to remove all media sources. Afterward, you may add new media sources with calls to addSource().
Use this to reuse a WAbstractMedia instantiation to play something else.
EventSignal & WAbstractMedia::ended | ( | ) |
Event signal emitted when the playback stopped because the end of the media was reached.
std::string WAbstractMedia::jsMediaRef | ( | ) | const |
Returns the JavaScript reference to the media object, or null.
It is possible, for browser compatibility reasons, that jsRef() is not the media element. jsMediaRef() is guaranteed to be an expression that evaluates to the media object. This expression may yield null, if the video object is not rendered at all (e.g. on older versions of Internet Explorer).
void WAbstractMedia::pause | ( | ) |
Invoke pause() on the media element.
JavaScript must be available for this function to work.
void WAbstractMedia::play | ( | ) |
Invoke play() on the media element.
JavaScript must be available for this function to work.
EventSignal & WAbstractMedia::playbackPaused | ( | ) |
Event signal emitted when the playback has paused.
EventSignal & WAbstractMedia::playbackStarted | ( | ) |
Event signal emitted when playback has begun.
This event fires when play was invoked, or when the media element starts playing because the Autoplay option was provided.
void WAbstractMedia::setAlternativeContent | ( | WWidget * | alternative | ) |
Content to be shown when media cannot be played.
As not all browsers are HTML5 compliant, it is a good idea to provide fallback options when the media cannot be displayed. If the media can be played by the browser, the alternative content will be suppressed.
The two reasons to display the alternative content are (1) the media tag is not supported, or (2) the media tag is supported, but none of the media sources are supported by the browser. In the first case, fall-back is automatic and does not rely on JavaScript in the browser; in the latter case, JavaScript is required to make the fallback work.
The alternative content can be any widget: you can set it to an alternative media player (QuickTime, Flash, ...), show a Flash movie, an animated gif, a text, a poster image, ...
void WAbstractMedia::setOptions | ( | const WFlags< Options > & | flags | ) |
Set the media element options.
EventSignal & WAbstractMedia::timeUpdated | ( | ) |
Event signal emitted when the current playback position has changed.
This event is fired when the playback position has changed, both when the media is in a normal playing mode, but also when it has changed discontinuously because of another reason.
EventSignal & WAbstractMedia::volumeChanged | ( | ) |
Event signal emitted when the playback volume has changed.