Wt: Wt::WMediaPlayer Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions
Wt::WMediaPlayer Class Reference

A media player. More...

`#include <Wt/WMediaPlayer>`

Inheritance diagram for Wt::WMediaPlayer:
[legend]

List of all members.

## 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.
## Protected Member Functions
virtual void | render (WFlags< RenderFlag > flags)
| Renders the widget.

## Detailed Description

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::relativeRsourcesUrl() + "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.

## Member Enumeration Documentation

enum Wt::WMediaPlayer::BarControlId

An enumeration for a progressbar function.

See also:
  setProgressBar(), progressBar()

Enumerator:

  Time | The time bar.
  Volume | The volume bar.

enum Wt::WMediaPlayer::ButtonControlId

An enumeration for a button function.

See also:
  setButton(), button()

Enumerator:

  VideoPlay | Play button which overlays the video (for Video only)
  Play | Play button, is hidden while playing.
  Pause | Pause button, is hidden while paused.
  Stop | Stop button.
  VolumeMute | Volume mute button.
  VolumeUnmute | Volume unmute button.
  VolumeMax | Volume max button.
  FullScreen | Toggle button for full screen, is hidden while full screen (for Video only)
  RestoreScreen | Toggle button to restore the screen, is shown only in full screen (for Video only)
  RepeatOn | Toggle button to enable looping, is hidden while repeating is on
  RepeatOff | Toggle button to disable looping, is hidden while repeat is off

enum Wt::WMediaPlayer::Encoding

An enumeration for a media encoding.

See also:
  addSource()
  http://www.jplayer.org/latest/developer-guide/#jPlayer-media-encoding

Enumerator:

  PosterImage | The poster image (e.g. JPG/PNG) for a video.
  MP3 | Audio: MP3 encoding (essential audio format)
  M4A | Audio: MP4 encoding (essential audio format)
  OGA | Audio: OGG encoding.
  WAV | Audio: WAV (uncompressed) format.
  WEBMA | Audio: WebM encoding.
  FLA | Audio: Flash format.
  M4V | Video: MP4 encoding (essential video format)
  OGV | Video: OGG encoding.
  WEBMV | Video: WebM encoding.
  FLV | Video: Flash format.

enum Wt::WMediaPlayer::MediaType

An enumeration for a media type.

Enumerator:

  Audio | Defines an audio player.
  Video | Defines a video player.

enum Wt::WMediaPlayer::ReadyState

An enumeration for the player state.

See also:
  readyState()

Enumerator:

  HaveNothing | No information available.
  HaveMetaData | Metadata loaded: duration, width, height.
  HaveCurrentData | Data at playback position is available.
  HaveFutureData | Have data to play for a while.
  HaveEnoughData | Enough to reach the end without stalling.

enum Wt::WMediaPlayer::TextId

An enumeration for a text.

See also:
  setText(), text()

Enumerator:

  CurrentTime | Displays the current time.
  Duration | Displays the total duration.
  Title | Displays the title set in setTitle()

## Constructor & Destructor Documentation

Wt::WMediaPlayer::WMediaPlayer | ( | MediaType | mediaType,
|  | WContainerWidget * | parent = `0`
| ) |  |

Creates a new media player.

The player is instantiated with default controls.

See also:
  setControlsWidget()

## Member Function Documentation

void Wt::WMediaPlayer::addSource | ( | Encoding | encoding,
|  | const WLink & | link
| ) |  |

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.

See also:
  setButton()

void Wt::WMediaPlayer::clearSources | ( |  | ) |

Clears all sources.

See also:
  addSource()

WWidget * Wt::WMediaPlayer::controlsWidget | ( |  | ) | const

Returns the user-interface controls widget.

See also:
  setControlsWidget()

double Wt::WMediaPlayer::currentTime | ( |  | ) | const

Returns the current playback time.

Returns the current playback time, expressed in seconds.

See also:
  seek()

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.

See also:
  readyState(), currentTime()

WLink Wt::WMediaPlayer::getSource | ( | Encoding | encoding | ) | const

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.

See also:
  setVolume()

void Wt::WMediaPlayer::pause | ( |  | ) |

Pauses the player.

See also:
  play()

void Wt::WMediaPlayer::play | ( |  | ) |

Start or resume playing.

The player starts or resumes playing at the current time.

See also:
  seek()

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.

See also:
  setPlaybackRate()

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.

See also:
  play()

WProgressBar * Wt::WMediaPlayer::progressBar | ( | BarControlId | id | ) | const

Returns a control progress bar.

See also:
  setProgressBar()

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::render | ( | WFlags< RenderFlag > | flags | ) | `[protected, virtual]`

Renders the widget.

This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

Reimplemented from Wt::WCompositeWidget.

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).

Note:
  It may be the case that this only works after the player has already loaded the media.

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

Note:
  Not all browsers support this function.

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.

void Wt::WMediaPlayer::setText | ( | TextId | id,
|  | WText * | text
| ) |  |

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.

See also:
  WMediaPlayer::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.

See also:
  play()

WText * Wt::WMediaPlayer::text | ( | TextId | id | ) | const

Returns a text place-holder widget.

See also:
  setText()

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.

See also:
  setVideoSize()

int Wt::WMediaPlayer::videoWidth | ( |  | ) | const

Returns the video width.

See also:
  setVideoSize()

double Wt::WMediaPlayer::volume | ( |  | ) | const

Returns the volume.

See also:
  setVolume()

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator