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.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 20%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 120" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget" target="_top"><rect x="1" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="56" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">EventTarget</text></a><polyline points="111,25 121,20 121,30 111,25" stroke="#D4DDE4" fill="none"/><line x1="121" y1="25" x2="151" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/Node" target="_top"><rect x="151" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="188.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Node</text></a><polyline points="226,25 236,20 236,30 226,25" stroke="#D4DDE4" fill="none"/><line x1="236" y1="25" x2="266" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/Element" target="_top"><rect x="266" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="303.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Element</text></a><polyline points="341,25 351,20 351,30 341,25" stroke="#D4DDE4" fill="none"/><line x1="351" y1="25" x2="381" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_top"><rect x="381" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="436" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">HTMLElement</text></a><polyline points="491,25 501,20 501,30 491,25" stroke="#D4DDE4" fill="none"/><line x1="501" y1="25" x2="509" y2="25" stroke="#D4DDE4"/><line x1="509" y1="25" x2="509" y2="90" stroke="#D4DDE4"/><line x1="509" y1="90" x2="492" y2="90" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement" target="_top"><rect x="331" y="65" width="160" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="411" y="94" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">HTMLMediaElement</text></a></svg></div>
  a:hover text { fill: #0095DD; pointer-events: all;}
Properties
This interface also inherits properties from its ancestors HTMLElement, Element, Node, and EventTarget.
- HTMLMediaElement.audioTracks
- A AudioTrackListthat lists theAudioTrackobjects contained in the element.
- HTMLMediaElement.autoplay
- A Booleanthat reflects theautoplayHTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.Sites which automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so it should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, this can be useful when creating media elements whose source will be set at a later time, under user control.
- 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.controller
- Is a MediaControllerobject that represents the media controller assigned to the element, ornullif none is assigned.
- HTMLMediaElement.controls
- Is a Booleanthat reflects thecontrolsHTML attribute, indicating whether user interface items for controlling the resource should be displayed.
- HTMLMediaElement.controlsListRead only
- 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
- Is a DOMStringindicating the CORS setting for this media element.
- HTMLMediaElement.currentSrcRead only
- Returns a DOMStringwith the absolute URL of the chosen media resource.
- HTMLMediaElement.currentTime
- Is a doubleindicating the current playback time in seconds. Setting this value seeks the media to the new time.
- HTMLMediaElement.defaultMuted
- Is a Booleanthat reflects themutedHTML attribute, which indicates whether the media element's audio output should be muted by default.
- HTMLMediaElement.defaultPlaybackRate
- Is a doubleindicating the default playback rate for the media.
- HTMLMediaElement.disableRemotePlayback
- Is a Booleanthat sets or returns the remote playback state, indicating whether the media element is allowed to have a remote playback UI.
- HTMLMediaElement.durationRead only
- Returns a doubleindicating the length of the media in seconds, or 0 if no media data is available.
- HTMLMediaElement.endedRead only
- Returns a Booleanthat 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.initialTimeRead only
- Returns a doublethat indicates the initial playback position in seconds.
- HTMLMediaElement.loop
- Is a Booleanthat reflects theloopHTML attribute, which indicates whether the media element should start over when it reaches the end.
- HTMLMediaElement.mediaGroup
- Is a DOMStringthat reflects themediagroupHTML attribute, which indicates the name of the group of elements it belongs to. A group of media elements shares a commonMediaController.
- HTMLMediaElement.mediaKeysRead only
- Returns a MediaKeysobject ornull. MediaKeys is a set of keys that an associated HTMLMediaElement can use for decryption of media data during playback.
- HTMLMediaElement.mozAudioCapturedRead only
- Returns a Boolean. Related to audio stream capture.
- HTMLMediaElement.mozChannelsRead only
- Returns a doublerepresenting the number of channels in the audio resource (e.g.,2for stereo).
- HTMLMediaElement.mozFragmentEnd
- Is a doublethat provides access to the fragment end time if the media element has a fragment URI forcurrentSrc, otherwise it is equal to the media duration.
- HTMLMediaElement.mozFrameBufferLength
- 
 Is a unsigned longthat indicates the number of samples that will be returned in the framebuffer of eachMozAudioAvailableevent. 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 mozFrameBufferLengthproperty 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 orMozAudioAvailableevents have begun firing.
- HTMLMediaElement.mozSampleRateRead only
- Returns a doublerepresenting 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.muted
- Is a Booleanthat 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 Booleanthat indicates whether the media element is paused.
- HTMLMediaElement.playbackRate
- Is 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
- Is a DOMStringthat reflects thepreloadHTML attribute, indicating what data should be preloaded, if any. Possible values are:none,metadata,auto.
- HTMLMediaElement.preservesPitch
- Is a Booleanthat determines if the pitch of the sound will be preserved. If set tofalse, the pitch will adjust to the speed of the audio. This is implemented with prefixes in Firefox (mozPreservesPitch) and WebKit (webkitPreservesPitch).
- HTMLMediaElement.readyStateRead only
- Returns a unsigned short(enumeration) indicating the readiness state of the media.
- HTMLMediaElement.seekableRead only
- Returns a TimeRangesobject that contains the time ranges that the user is able to seek to, if any.
- HTMLMediaElement.seekingRead only
- Returns a Booleanthat indicates whether the media is in the process of seeking to a new position.
- HTMLMediaElement.sinkIdRead only
- Returns a DOMStringthat 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 theMediaDeviceInfo.deviceidvalues returned fromMediaDevices.enumeratedDevices(),id-multimedia, orid-communications.
- HTMLMediaElement.src
- Is a DOMStringthat reflects thesrcHTML attribute, which contains the URL of a media resource to use.
- HTMLMediaElement.srcObject
- Is a MediaStreamrepresenting the media to play or that has played in the currentHTMLMediaElement.
- HTMLMediaElement.textTracksRead only
- Returns the list of TextTrackobjects contained in the element.
- HTMLMediaElement.videoTracksRead only
- Returns the list of VideoTrackobjects contained in the element.Note: Gecko supports only single track playback, and the parsing of tracks' metadata is only available for media with the Ogg container format. 
- HTMLMediaElement.volume
- Is a doubleindicating the audio volume, from 0.0 (silent) to 1.0 (loudest).
Event handlers
- HTMLMediaElement.onmozinterruptbegin
- Sets the EventHandlercalled when the media element is interrupted because of the audiochannel manager.
- HTMLMediaElement.onmozinterruptend
- Sets the EventHandlercalled when the interruption is concluded.
- HTMLMediaElement.onencrypted
- Sets the EventHandlercalled when the media is encrypted.
- HTMLMediaElement.onwaitingforkey
- Sets the EventHandlercalled when playback is blocked while waiting for an encryption key.
Methods
This interface also inherits methods from its ancestors HTMLElement, Element, Node, and EventTarget.
- HTMLMediaElement.addTextTrack()
- Adds a text track (such as a track for subtitles) to a media element.
- HTMLMediaElement.captureStream()
- Returns MediaStream, captures a stream of the media content.
- HTMLMediaElement.canPlayType()
- Determines whether the specified media type can be played back.
- HTMLMediaElement.fastSeek()
- Directly seeks to the given time.
- HTMLMediaElement.load()
- Resets the media element and restarts the media resource. Any pending events are discarded. How much media data is fetched is still affected by the preloadattribute. This method can be useful for releasing resources after anysrcattribute andsourceelement descendants have been removed. Otherwise, it is usually unnecessary to use this method, unless required to rescansourceelement children after dynamic changes.
- HTMLMediaElement.mozCaptureStream()
- [enter description]
- HTMLMediaElement.mozCaptureStreamUntilEnded()
- [enter description]
- HTMLMediaElement.mozGetMetadata()
- Returns 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.mozLoadFrom()
- This method, available only in Mozilla's implementation, loads data from another media element. This works similarly to load()except that instead of running the normal resource selection algorithm, the source is simply set to theotherelement'scurrentSrc. This is optimized so this element gets access to all of theotherelement's cached and buffered data; in fact, the two elements share downloaded data, so data downloaded by either element is available to both.
- HTMLMediaElement.pause()
- Pauses the media playback.
- HTMLMediaElement.play()
- Begins playback of the media.
- HTMLMediaElement.seekToNextFrame()
- Seeks to the next frame in the media. This non-standard, experimental method makes it possible to manually drive reading and rendering of media at a custom speed, or to move through the media frame-by-frame to perform filtering or other operations.
- HTMLMediaElement.setMediaKeys()
- Returns Promise. Sets theMediaKeyskeys to use when decrypting media during playback.
- HTMLMediaElement.setSinkId()
- Sets the ID of the audio device to use for output and returns a Promise. This only works when the application is authorized to use the specified device.
Specifications
| 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. | Working Draft | Adds MediaKeys,MediaEncryptedEvent,setMediaKeys,onencrypted, andonwaitingforkey. | 
| Media Capture and Streams The definition of 'HTMLMediaElement' in that specification. | Editor's Draft | Adds sinkIdandsetSinkId(), andcaptureStream(). | 
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari | 
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | 3.5 (1.9.1) [1] | 9 | (Yes) | ? | 
| bufferedproperty | (Yes) | (Yes) | 4.0 (2.0) | 9 | ? | ? | 
| defaultMutedproperty | (Yes) | (Yes) | 11.0 (11.0) | ? | ? | ? | 
| loopproperty | (Yes) | (Yes) | 11.0 (11.0) | 9 | ? | ? | 
| seekableproperty | (Yes) | (Yes) | 8.0 (8.0) | 9 | ? | ? | 
| defaultPlaybackRateproperty | (Yes) | (Yes) | 20.0 (20.0) | 9 | ? | ? | 
| playbackRateproperty | (Yes) | (Yes) | 20.0 (20.0) | 9 | ? | ? | 
| preservesPitchproperty | (Yes)webkit | No support | 20.0 (20.0)moz | No support | No support | No support | 
| preloadproperty | (Yes) | (Yes) | 4.0 (2.0)[2] | ? | ? | ? | 
| playedproperty | (Yes) | (Yes) | 15.0 (15.0) | ? | ? | ? | 
| crossOriginproperty | (Yes) | (Yes) | 12.0 (12.0)[3] 22.0 (22.0) | ? | ? | ? | 
| mozAudioChannelType property | No support | No support | No support | No support | No support | No support | 
| mozChannels,mozFrameBufferLength,mozSampleRateproperties | No support | No support | 4.0 (2.0) | No support | No support | No support | 
| mozGetMetadata() | No support | No support | 17.0 (17.0) | No support | No support | No support | 
| mozLoadFrom()Obsolete since Gecko 24 | No support | No support | 3.6 (1.9.2) | No support | No support | No support | 
| mozSrcObjectproperty | No support | No support | 18.0 (18.0) | No support | No support | No support | 
| initialTimeproperty | ? | No support | 9.0 (9.0)[4] | ? | ? | ? | 
| fastSeekmethod | ? | No support | 31.0 (31.0) | ? | ? | ? | 
| startDateproperty | ? | No support | No support[8] | ? | ? | ? | 
| mediaGroupandcontrollerproperties | ? | No support | No support[9] | ? | ? | ? | 
| audioTracks, andvideoTracksproperties | ? | No support | 33.0 (33.0) [5] | ? | ? | ? | 
| textTracksproperty | ? | No support | Nightly build [6] | ? | ? | ? | 
| sinkIdproperty andsetSinkId()method | 49.0 | No support | ? | ? | ? | ? | 
| seekToNextFrame()method | ? | No support | 49 (49) [10] | ? | ? | ? | 
| srcObject | 52.0 | (Yes) | ? | ? | 39 | ? | 
| captureStream() | 53.0 | No support | ? | ? | ? | ? | 
| onwaitingforkey | 55.0 | No support | ? | ? | 42 | ? | 
| controlsList | 58.0 | ? | ? | ? | 45 | ? | 
| Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | 
|---|---|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | ? | (Yes) | (Yes) | 
| bufferedproperty | (Yes) | (Yes) | (Yes) | 4.0 (2.0) | (Yes) | ? | ? | ? | 
| defaultMutedproperty | (Yes) | (Yes) | (Yes) | 11.0 (11.0) | (Yes) | ? | ? | ? | 
| loopproperty | (Yes) | (Yes) | (Yes) | 11.0 (11.0) | (Yes) | ? | ? | ? | 
| seekableproperty | (Yes) | (Yes) | (Yes) | 8.0 (8.0) | (Yes) | ? | ? | ? | 
| defaultPlaybackRateproperty | (Yes) | (Yes) | (Yes) | 20.0 (20.0) | (Yes) | ? | ? | ? | 
| playbackRateproperty | (Yes) | (Yes) | (Yes) | 20.0 (20.0) | (Yes) | ? | ? | ? | 
| preservesPitchproperty | (Yes) | (Yes) | No support | 20.0 (20.0)moz | (Yes) | No support | No support | No support | 
| preloadproperty | (Yes) | (Yes) | (Yes) | 4.0 (2.0) | (Yes) | ? | ? | ? | 
| playedproperty | (Yes) | (Yes) | (Yes) | 15.0 (15.0) | (Yes) | ? | ? | ? | 
| crossOriginproperty | (Yes) | (Yes) | (Yes) | 12.0 (12.0)[3] 22.0 (22.0) | (Yes) | ? | ? | ? | 
| mozAudiochannelType | No support | No support | No support | No support | 1.0.1 | No support | No support | No support | 
| mozChannels,mozFrameBufferLength,mozSampleRateproperties | No support | No support | No support | 4.0 (2.0) | (Yes) | No support | No support | No support | 
| mozGetMetadata() | No support | No support | No support | 17.0 (17.0) | (Yes) | No support | No support | No support | 
| mozLoadFrom() | No support | No support | No support | 1.0 (1.9.2)[7] | (Yes) | No support | No support | No support | 
| mozSrcObjectproperty | No support | No support | No support | 18.0 (18.0) | (Yes) | No support | No support | No support | 
| initialTimeproperty | ? | ? | No support | 9.0 (9.0)[4] | (Yes) | ? | ? | ? | 
| fastSeekmethod | ? | ? | No support | 31.0 (31.0) | (Yes) | ? | ? | ? | 
| startDateproperty | ? | ? | No support | No support[8] | (Yes) | ? | ? | ? | 
| mediaGroupandcontrollerproperties | ? | ? | No support | No support[9] | (Yes) | ? | ? | ? | 
| audioTracks, andvideoTracksproperties | ? | ? | (Yes) | 33.0 (33.0)[5] | (Yes) | ? | ? | ? | 
| textTracksproperty | ? | ? | (Yes) | Nightly build[6] | (Yes) | ? | ? | ? | 
| sinkIdproperty andsetSinkId()method | 49.0 | 49.0 | No support | ? | ? | ? | ? | ? | 
| seekToNextFrame()method | ? | ? | No support | 49.0 (49) [10] | ? | ? | ? | ? | 
| srcObject | 52.0 | 52.0 | (Yes) | ? | ? | ? | 39 | ? | 
| captureStream() | 53.0 | 53.0 | No support | ? | ? | ? | ? | ? | 
| onwaitingforkey | 55.0 | 55.0 | No support | ? | ? | ? | 42 | ? | 
| controlsList | 58.0 | 58.0 | ? | ? | ? | ? | 42 | ? | 
[1] The NETWORK_LOADED state was removed to align with the HTML spec in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1).
[2] Previously Gecko implemented this as autobuffer.
[3] Gecko implements this in lowercase, i.e. crossorigin.
[4] The feature was removed in Gecko 23.0 (Firefox 23 / Thunderbird 23 / SeaMonkey 2.20).
[5] The implementation is hidden behind the media.track.enabled preference.
[6] The implementation is hidden behind the media.webvtt.enabled preference, defaulting there to true.
[7] This feature was removed in 24.0 (24).
[8] Gecko doesn't implement this yet. See bug 847376.
[9] Gecko doesn't implement this yet. See bug 847377.
[10] The preference media.seekToNextFrame must be enabled to use the seekToNextFrame() method.
See also
- References
  - <video>and- <audio>HTML elements.
- HTMLVideoElementand- HTMLAudioElementinterfaces, derived from- HTMLMediaElement.
 
- Articles