Wt
3.2.3
|
A media player. More...
#include <Wt/WMediaPlayer>
Public Types | |
enum | Encoding { PosterImage, MP3, M4A, OGA, WAV, WEBMA, FLA, M4V, OGV, WEBMV, FLV } |
An enumeration for a media encoding. More... | |
enum | MediaType { Audio, Video } |
An enumeration for a media type. More... | |
enum | ButtonControlId { VideoPlay, Play, Pause, Stop, VolumeMute, VolumeUnmute, VolumeMax, FullScreen, RestoreScreen, RepeatOn, RepeatOff } |
An enumeration for a button function. More... | |
enum | BarControlId { Time, Volume } |
An enumeration for a progressbar function. More... | |
enum | TextId { CurrentTime, Duration, Title } |
An enumeration for a text. More... | |
enum | ReadyState { HaveNothing = 0, HaveMetaData = 1, HaveCurrentData = 2, HaveFutureData = 3, HaveEnoughData = 4 } |
An enumeration for the player state. More... | |
Public Member Functions | |
WMediaPlayer (MediaType mediaType, WContainerWidget *parent=0) | |
Creates a new media player. | |
~WMediaPlayer () | |
Destructor. | |
void | setVideoSize (int width, int height) |
Sets the video size. | |
int | videoWidth () const |
Returns the video width. | |
int | videoHeight () const |
Returns the video height. | |
void | setControlsWidget (WWidget *controls) |
Sets the user-interface controls widget. | |
WWidget * | controlsWidget () const |
Returns the user-interface controls widget. | |
void | setTitle (const WString &title) |
Sets the media title. | |
void | addSource (Encoding encoding, const WLink &link) |
Adds a source. | |
WLink | getSource (Encoding encoding) const |
Returns a source. | |
void | clearSources () |
Clears all sources. | |
void | setButton (ButtonControlId id, WInteractWidget *btn) |
Binds a control button. | |
WInteractWidget * | button (ButtonControlId id) const |
Returns a control button. | |
void | setProgressBar (BarControlId id, WProgressBar *progressBar) |
Binds a control progress bar. | |
WProgressBar * | progressBar (BarControlId id) const |
Returns a control progress bar. | |
void | setText (TextId id, WText *text) |
Sets a text place-holder widget. | |
WText * | text (TextId id) const |
Returns a text place-holder widget. | |
void | pause () |
Pauses the player. | |
void | play () |
Start or resume playing. | |
void | stop () |
Stops the player. | |
void | seek (double time) |
Seeks to a time. | |
void | setPlaybackRate (double rate) |
Sets the playback rate. | |
void | setVolume (double volume) |
Sets the volume. | |
double | volume () const |
Returns the volume. | |
void | mute (bool mute) |
Mutes or unmutes the playback volume. | |
bool | playing () const |
Returns whether the media is currently playing. | |
ReadyState | readyState () const |
Returns the current player state. | |
double | duration () const |
Returns the duration. | |
double | currentTime () const |
Returns the current playback time. | |
double | playbackRate () const |
Returns the current playback rate. | |
JSignal & | timeUpdated () |
Event that indicates a time update. | |
JSignal & | playbackStarted () |
Event that indicates that playback started. | |
JSignal & | playbackPaused () |
Event that indicates that playback paused. | |
JSignal & | ended () |
Event that indicates that the video or audio has ended. | |
JSignal & | volumeChanged () |
Event that indicates that the volume has changed. |
A media player.
This widget implements a media player, suitable to play video or audio, and with a customizable user-interface.
To support cross-browser playing of video or audio content, you may need to provide the contents appropriately encoded. For audio, at least an MP3 or MP4 audio (M4A) encoding should be supplied, while for video the M4V encoding should be provided. Additional encodings are beneficial since they increase the chance that native HTML <video>
or <audio>
elements can be used (which may be hardware accelerated), instead of the flash player. See HTML5 browser media support.
You need to specify the encoding types you are going to use when instantiating the media player, since based on the chosen encodings, a particular suitable implementation will be used. Thus, you need to call addSource() immediately, but you may pass empty URLs if you do not yet want to load media.
The player provides a user-interface to control the playback which may be freely customized, and which is independent of the underlying media technology (HTML video or Flash player). The controls user-interface may be implemented as a Wt widget, where the controls (buttons, progress bars, and text widgets) are bound directly to the video player component (client-side).
This widget relies on a third-party JavaScript component jPlayer, which is distributed together with Wt.
The default user-interface can be themed using jPlayer themes. The theme is global (it applies to all media player instances), and is configured by loading a CSS stylesheet.
The following code creates a video using the default controls:
useStyleSheet(WApplication::resourcesUrl() + "jPlayer/skin/jplayer.blue.monday.css"); WMediaPlayer *player = new WMediaPlayer(WMediaPlayer::Video); player->addSource(WMediaPlayer::M4V, "video.m4v"); player->addSource(WMediaPlayer::OGV, "video.ogv"); player->addSource(WMediaPlayer::PosterImage, "poster.png");
Alternatively, a custom widget may be set which implements the controls, using setControlsWidget(). In this case, you should add to this widget the buttons, text place holders, and progress bars and bind them to the media player using the setButton(), setText() and setProgressBar() methods. The controls widget is integrated in the media player, and this has as unique benefit (for a video player) that they may also be shown when the video player is maximized.
Finally, you may want to control the media player only through widgets external to the media player. This may be configured by setting 0
as controlsWidget. In this case however, full screen mode should not be used since there is no way to restore the original size.
An enumeration for a progressbar function.
An enumeration for a button function.
An enumeration for a media encoding.
An enumeration for the player state.
An enumeration for a text.
CurrentTime |
Displays the current time. |
Duration |
Displays the total duration. |
Title |
Displays the title set in setTitle() |
Wt::WMediaPlayer::WMediaPlayer | ( | MediaType | mediaType, |
WContainerWidget * | parent = 0 |
||
) |
Creates a new media player.
The player is instantiated with default controls.
Adds a source.
Adds a media source. The source may be specified as a URL or as a dynamic resource.
You may pass a null link
if you want to indicate the media types you will use (later) without already loading data.
WInteractWidget * Wt::WMediaPlayer::button | ( | ButtonControlId | id | ) | const |
Returns a control button.
void Wt::WMediaPlayer::clearSources | ( | ) |
Clears all sources.
WWidget * Wt::WMediaPlayer::controlsWidget | ( | ) | const |
Returns the user-interface controls widget.
double Wt::WMediaPlayer::currentTime | ( | ) | const |
Returns the current playback time.
Returns the current playback time, expressed in seconds.
double Wt::WMediaPlayer::duration | ( | ) | const |
Returns the duration.
The duration may be reported as 0 if the player has not yet loaded the media to determine the duration. Otherwise the duration is the duration of the loaded media, expressed in seconds.
Returns a source.
Returns the media source for the given encoding
, which must have previously been added using addSource().
void Wt::WMediaPlayer::mute | ( | bool | mute | ) |
Mutes or unmutes the playback volume.
void Wt::WMediaPlayer::pause | ( | ) |
Pauses the player.
void Wt::WMediaPlayer::play | ( | ) |
JSignal & Wt::WMediaPlayer::playbackPaused | ( | ) |
Event that indicates that playback paused.
The event is fired when playback has been paused.
double Wt::WMediaPlayer::playbackRate | ( | ) | const |
Returns the current playback rate.
JSignal & Wt::WMediaPlayer::playbackStarted | ( | ) |
Event that indicates that playback started.
The event is fired when playback has started (or is being continued).
bool Wt::WMediaPlayer::playing | ( | ) | const |
Returns whether the media is currently playing.
WProgressBar * Wt::WMediaPlayer::progressBar | ( | BarControlId | id | ) | const |
Returns a control progress bar.
ReadyState Wt::WMediaPlayer::readyState | ( | ) | const |
Returns the current player state.
The state reflects in how far the media player has loaded the media, and has determined its characteristics.
void Wt::WMediaPlayer::seek | ( | double | time | ) |
Seeks to a time.
If possible, the player sets the current time to the indicated time
(expressed in seconds).
void Wt::WMediaPlayer::setButton | ( | ButtonControlId | id, |
WInteractWidget * | btn | ||
) |
Binds a control button.
A control button is typically implemented as a WAnchor or a WPushButton (although any WInteractWidget can work).
You should use this method in conjunction with setControlsWidget() to bind buttons in a custom control interface to media player functions.
The default control widget implements all buttons using a WAnchor.
void Wt::WMediaPlayer::setControlsWidget | ( | WWidget * | controls | ) |
Sets the user-interface controls widget.
This sets a widget that contains the controls (buttons, text widgets, etc...) to allow the user to control the player.
Widgets that implement the buttons, bars, and text holders should be bound to the player using setButton(), setText() and setProgressBar() calls.
Setting a 0
widget will result in a player without controls. For an audio player this has the effect of being entirely invisible.
The default controls widget is a widget that can be styled using a jPlayer CSS theme.
void Wt::WMediaPlayer::setPlaybackRate | ( | double | rate | ) |
Sets the playback rate.
This modifies the playback rate, expressed as a ratio of the normal (natural) playback rate.
The default value is 1.0
void Wt::WMediaPlayer::setProgressBar | ( | BarControlId | id, |
WProgressBar * | progressBar | ||
) |
Binds a control progress bar.
The progress bar for the WMediaPlayer::Time indication should be contained in a WContainerWidget which bounds the width of the progress bar, rather than setting a width on the progress bar. This is because the progress bar may, in some cases, also be used to indicate which part of the media can be seeked, and for this its width is being manipulated.
You should use this method in conjunction with setControlsWidget() to bind progress bars in a custom control interface to media player functions.
Sets a text place-holder widget.
This binds the widget that displays text such as current time and total duration of the loaded media.
You should use this method in conjunction with setControlsWidget() to bind progress bars in a custom control interface to media player functions.
void Wt::WMediaPlayer::setTitle | ( | const WString & | title | ) |
Sets the media title.
void Wt::WMediaPlayer::setVideoSize | ( | int | width, |
int | height | ||
) |
Sets the video size.
This sets the size for the video. The actual size of the media player may be slightly larger, if the controlWidget take additional space (i.e. is not overlayed on top of the video).
CSS Themes for the default jPlayer controls support two formats (480 x 270 and 640 x 360).
The default video size is 480 x 270.
void Wt::WMediaPlayer::setVolume | ( | double | volume | ) |
Sets the volume.
This modifies the volume, which must be a number between 0 and 1.0.
The default value is 0.8
void Wt::WMediaPlayer::stop | ( | ) |
Stops the player.
Returns a text place-holder widget.
JSignal & Wt::WMediaPlayer::timeUpdated | ( | ) |
Event that indicates a time update.
The event indicates that the currentTime() has changed.
int Wt::WMediaPlayer::videoHeight | ( | ) | const |
Returns the video height.
int Wt::WMediaPlayer::videoWidth | ( | ) | const |
Returns the video width.
double Wt::WMediaPlayer::volume | ( | ) | const |
Returns the volume.