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.
This interface also inherits properties from its ancestors HTMLElement, Element, Node, and EventTarget.
HTMLMediaElement.audioTracksAudioTrackList that lists the AudioTrack objects contained in the element.HTMLMediaElement.autoplayBoolean that reflects the autoplay HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption. HTMLMediaElement.buffered Read only
TimeRanges object that indicates the ranges of the media source that the browser has buffered (if any) at the moment the buffered property is accessed.HTMLMediaElement.controllerMediaController object that represents the media controller assigned to the element, or null if none is assigned.HTMLMediaElement.controlsBoolean that reflects the controls HTML attribute, indicating whether user interface items for controlling the resource should be displayed.HTMLMediaElement.controlsList Read only
DOMTokenList that helps the user agent select what controls to show on the media element whenever the user agent shows its own set of controls. The DOMTokenList takes one or more of three possible values: nodownload, nofullscreen, and noremoteplayback.HTMLMediaElement.crossOriginDOMString indicating the CORS setting for this media element.HTMLMediaElement.currentSrc Read only
DOMString with the absolute URL of the chosen media resource.HTMLMediaElement.currentTimedouble indicating the current playback time in seconds. Setting this value seeks the media to the new time.HTMLMediaElement.defaultMutedBoolean that reflects the muted HTML attribute, which indicates whether the media element's audio output should be muted by default.HTMLMediaElement.defaultPlaybackRatedouble indicating the default playback rate for the media.HTMLMediaElement.disableRemotePlaybackBoolean that sets or returns the remote playback state, indicating whether the media element is allowed to have a remote playback UI.HTMLMediaElement.duration Read only
double indicating the length of the media in seconds, or 0 if no media data is available.HTMLMediaElement.ended Read only
Boolean that indicates whether the media element has finished playing.HTMLMediaElement.error Read only
MediaError object for the most recent error, or null if there has not been an error.HTMLMediaElement.loopBoolean that reflects the loop HTML attribute, which indicates whether the media element should start over when it reaches the end.HTMLMediaElement.mediaGroupDOMString that reflects the mediagroup HTML attribute, which indicates the name of the group of elements it belongs to. A group of media elements shares a common MediaController.HTMLMediaElement.mediaKeys Read only
MediaKeys object or null. MediaKeys is a set of keys that an associated HTMLMediaElement can use for decryption of media data during playback.HTMLMediaElement.mozAudioCaptured Read only
Boolean. Related to audio stream capture.HTMLMediaElement.mozFragmentEnd
double that provides access to the fragment end time if the media element has a fragment URI for currentSrc, otherwise it is equal to the media duration.HTMLMediaElement.mozFrameBufferLength
Is a unsigned long that indicates the number of samples that will be returned in the framebuffer of each MozAudioAvailable event. This number is a total for all channels, and by default is set to be the number of channels * 1024 (e.g., 2 channels * 1024 samples = 2048 total).
The mozFrameBufferLength property can be set to a new value for lower latency, larger amounts of data, etc. The size given must be a number between 512 and 16384. Using any other size results in an exception being thrown. The best time to set a new length is after the loadedmetadata event fires, when the audio info is known, but before the audio has started or MozAudioAvailable events have begun firing.
HTMLMediaElement.mozSampleRate Read only
double representing the number of samples per second that will be played. For example, 44100 samples per second is the sample rate used by CD audio.HTMLMediaElement.mutedBoolean that determines whether audio is muted. true if the audio is muted and false otherwise.HTMLMediaElement.networkState Read only
unsigned short (enumeration) indicating the current state of fetching the media over the network.HTMLMediaElement.paused Read only
Boolean that indicates whether the media element is paused.HTMLMediaElement.playbackRatedouble that indicates the rate at which the media is being played back. HTMLMediaElement.played Read only
TimeRanges object that contains the ranges of the media source that the browser has played, if any.HTMLMediaElement.preloadDOMString that reflects the preload HTML attribute, indicating what data should be preloaded, if any. Possible values are: none, metadata, auto.HTMLMediaElement.preservesPitch
Boolean 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. This is implemented with prefixes in Firefox (mozPreservesPitch) and WebKit (webkitPreservesPitch).HTMLMediaElement.readyState Read only
unsigned short (enumeration) indicating the readiness state of the media.HTMLMediaElement.seekable Read only
TimeRanges object that contains the time ranges that the user is able to seek to, if any.HTMLMediaElement.seeking Read only
Boolean that indicates whether the media is in the process of seeking to a new position.HTMLMediaElement.sinkId Read only
DOMString that is the unique ID of the audio device delivering output, or an empty string if it is using the user agent default. This ID should be one of the MediaDeviceInfo.deviceid values returned from MediaDevices.enumerateDevices(), id-multimedia, or id-communications.HTMLMediaElement.srcDOMString that reflects the src HTML attribute, which contains the URL of a media resource to use.HTMLMediaElement.srcObjectMediaStream representing the media to play or that has played in the current HTMLMediaElement, or null if not assigned.HTMLMediaElement.textTracks Read only
TextTrack objects contained in the element.HTMLMediaElement.videoTracks Read only
VideoTrack objects contained in the element. Gecko supports only single track playback, and the parsing of tracks' metadata is only available for media with the Ogg container format.
HTMLMediaElement.volumedouble indicating the audio volume, from 0.0 (silent) to 1.0 (loudest).HTMLMediaElement.onencryptedEventHandler called when the media is encrypted.HTMLMediaElement.onwaitingforkeyEventHandler called when playback is blocked while waiting for an encryption key.These attributes are obsolete and should not be used, even if a browser still supports them.
HTMLMediaElement.initialTime Read only
double that indicates the initial playback position in seconds.HTMLMediaElement.mozChannels Read only
double representing the number of channels in the audio resource (e.g., 2 for stereo).HTMLMediaElement.onmozinterruptbegin
EventHandler called when the media element is interrupted because of the Audio Channel manager. This was Firefox-specific, having been implemented for Firefox OS, and was removed in Firefox 55.HTMLMediaElement.onmozinterruptend
EventHandler called when the interruption is concluded. This was Firefox-specific, having been implemented for Firefox OS, and was removed in Firefox 55.This interface also inherits methods from its ancestors HTMLElement, Element, Node, and EventTarget.
HTMLMediaElement.addTextTrack()HTMLMediaElement.captureStream()
MediaStream, captures a stream of the media content.HTMLMediaElement.canPlayType()HTMLMediaElement.fastSeek()HTMLMediaElement.load()src attribute or the <source> element.HTMLMediaElement.mozCaptureStream()
HTMLMediaElement.mozCaptureStreamUntilEnded()
HTMLMediaElement.mozGetMetadata()
Object, which contains properties that represent metadata from the playing media resource as {key: value} pairs. A separate copy of the data is returned each time the method is called. This method must be called after the loadedmetadata event fires.HTMLMediaElement.pause()HTMLMediaElement.play()HTMLMediaElement.seekToNextFrame()
HTMLMediaElement.setMediaKeys()
Promise. Sets the MediaKeys keys to use when decrypting media during playback.HTMLMediaElement.setSinkId()
Promise. This only works when the application is authorized to use the specified device.These methods are obsolete and should not be used, even if a browser still supports them.
HTMLMediaElement.mozLoadFrom()
load() except that instead of running the normal resource selection algorithm, the source is simply set to the other element's currentSrc. This is optimized so this element gets access to all of the other element's cached and buffered data; in fact, the two elements share downloaded data, so data downloaded by either element is available to both.| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'HTMLMediaElement' in that specification. | Living Standard | No change from HTML5 |
| HTML5 The definition of 'HTMLMediaElement' in that specification. | Recommendation | Initial definition. |
| Encrypted Media Extensions The definition of 'Encrypted Media Extensions' in that specification. | Recommendation | Adds MediaKeys, MediaEncryptedEvent, setMediaKeys, onencrypted, and onwaitingforkey. |
| Media Capture and Streams The definition of 'HTMLMediaElement' in that specification. | Candidate Recommendation | Adds sinkId and setSinkId(), and captureStream(). |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Yes | 3.5 | 9 | Yes | Yes |
addTextTrack |
? | ? | ? | ? | ? | ? |
audioTracks |
? | No | 33
|
? | ? | ? |
autoplay |
Yes | Yes | 3.5 | 9 | Yes | Yes |
buffered |
Yes | Yes | 4 | 9 | Yes | Yes |
canPlayType |
Yes | Yes | 3.5 | 9 | Yes | Yes |
captureStream |
53 | No | 15
|
No | ? | No |
controller |
? | No | No
|
? | ? | ? |
controls |
Yes | Yes | 3.5 | 9 | Yes | Yes |
controlsList |
58 | ? | ? | ? | 45 | ? |
crossOrigin |
Yes | Yes | 22
|
9 | Yes | Yes |
currentSrc |
Yes | Yes | 3.5 | 9 | Yes | Yes |
currentTime |
Yes | Yes | 3.5 | 9 | Yes | Yes |
defaultMuted |
Yes | Yes | 11 | ? | Yes | Yes |
defaultPlaybackRate |
Yes | Yes | 20 | 9 | ? | ? |
disableRemotePlayback |
49 | Yes | 20 | 9 | Yes | Yes |
duration |
Yes | Yes | 3.5 | 9 | Yes | Yes |
ended |
Yes | Yes | 3.5 | 9 | Yes | Yes |
error |
Yes | Yes | 3.5 | 9 | Yes | Yes |
fastSeek |
? | No | 31 | ? | ? | ? |
initialTime
|
? | No | 9 — 23 | ? | ? | ? |
load |
1 | 12 | 3.6 | ? | Yes | Yes |
loop |
Yes | Yes | 11 | 9 | ? | ? |
mediaGroup |
? | No | No
|
? | ? | ? |
mediaKeys |
? | ? | ? | ? | ? | ? |
mozAudioCaptured
|
? | ? | ? | ? | ? | ? |
mozCaptureStreamUntilEnded
|
? | ? | ? | ? | ? | ? |
mozChannels
|
No | No | 4 | No | No | No |
mozFragmentEnd
|
? | ? | ? | ? | ? | ? |
mozFrameBufferLength
|
No | No | 4 | No | No | No |
mozGetMetadata |
No | No | 17 | No | No | No |
mozLoadFrom
|
No | No | 3.6 — 24 | No | No | No |
mozSampleRate
|
No | No | 4 | No | No | No |
muted |
Yes | Yes | 3.5 | 9 | Yes | Yes |
networkState |
Yes | Yes | 3.5
|
9 | Yes | Yes |
onerror |
Yes | Yes | 3.5 | 9 | Yes | Yes |
onencrypted |
? | ? | ? | ? | ? | ? |
onmozinterruptbegin
|
? | ? | ? — 55 | ? | ? | ? |
onmozinterruptend |
? | ? | ? — 55 | ? | ? | ? |
onwaitingforkey |
55 | No | ? | ? | 42 | ? |
pause |
Yes | Yes | 3.5 | 9 | Yes | Yes |
paused |
Yes | Yes | 3.5 | 9 | Yes | Yes |
play |
Yes | Yes | 3.5 | 9 | Yes | Yes |
playbackRate |
Yes | Yes | 20 | 9 | ? | ? |
played |
Yes | Yes | 15 | 9 | ? | ? |
preload |
Yes | Yes | 4 | 9 | ? | ? |
preservesPitch
|
Yes
|
No | 20
|
No | No | No |
readyState |
Yes | Yes | 3.5 | 9 | Yes | Yes |
seekToNextFrame
|
? | No | 49
|
? | ? | ? |
seekable |
Yes | Yes | 8 | 9 | ? | ? |
seeking |
Yes | Yes | 3.5 | 9 | Yes | Yes |
setMediaKeys |
? | ? | ? | ? | ? | ? |
setSinkId |
49 | 17 | ? | ? | ? | ? |
sinkId
|
49 | 17 | ? | ? | ? | ? |
src |
Yes | Yes | 3.5 | 9 | Yes | Yes |
srcObject |
52
|
Partial
|
Partial
|
? | 39
|
? |
textTracks |
? | No | ? | ? | ? | ? |
videoTracks |
? | No | 33
|
? | ? | ? |
volume |
Yes | Yes | 3.5 | 9 | Yes | Yes |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | Yes | Yes | Yes | ? |
addTextTrack |
? | ? | ? | ? | ? | ? | ? |
audioTracks |
? | ? | Yes | 33
|
? | ? | ? |
autoplay |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
buffered |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
canPlayType |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
captureStream |
53 | 53 | No | 15
|
? | No | ? |
controller |
? | ? | No | No
|
? | ? | ? |
controls |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
controlsList |
58 | 58 | ? | ? | 42 | ? | ? |
crossOrigin |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
currentSrc |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
currentTime |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
defaultMuted |
Yes | Yes | Yes | 14 | Yes | Yes | ? |
defaultPlaybackRate |
Yes | Yes | Yes | 20 | ? | ? | ? |
disableRemotePlayback |
49 | 49 | Yes | 15 | Yes | Yes | ? |
duration |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
ended |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
error |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
fastSeek |
? | ? | No | 31 | ? | ? | ? |
initialTime
|
? | ? | No | 9 — 23 | ? | ? | ? |
load |
1 | 18 | 12 | 4 | ? | Yes | ? |
loop |
Yes | Yes | Yes | Yes | ? | ? | ? |
mediaGroup |
? | ? | No | No
|
? | ? | ? |
mediaKeys |
? | ? | ? | ? | ? | ? | ? |
mozAudioCaptured
|
? | ? | ? | ? | ? | ? | ? |
mozCaptureStreamUntilEnded
|
? | ? | ? | ? | ? | ? | ? |
mozChannels
|
No | No | No | 4 | No | No | ? |
mozFragmentEnd
|
? | ? | ? | ? | ? | ? | ? |
mozFrameBufferLength
|
No | No | No | 4 | No | No | ? |
mozGetMetadata |
No | No | No | 17 | No | No | ? |
mozLoadFrom
|
No | No | No | 4 — 24 | No | No | ? |
mozSampleRate
|
No | No | No | 4 | No | No | ? |
muted |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
networkState |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
onerror |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
onencrypted |
? | ? | ? | ? | ? | ? | ? |
onmozinterruptbegin
|
? | ? | ? | ? — 55 | ? | ? | ? |
onmozinterruptend |
? | ? | ? | ? — 55 | ? | ? | ? |
onwaitingforkey |
55 | 55 | No | ? | 42 | ? | ? |
pause |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
paused |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
play |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
playbackRate |
Yes | Yes | Yes | 20 | ? | ? | ? |
played |
Yes | Yes | Yes | 15 | ? | ? | ? |
preload |
Yes | Yes | Yes | 4 | ? | ? | ? |
preservesPitch
|
Yes | Yes | Yes | Yes | No | No | ? |
readyState |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
seekToNextFrame
|
? | ? | No | 49
|
? | ? | ? |
seekable |
Yes | Yes | Yes | 8 | ? | ? | ? |
seeking |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
setMediaKeys |
? | ? | ? | ? | ? | ? | ? |
setSinkId |
49 | 49 | 17 | ? | ? | ? | ? |
sinkId
|
49 | 49 | 17 | ? | ? | ? | ? |
src |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
srcObject |
52
|
52
|
Partial
|
Partial
|
39
|
? | ? |
textTracks |
? | ? | No | ? | ? | ? | ? |
videoTracks |
? | ? | Yes | 33
|
? | ? | ? |
volume |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
<video> and <audio> HTML elements.HTMLVideoElement and HTMLAudioElement interfaces, derived from HTMLMediaElement.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement