Class MediaElement

Direct Known Subclasses:
AudioElement, VideoElement

public class MediaElement extends Element
Common superclass for Audio and Video elements. See
invalid @link
{@link <a href="http://www.w3.org/TR/html5/video.html">W3C
HTML5 Video and Audio}
  • Field Details

  • Constructor Details

    • MediaElement

      protected MediaElement()
  • Method Details

    • canPlayType

      public final String canPlayType(String type)
      Returns true if the native player is capable of playing content of the given MIME type.
      Parameters:
      type - a String representing a MIME type
      Returns:
      one of CAN_PLAY_PROBABLY, CAN_PLAY_MAYBE, or CANNOT_PLAY
    • getBuffered

      public final TimeRanges getBuffered()
      Returns a TimeRanges object indicating which portions of the source have been buffered locally.
      Returns:
      a TimeRanges instance, or null.
    • getCurrentSrc

      public final 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 final double getCurrentTime()
      Returns the current time within the source media stream.
      Returns:
      the time, in seconds, as a double
      See Also:
    • getDefaultPlaybackRate

      public final 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:
    • getDuration

      public final double getDuration()
      Returns the duration of the source media stream, in seconds. If the duration is unknown, Double.NaN is returned. For unbounded media streams, Double.POSITIVE_INFINITY is returned.
      Returns:
      a positive duration in seconds, NaN, or Infinity
    • getError

      public final MediaError getError()
      Returns the type of error that has occurred while attempting to load and play the media. If no error has occurred, null is returned.
      Returns:
      a MediaError instance, or null
    • getInitialTime

      public final 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
    • getNetworkState

      public final int getNetworkState()
      Returns the network state, one of NETWORK_EMPTY, NETWORK_IDLE, NETWORK_LOADING, or NETWORK_NO_SOURCE.
      Returns:
      an integer constant indicating the network state
      See Also:
    • getPlaybackRate

      public final 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:
    • getPlayed

      public final TimeRanges getPlayed()
      Returns a TimeRanges object indicating which portions of the source have been played.
      Returns:
      a TimeRanges instance, or null.
    • getPreload

      public final String getPreload()
      Returns the preload setting, one of PRELOAD_AUTO, PRELOAD_METADATA, or PRELOAD_NONE.
      Returns:
      the preload setting
      See Also:
    • getReadyState

      public final int getReadyState()
      Returns the current state of the media with respect to rendering the current playback position, as one of the constants HAVE_CURRENT_DATA, HAVE_ENOUGH_DATA, HAVE_FUTURE_DATA, HAVE_METADATA, or HAVE_NOTHING .
      Returns:
      an integer constant indicating the ready state
      See Also:
    • getSeekable

      public final TimeRanges getSeekable()
      Returns a TimeRanges object indicating which portions of the source are seekable.
      Returns:
      a TimeRanges instance, or null.
    • getSrc

      public final String getSrc()
      Returns the source URL for the media, or null if none is set.
      Returns:
      a String URL or null
      See Also:
    • getStartOffsetTime

      public final double getStartOffsetTime()
      Returns the time corresponding to the zero time in the media timeline, measured in seconds since midnight, January 1 1970 UTC, or Double.NaN if none is specified.
      Returns:
      the start time
    • getVolume

      public final 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:
    • hasControls

      public final boolean hasControls()
      Returns true if the media player should display interactive controls (for example, to control play/pause, seek position, and volume), false otherwise.
      Returns:
      whether controls should be displayed
      See Also:
    • hasEnded

      public final boolean hasEnded()
      Returns true if playback has reached the end of the media, false otherwise.
      Returns:
      whether playback has ended
    • isAutoplay

      public final boolean isAutoplay()
      Returns true if autoplay is enabled, false otherwise. 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:
    • isLoop

      public final boolean isLoop()
      Returns true if the user agent is to seek back to the start of the media once playing has ended, false otherwise.
      Returns:
      the loop setting
      See Also:
    • isMuted

      public final boolean isMuted()
      Returns true if the volume is to be muted (overriding the normal volume setting), false otherwise.
      Returns:
      the muting setting
      See Also:
    • isPaused

      public final boolean isPaused()
      Returns true if playback is paused, false otherwise.
      Returns:
      the paused setting
      See Also:
    • isSeeking

      public final boolean isSeeking()
      Returns true if the playback position is in the process of changing discontinuously, e.g., by use of the interactive controls, false otherwise.
      Returns:
      the seeking status
      See Also:
    • load

      public final void load()
      Causes the resource to be loaded.
    • pause

      public final void pause()
      Causes playback of the resource to be paused.
    • play

      public final void play()
      Causes playback of the resource to be started or resumed.
    • setAutoplay

      public final void setAutoplay(boolean autoplay)
      Enables or disables autoplay of the resource.
      Parameters:
      autoplay - if true, enable autoplay
      See Also:
    • setControls

      public final void setControls(boolean controls)
      Enables or disables interactive controls.
      Parameters:
      controls - if true, enable controls
      See Also:
    • setCurrentTime

      public final void setCurrentTime(double time)
      Sets the current playback time within the media stream, in seconds.
      Parameters:
      time - a number within the ranges given by getSeekable()
      See Also:
    • setDefaultPlaybackRate

      public final void setDefaultPlaybackRate(double rate)
      Sets the default playback rate.
      Parameters:
      rate - a double value
      See Also:
    • setLoop

      public final void setLoop(boolean loop)
      Enables or disables looping.
      Parameters:
      loop - if true, enable looping
      See Also:
    • setMuted

      public final void setMuted(boolean muted)
      Enables or disables muting.
      Parameters:
      muted - if true, enable muting
      See Also:
    • setPlaybackRate

      public final void setPlaybackRate(double rate)
      Sets the playback rate.
      Parameters:
      rate - a double value
      See Also:
    • setPreload

      public final void setPreload(String preload)
      Changes the preload setting to one of PRELOAD_AUTO, PRELOAD_METADATA, or PRELOAD_NONE.
      Parameters:
      preload - a String constants
      See Also:
    • setSrc

      public final void setSrc(String url)
      Sets the source URL for the media.
      Parameters:
      url - a String URL
      See Also:
    • setVolume

      public final void setVolume(double volume)
      Sets the playback volume.
      Parameters:
      volume - a value between 0.0 (silent) and 1.0 (loudest)
      See Also: