HTMLMediaElement
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The HTMLMediaElement interface adds to HTMLElement the properties and methods needed to support basic media-related capabilities that are common to audio and video.
The HTMLVideoElement and HTMLAudioElement elements both inherit this interface.
Instance properties
This interface also inherits properties from its ancestors HTMLElement, Element, Node, and EventTarget.
HTMLMediaElement.audioTracksRead only-
An
AudioTrackListthat lists theAudioTrackobjects contained in the element. HTMLMediaElement.autoplay-
A boolean value that reflects the
autoplayHTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.Note: Automatically playing audio when the user doesn't expect or desire it is a poor user experience and should be avoided in most cases, though there are exceptions. See the Autoplay guide for media and Web Audio APIs for more information. Keep in mind that browsers may ignore autoplay requests, so you should ensure that your code isn't dependent on autoplay working.
HTMLMediaElement.bufferedRead only-
Returns a
TimeRangesobject that indicates the ranges of the media source that the browser has buffered (if any) at the moment thebufferedproperty is accessed. HTMLMediaElement.controls-
A boolean that reflects the
controlsHTML attribute, indicating whether user interface items for controlling the resource should be displayed. HTMLMediaElement.controlsList-
Returns a
DOMTokenListthat helps the user agent select what controls to show on the media element whenever the user agent shows its own set of controls. TheDOMTokenListtakes one or more of three possible values:nodownload,nofullscreen, andnoremoteplayback. HTMLMediaElement.crossOrigin-
A string indicating the CORS setting for this media element.
HTMLMediaElement.currentSrcRead only-
Returns a string with the absolute URL of the chosen media resource.
HTMLMediaElement.currentTime-
A double-precision floating-point value indicating the current playback time in seconds; if the media has not started to play and has not been seeked, this value is the media's initial playback time. Setting this value seeks the media to the new time. The time is specified relative to the media's timeline.
HTMLMediaElement.defaultMuted-
A boolean that reflects the
mutedHTML attribute, which indicates whether the media element's audio output should be muted by default. HTMLMediaElement.defaultPlaybackRate-
A
doubleindicating the default playback rate for the media. HTMLMediaElement.disableRemotePlayback-
A boolean that sets or returns the remote playback state, indicating whether the media element is allowed to have a remote playback UI.
HTMLMediaElement.durationRead only-
A read-only double-precision floating-point value indicating the total duration of the media in seconds. If no media data is available, the returned value is
NaN. If the media is of indefinite length (such as streamed live media, a WebRTC call's media, or similar), the value isInfinity. HTMLMediaElement.endedRead only-
Returns a boolean that indicates whether the media element has finished playing.
HTMLMediaElement.errorRead only-
Returns a
MediaErrorobject for the most recent error, ornullif there has not been an error. HTMLMediaElement.loading-
A string indicating whether the browser should load the media immediately (
eager) or when it is needed (lazy). See<video loading>and<audio loading>HTML attributes for more information. HTMLMediaElement.loop-
A boolean that reflects the
loopHTML attribute, which indicates whether the media element should start over when it reaches the end. HTMLMediaElement.mediaKeysRead only Secure context-
Returns a
MediaKeysobject, that is a set of keys that the element can use for decryption of media data during playback. If no key is available, it can benull. HTMLMediaElement.muted-
A boolean that determines whether audio is muted.
trueif the audio is muted andfalseotherwise. HTMLMediaElement.networkStateRead only-
Returns a
unsigned short(enumeration) indicating the current state of fetching the media over the network. HTMLMediaElement.pausedRead only-
Returns a boolean that indicates whether the media element is paused.
HTMLMediaElement.playbackRate-
A
doublethat indicates the rate at which the media is being played back. HTMLMediaElement.playedRead only-
Returns a
TimeRangesobject that contains the ranges of the media source that the browser has played, if any. HTMLMediaElement.preload-
A string that reflects the
preloadHTML attribute, indicating what data should be preloaded, if any. Possible values are:none,metadata,auto. HTMLMediaElement.preservesPitch-
A boolean value that determines if the pitch of the sound will be preserved. If set to
false, the pitch will adjust to the speed of the audio. HTMLMediaElement.readyStateRead only-
Returns a
unsigned short(enumeration) indicating the readiness state of the media. HTMLMediaElement.remoteRead only-
Return a
RemotePlaybackobject instance associated with the media element. HTMLMediaElement.seekableRead only