|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WWidget
eu.webtoolkit.jwt.WCompositeWidget
eu.webtoolkit.jwt.WMediaPlayer
public class WMediaPlayer
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 JWt 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:
...
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
null as controlsWidget. In this case however, full screen mode
should not be used since there is no way to restore the original size.
| Nested Class Summary | |
|---|---|
static class |
WMediaPlayer.BarControlId
An enumeration for a progressbar function. |
static class |
WMediaPlayer.ButtonControlId
An enumeration for a button function. |
static class |
WMediaPlayer.Encoding
An enumeration for a media encoding. |
static class |
WMediaPlayer.MediaType
An enumeration for a media type. |
static class |
WMediaPlayer.ReadyState
An enumeration for the player state. |
static class |
WMediaPlayer.TextId
An enumeration for a text. |
| Constructor Summary | |
|---|---|
WMediaPlayer(WMediaPlayer.MediaType mediaType)
Creates a new media player. |
|
WMediaPlayer(WMediaPlayer.MediaType mediaType,
WContainerWidget parent)
Creates a new media player. |
|
| Method Summary | |
|---|---|
void |
addSource(WMediaPlayer.Encoding encoding,
WLink link)
Adds a source. |
void |
clearSources()
Clears all sources. |
JSignal |
ended()
Event that indicates that the video or audio has ended. |
WInteractWidget |
getButton(WMediaPlayer.ButtonControlId id)
Returns a control button. |
WWidget |
getControlsWidget()
Returns the user-interface controls widget. |
double |
getCurrentTime()
Returns the current playback time. |
double |
getDuration()
Returns the duration. |
double |
getPlaybackRate()
Returns the current playback rate. |
WProgressBar |
getProgressBar(WMediaPlayer.BarControlId id)
Returns a control progress bar. |
WMediaPlayer.ReadyState |
getReadyState()
Returns the current player state. |
WLink |
getSource(WMediaPlayer.Encoding encoding)
Returns a source. |
WText |
getText(WMediaPlayer.TextId id)
Returns a text place-holder widget. |
int |
getVideoHeight()
Returns the video height. |
int |
getVideoWidth()
Returns the video width. |
boolean |
isPlaying()
Returns whether the media is currently playing. |
void |
mute(boolean mute)
Mutes or unmutes the playback volume. |
void |
pause()
Pauses the player. |
void |
play()
Start or resume playing. |
JSignal |
playbackPaused()
Event that indicates that playback paused. |
JSignal |
playbackStarted()
Event that indicates that playback started. |
void |
remove()
Destructor. |
void |
seek(double time)
Seeks to a time. |
void |
setButton(WMediaPlayer.ButtonControlId id,
WInteractWidget w)
Binds a control button. |
void |
setControlsWidget(WWidget controlsWidget)
Sets the user-interface controls widget. |
void |
setPlaybackRate(double rate)
Sets the playback rate. |
void |
setProgressBar(WMediaPlayer.BarControlId id,
WProgressBar w)
Binds a control progress bar. |
void |
setText(WMediaPlayer.TextId id,
WText w)
Sets a text place-holder widget. |
void |
setTitle(java.lang.CharSequence title)
Sets the media title. |
void |
setVideoSize(int width,
int height)
Sets the video size. |
void |
setVolume(double volume)
Sets the volume. |
void |
stop()
Stops the player. |
JSignal |
timeUpdated()
Event that indicates a time update. |
JSignal |
volumeChanged()
Event that indicates that the volume has changed. |
| Methods inherited from class eu.webtoolkit.jwt.WWidget |
|---|
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, isRendered, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
addChild, getObjectName, setObjectName |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WMediaPlayer(WMediaPlayer.MediaType mediaType,
WContainerWidget parent)
The player is instantiated with default controls.
setControlsWidget(WWidget controlsWidget)public WMediaPlayer(WMediaPlayer.MediaType mediaType)
Calls
this(mediaType, (WContainerWidget)null)
| Method Detail |
|---|
public void remove()
remove in class WCompositeWidgetWContainerWidget.removeWidget(WWidget widget)
public void setVideoSize(int width,
int height)
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.
public int getVideoWidth()
setVideoSize(int width, int height)public int getVideoHeight()
setVideoSize(int width, int height)public void setControlsWidget(WWidget controlsWidget)
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 null 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.
public WWidget getControlsWidget()
setControlsWidget(WWidget controlsWidget)public void setTitle(java.lang.CharSequence title)
WMediaPlayer.TextId.Title
public void addSource(WMediaPlayer.Encoding encoding,
WLink link)
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.
public WLink getSource(WMediaPlayer.Encoding encoding)
Returns the media source for the given encoding, which must
have previously been added using
addSource().
public void clearSources()
addSource(WMediaPlayer.Encoding encoding, WLink link)
public void setButton(WMediaPlayer.ButtonControlId id,
WInteractWidget w)
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.
public WInteractWidget getButton(WMediaPlayer.ButtonControlId id)
setButton(WMediaPlayer.ButtonControlId id,
WInteractWidget w)
public void setProgressBar(WMediaPlayer.BarControlId id,
WProgressBar w)
The progress bar for the WMediaPlayer.BarControlId.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.
public WProgressBar getProgressBar(WMediaPlayer.BarControlId id)
setProgressBar(WMediaPlayer.BarControlId id,
WProgressBar w)
public void setText(WMediaPlayer.TextId id,
WText w)
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.
public WText getText(WMediaPlayer.TextId id)
setText(WMediaPlayer.TextId id, WText w)public void pause()
play()public void play()
The player starts or resumes playing at the current time.
seek(double time)public void stop()
play()public void seek(double 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.
public void setPlaybackRate(double 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.
public void setVolume(double volume)
This modifies the volume, which must be a number between 0 and 1.0.
The default value is 0.8
public void mute(boolean mute)
setVolume(double volume)public boolean isPlaying()
play()public WMediaPlayer.ReadyState getReadyState()
The state reflects in how far the media player has loaded the media, and has determined its characteristics.
public double getDuration()
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.
getReadyState(),
getCurrentTime()public double getCurrentTime()
Returns the current playback time, expressed in seconds.
seek(double time)public double getPlaybackRate()
setPlaybackRate(double rate)public JSignal timeUpdated()
The event indicates that the getCurrentTime() has changed.
public JSignal playbackStarted()
The event is fired when playback has started (or is being continued).
public JSignal playbackPaused()
The event is fired when playback has been paused.
public JSignal ended()
public JSignal volumeChanged()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||