Class MediaBase
- java.lang.Object
-
- com.google.gwt.user.client.ui.UIObject
-
- com.google.gwt.user.client.ui.Widget
-
- com.google.gwt.user.client.ui.FocusWidget
-
- com.google.gwt.media.client.MediaBase
-
- All Implemented Interfaces:
HasAllDragAndDropHandlers,HasAllFocusHandlers,HasAllGestureHandlers,HasAllKeyHandlers,HasAllMediaHandlers,HasAllMouseHandlers,HasAllTouchHandlers,HasBlurHandlers,HasCanPlayThroughHandlers,HasClickHandlers,HasDoubleClickHandlers,HasDragEndHandlers,HasDragEnterHandlers,HasDragHandlers,HasDragLeaveHandlers,HasDragOverHandlers,HasDragStartHandlers,HasDropHandlers,HasEndedHandlers,HasFocusHandlers,HasGestureChangeHandlers,HasGestureEndHandlers,HasGestureStartHandlers,HasKeyDownHandlers,HasKeyPressHandlers,HasKeyUpHandlers,HasLoadedMetadataHandlers,HasMouseDownHandlers,HasMouseMoveHandlers,HasMouseOutHandlers,HasMouseOverHandlers,HasMouseUpHandlers,HasMouseWheelHandlers,HasProgressHandlers,HasTouchCancelHandlers,HasTouchEndHandlers,HasTouchMoveHandlers,HasTouchStartHandlers,HasAttachHandlers,HasHandlers,EventListener,Focusable,HasEnabled,HasFocus,HasVisibility,IsWidget,SourcesClickEvents,SourcesFocusEvents,SourcesKeyboardEvents,SourcesMouseEvents
public abstract class MediaBase extends FocusWidget implements HasAllMediaHandlers
A widget representing a media element.
Experimental API: This API is still under development and is subject to change.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
-
-
Field Summary
-
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMediaBase(MediaElement element)Protected constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HandlerRegistrationaddCanPlayThroughHandler(CanPlayThroughHandler handler)Adds aCanPlayThroughEventhandler.HandlerRegistrationaddEndedHandler(EndedHandler handler)Adds aEndedEventhandler.HandlerRegistrationaddLoadedMetadataHandler(LoadedMetadataHandler handler)Adds aLoadedMetadataEventhandler.HandlerRegistrationaddProgressHandler(ProgressHandler handler)Adds aProgressEventhandler.SourceElementaddSource(java.lang.String url)Add a source element to this media.SourceElementaddSource(java.lang.String url, java.lang.String type)Add a source element to this media, specifying the type (format) of the media.java.lang.StringcanPlayType(java.lang.String type)Returnstrueif the native player is capable of playing content of the given MIME type.TimeRangesgetBuffered()Returns aTimeRangesobject indicating which portions of the source have been buffered locally.java.lang.StringgetCurrentSrc()Returns the URL of the current media source, or the empty String if no source is set.doublegetCurrentTime()Returns the current time within the source media stream.doublegetDefaultPlaybackRate()Returns the default playback rate, where 1.0 corresponds to normal playback.doublegetDuration()Returns the duration of the source media stream, in seconds.MediaErrorgetError()Returns the type of error that has occurred while attempting to load and play the media.doublegetInitialTime()Returns the time to which the media stream was seeked at the time it was loaded, in seconds, or 0.0 if the position is unknown.MediaElementgetMediaElement()Returns the attached Media Element.intgetNetworkState()Returns the network state, one ofMediaElement.NETWORK_EMPTY,MediaElement.NETWORK_IDLE,MediaElement.NETWORK_LOADING, orMediaElement.NETWORK_NO_SOURCE.doublegetPlaybackRate()Returns the playback rate, where 1.0 corresponds to normal playback.TimeRangesgetPlayed()Returns aTimeRangesobject indicating which portions of the source have been played.java.lang.StringgetPreload()Returns the preload setting, one ofMediaElement.PRELOAD_AUTO,MediaElement.PRELOAD_METADATA, orMediaElement.PRELOAD_NONE.intgetReadyState()Returns the current state of the media with respect to rendering the current playback position, as one of the constantsMediaElement.HAVE_CURRENT_DATA,MediaElement.HAVE_ENOUGH_DATA,MediaElement.HAVE_FUTURE_DATA,MediaElement.HAVE_METADATA, orMediaElement.HAVE_NOTHING.TimeRangesgetSeekable()Returns aTimeRangesobject indicating which portions of the source are seekable.java.lang.StringgetSrc()Returns the source URL for the media, ornullif none is set.doublegetStartOffsetTime()Returns the time corresponding to the zero time in the media timeline, measured in seconds since midnight, January 1 1970 UTC, orDouble.NaNif none is specified.doublegetVolume()Returns the current audio volume setting for the media, as a number between 0.0 and 1.0.booleanhasControls()Returnstrueif the media player should display interactive controls (for example, to control play/pause, seek position, and volume),falseotherwise.booleanhasEnded()Returnstrueif playback has reached the end of the media,falseotherwise.booleanisAutoplay()Returnstrueif autoplay is enabled,falseotherwise.booleanisLoop()Returnstrueif the user agent is to seek back to the start of the media once playing has ended,falseotherwise.booleanisMuted()Returnstrueif the volume is to be muted (overriding the normal volume setting),falseotherwise.booleanisPaused()Returnstrueif playback is paused,falseotherwise.booleanisSeeking()Returnstrueif the playback position is in the process of changing discontinuously, e.g., by use of the interactive controls,falseotherwise.voidload()Causes the resource to be loaded.voidpause()Causes playback of the resource to be paused.voidplay()Causes playback of the resource to be started or resumed.voidremoveSource(SourceElement source)Remove the specifiedSourceElementfrom this media.voidsetAutoplay(boolean autoplay)Enables or disables autoplay of the resource.voidsetControls(boolean controls)Enables or disables interactive controls.voidsetCurrentTime(double time)Sets the current playback time within the media stream, in seconds.voidsetDefaultPlaybackRate(double rate)Sets the default playback rate.voidsetLoop(boolean loop)Enables or disables looping.voidsetMuted(boolean muted)Enables or disables muting.voidsetPlaybackRate(double rate)Sets the playback rate.voidsetPreload(java.lang.String preload)Changes the preload setting to one ofMediaElement.PRELOAD_AUTO,MediaElement.PRELOAD_METADATA, orMediaElement.PRELOAD_NONE.voidsetSrc(java.lang.String url)Sets the source URL for the media.voidsetVolume(double volume)Sets the playback volume.-
Methods inherited from class com.google.gwt.user.client.ui.FocusWidget
addBlurHandler, addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addFocusHandler, addFocusListener, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, getFocusImpl, getTabIndex, isEnabled, onAttach, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setEnabled, setFocus, setTabIndex
-
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
-
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
-
-
-
-
Constructor Detail
-
MediaBase
protected MediaBase(MediaElement element)
Protected constructor.
-
-
Method Detail
-
addCanPlayThroughHandler
public HandlerRegistration addCanPlayThroughHandler(CanPlayThroughHandler handler)
Description copied from interface:HasCanPlayThroughHandlersAdds aCanPlayThroughEventhandler.- Specified by:
addCanPlayThroughHandlerin interfaceHasCanPlayThroughHandlers- Parameters:
handler- the media CanPlayThrough handler- Returns:
HandlerRegistrationused to remove this handler
-
addEndedHandler
public HandlerRegistration addEndedHandler(EndedHandler handler)
Description copied from interface:HasEndedHandlersAdds aEndedEventhandler.- Specified by:
addEndedHandlerin interfaceHasEndedHandlers- Parameters:
handler- the media ended handler- Returns:
HandlerRegistrationused to remove this handler
-
addProgressHandler
public HandlerRegistration addProgressHandler(ProgressHandler handler)
Description copied from interface:HasProgressHandlersAdds aProgressEventhandler.- Specified by:
addProgressHandlerin interfaceHasProgressHandlers- Parameters:
handler- the media progress handler- Returns:
HandlerRegistrationused to remove this handler
-
addLoadedMetadataHandler
public HandlerRegistration addLoadedMetadataHandler(LoadedMetadataHandler handler)
Description copied from interface:HasLoadedMetadataHandlersAdds aLoadedMetadataEventhandler.- Specified by:
addLoadedMetadataHandlerin interfaceHasLoadedMetadataHandlers- Parameters:
handler- the media loadedmetadata handler- Returns:
HandlerRegistrationused to remove this handler
-
addSource
public SourceElement addSource(java.lang.String url)
Add a source element to this media. The browser will request source files from the server until it finds one it can play.Only use this method if you do not know the type of the source file, as the browser cannot determine the format from the filename and must download each source until a compatible one is found. Instead, you should specify the type for the media using
addSource(String, String)so the browser can choose a source file without downloading the file.- Parameters:
url- a String URL- See Also:
addSource(String, String)
-
addSource
public SourceElement addSource(java.lang.String url, java.lang.String type)
Add a source element to this media, specifying the type (format) of the media. The browser will choose a supported source file and download it.The type is the format or encoding of the media represented by the source element. For example, the type of an
AudioElementcould be one of "audio/ogg",AudioElement.TYPE_MP3, orAudioElement.TYPE_WAV.You can also add the codec information to the type, giving the browser even more information about whether or not it can play the file (Example: "
audio/ogg; codec=vorbis");- Parameters:
url- a String URLtype- the type (format) of the media- See Also:
getSrc()
-
canPlayType
public java.lang.String canPlayType(java.lang.String type)
Returnstrueif the native player is capable of playing content of the given MIME type.- Parameters:
type- a String representing a MIME type- Returns:
- one of
MediaElement.CAN_PLAY_PROBABLY,MediaElement.CAN_PLAY_MAYBE, orMediaElement.CANNOT_PLAY
-
getBuffered
public TimeRanges getBuffered()
Returns aTimeRangesobject indicating which portions of the source have been buffered locally.- Returns:
- a
TimeRangesinstance, ornull.
-
getCurrentSrc
public java.lang.String getCurrentSrc()
Returns the URL of the current media source, or the empty String if no source is set.- Returns:
- a String URL
-
getCurrentTime
public double getCurrentTime()
Returns the current time within the source media stream.- Returns:
- the time, in seconds, as a double
- See Also:
setCurrentTime(double)
-
getDefaultPlaybackRate
public double getDefaultPlaybackRate()
Returns the default playback rate, where 1.0 corresponds to normal playback. If no rate has been set, 1.0 is returned.- Returns:
- the current default playback rate, or 1.0 if it has not been set
- See Also:
setDefaultPlaybackRate(double)
-
getDuration
public double getDuration()
Returns the duration of the source media stream, in seconds. If the duration is unknown,Double.NaNis returned. For unbounded media streams,Double.POSITIVE_INFINITYis returned.- Returns:
- a positive duration in seconds, NaN, or Infinity
-
getError
public MediaError getError()
Returns the type of error that has occurred while attempting to load and play the media. If no error has occurred,nullis returned.- Returns:
- a
MediaErrorinstance, ornull
-
getInitialTime
public double getInitialTime()
Returns the time to which the media stream was seeked at the time it was loaded, in seconds, or 0.0 if the position is unknown.- Returns:
- the initial time, or 0.0 if unknown
-
getMediaElement
public MediaElement getMediaElement()
Returns the attached Media Element.- Returns:
- the Media Element
-
getNetworkState
public int getNetworkState()
Returns the network state, one ofMediaElement.NETWORK_EMPTY,MediaElement.NETWORK_IDLE,MediaElement.NETWORK_LOADING, orMediaElement.NETWORK_NO_SOURCE.- Returns:
- an integer constant indicating the network state
- See Also:
MediaElement.NETWORK_EMPTY,MediaElement.NETWORK_IDLE,MediaElement.NETWORK_LOADING,MediaElement.NETWORK_NO_SOURCE
-
getPlaybackRate
public double getPlaybackRate()
Returns the playback rate, where 1.0 corresponds to normal playback. If the rate has not been set, 1.0 is returned.- Returns:
- the playback rate, if known, otherwise 1.0
- See Also:
setPlaybackRate(double)
-
getPlayed
public TimeRanges getPlayed()
Returns aTimeRangesobject indicating which portions of the source have been played.- Returns:
- a
TimeRangesinstance, ornull.
-
getPreload
public java.lang.String getPreload()
Returns the preload setting, one ofMediaElement.PRELOAD_AUTO,MediaElement.PRELOAD_METADATA, orMediaElement.PRELOAD_NONE.- Returns:
- the preload setting
- See Also:
setPreload(String),MediaElement.PRELOAD_AUTO,MediaElement.PRELOAD_METADATA,MediaElement.PRELOAD_NONE
-
getReadyState
public int getReadyState()
Returns the current state of the media with respect to rendering the current playback position, as one of the constantsMediaElement.HAVE_CURRENT_DATA,MediaElement.HAVE_ENOUGH_DATA,MediaElement.HAVE_FUTURE_DATA,MediaElement.HAVE_METADATA, orMediaElement.HAVE_NOTHING.- Returns:
- an integer constant indicating the ready state
- See Also:
MediaElement.HAVE_CURRENT_DATA,MediaElement.HAVE_ENOUGH_DATA,MediaElement.HAVE_FUTURE_DATA,MediaElement.HAVE_METADATA,MediaElement.HAVE_NOTHING
-
getSeekable
public TimeRanges getSeekable()
Returns aTimeRangesobject indicating which portions of the source are seekable.- Returns:
- a
TimeRangesinstance, ornull.
-
getSrc
public java.lang.String getSrc()
Returns the source URL for the media, ornullif none is set.- Returns:
- a String URL or
null - See Also:
setSrc(String)
-
getStartOffsetTime
public double getStartOffsetTime()
Returns the time corresponding to the zero time in the media timeline, measured in seconds since midnight, January 1 1970 UTC, orDouble.NaNif none is specified.- Returns:
- the start time
-
getVolume
public double getVolume()
Returns the current audio volume setting for the media, as a number between 0.0 and 1.0.- Returns:
- a number between 0.0 (silent) and 1.0 (loudest)
- See Also:
setVolume(double)
-
hasControls
public boolean hasControls()
Returnstrueif the media player should display interactive controls (for example, to control play/pause, seek position, and volume),falseotherwise.- Returns:
- whether controls should be displayed
- See Also:
setControls(boolean)
-
hasEnded
public boolean hasEnded()
Returnstrueif playback has reached the end of the media,falseotherwise.- Returns:
- whether playback has ended
-
isAutoplay
public boolean isAutoplay()
Returnstrueif autoplay is enabled,falseotherwise. When autoplay is enabled, the user agent will begin playback automatically as soon as it can do so without stopping.- Returns:
- the autoplay setting
- See Also:
setAutoplay(boolean)
-
isLoop
public boolean isLoop()
Returnstrueif the user agent is to seek back to the start of the media once playing has ended,falseotherwise.- Returns:
- the loop setting
- See Also:
setLoop(boolean)
-
isMuted
public boolean isMuted()
Returnstrueif the volume is to be muted (overriding the normal volume setting),falseotherwise.- Returns:
- the muting setting
- See Also:
setMuted(boolean),getVolume(),setVolume(double)
-
isPaused
public boolean isPaused()
Returnstrueif playback is paused,falseotherwise.
-
isSeeking
public boolean isSeeking()
Returnstrueif the playback position is in the process of changing discontinuously, e.g., by use of the interactive controls,falseotherwise.- Returns:
- the seeking status
- See Also:
setControls(boolean),hasControls()
-
load
public void load()
Causes the resource to be loaded.
-
pause
public void pause()
Causes playback of the resource to be paused.
-
play
public void play()
Causes playback of the resource to be started or resumed.
-
removeSource
public void removeSource(SourceElement source)
Remove the specifiedSourceElementfrom this media. If the source element is not a child of this widget, it will not be removed.- Parameters:
source- the source element to remove- See Also:
addSource(String, String)
-
setAutoplay
public void setAutoplay(boolean autoplay)
Enables or disables autoplay of the resource.- Parameters:
autoplay- iftrue, enable autoplay- See Also:
isAutoplay()
-
setControls
public void setControls(boolean controls)
Enables or disables interactive controls.- Parameters:
controls- iftrue, enable controls- See Also:
hasControls()
-
setCurrentTime
public void setCurrentTime(double time)
Sets the current playback time within the media stream, in seconds.- Parameters:
time- a number within the ranges given bygetSeekable()- See Also:
getCurrentTime()
-
setDefaultPlaybackRate
public void setDefaultPlaybackRate(double rate)
Sets the default playback rate.- Parameters:
rate- a double value- See Also:
getDefaultPlaybackRate()
-
setLoop
public final void setLoop(boolean loop)
Enables or disables looping.- Parameters:
loop- iftrue, enable looping- See Also:
isLoop()
-
setMuted
public void setMuted(boolean muted)
Enables or disables muting.- Parameters:
muted- iftrue, enable muting- See Also:
isMuted()
-
setPlaybackRate
public void setPlaybackRate(double rate)
Sets the playback rate.- Parameters:
rate- a double value- See Also:
getPlaybackRate()
-
setPreload
public void setPreload(java.lang.String preload)
Changes the preload setting to one ofMediaElement.PRELOAD_AUTO,MediaElement.PRELOAD_METADATA, orMediaElement.PRELOAD_NONE.- Parameters:
preload- a String constants- See Also:
getPreload(),setPreload(String),MediaElement.PRELOAD_AUTO,MediaElement.PRELOAD_METADATA,MediaElement.PRELOAD_NONE
-
setSrc
public void setSrc(java.lang.String url)
Sets the source URL for the media.Support for different media types varies between browsers. Instead of using this method, you should encode your media in multiple formats and add all of them using
addSource(String, String)so the browser can choose a source that it supports.- Parameters:
url- a String URL- See Also:
getSrc(),addSource(String, String)
-
setVolume
public void setVolume(double volume)
Sets the playback volume.- Parameters:
volume- a value between 0.0 (silent) and 1.0 (loudest)- See Also:
getVolume()
-
-