HtmlMediaElement Class
https://html.spec.whatwg.org/multipage/media.html#htmlmediaelement
public abstract class HtmlMediaElement : HtmlElement- Inheritance
HtmlElementHtmlMediaElement
Properties
| Name | Description |
|---|---|
| AudioTracks | Gets the audio tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-audiotracks). |
| Autoplay | Gets or sets a value indicating whether the element has the autoplay content attribute. |
| Buffered | Gets the time ranges of the media resource that are buffered (https://html.spec.whatwg.org/multipage/media.html#dom-media-buffered). |
| Controls | Gets or sets a value indicating whether the element has the controls content attribute. |
| CrossOrigin | Gets or sets the value of the crossorigin content attribute, limited to the known values (the canonical keyword, or the default value). |
| CurrentSrc | Gets the absolute URL of the current media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-currentsrc), or an empty string when there is none, or when it is a media provider object. |
| CurrentTime | https://html.spec.whatwg.org/multipage/media.html#dom-media-currenttime: the official playback position (or the default playback start position, without media data). Setting it seeks to the new position, limited to the seekable ranges of the media resource. |
| DefaultMuted | Gets or sets a value indicating whether the element has the muted content attribute. |
| DefaultPlaybackRate | Gets or sets the default playback rate of the media (https://html.spec.whatwg.org/multipage/media.html#dom-media-defaultplaybackrate). |
| Duration | Gets the length of the media resource in seconds (https://html.spec.whatwg.org/multipage/media.html#dom-media-duration): NaN when no media data is available, positive infinity for an unbounded stream. |
| Ended | Gets a value indicating whether the playback reached the end of the media resource, playing forwards (https://html.spec.whatwg.org/multipage/media.html#dom-media-ended). |
| Error | Gets the last error of the element since its resource selection algorithm was last invoked, or null (https://html.spec.whatwg.org/multipage/media.html#dom-media-error). |
| Loading | Gets or sets the value of the loading content attribute, limited to the known values (the canonical keyword, or the default value). |
| Loop | Gets or sets a value indicating whether the element has the loop content attribute. |
| Muted | https://html.spec.whatwg.org/multipage/media.html#dom-media-muted: whether the element is muted (see HtmlMediaElement.IsMuted). The setter sets the muted state (initially "default": the muted content attribute). |
| NetworkState | Gets the current state of the network activity of the element (https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate). |
| Paused | Gets a value indicating whether the playback is paused (https://html.spec.whatwg.org/multipage/media.html#dom-media-paused). |
| PlaybackRate | Gets or sets the effective playback rate of the media (https://html.spec.whatwg.org/multipage/media.html#dom-media-playbackrate). The setter throws a NotSupportedError when the player does not support the rate (MediaPlayer.SupportsPlaybackRate). |
| Played | Gets the time ranges of the media resource that were reached through the usual monotonic increase of the current playback position during normal playback (https://html.spec.whatwg.org/multipage/media.html#dom-media-played). |
| Preload | Gets or sets the value of the preload content attribute, limited to the known values (the canonical keyword, or the default value). |
| PreservesPitch | Gets or sets a value indicating whether the pitch of the audio is preserved when the playback rate changes. |
| ReadyState | Gets the readiness of the element to render the current playback position (https://html.spec.whatwg.org/multipage/media.html#dom-media-readystate). |
| Seekable | Gets the time ranges of the media resource that the user agent can seek to (https://html.spec.whatwg.org/multipage/media.html#dom-media-seekable). |
| Seeking | Gets a value indicating whether the element is seeking (https://html.spec.whatwg.org/multipage/media.html#dom-media-seeking). |
| Src | Gets or sets the src content attribute, as a URL resolved against the base URL of the document. |
| SrcObject | Gets or sets the assigned media provider object (https://html.spec.whatwg.org/multipage/media.html#dom-media-srcobject): a Blob that contains the media resource, a MediaSource, or the MediaSourceHandle of a media source constructed in a dedicated worker (MediaStream is not implemented). It takes priority over the src attribute and the source elements. Setting it runs the media element load algorithm. |
| TextTracks | Gets the text tracks of the media element (https://html.spec.whatwg.org/multipage/media.html#dom-media-texttracks). |
| VideoTracks | Gets the video tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-videotracks). |
| Volume | https://html.spec.whatwg.org/multipage/media.html#dom-media-volume |
AudioTracks
MediaElements.csGets the audio tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-audiotracks).
public AudioTrackList AudioTracks { get; }Property value
See also
Autoplay
HtmlElements.g.csGets or sets a value indicating whether the element has the autoplay content attribute.
public bool Autoplay { get; set; }Buffered
MediaElements.Playback.csGets the time ranges of the media resource that are buffered (https://html.spec.whatwg.org/multipage/media.html#dom-media-buffered).
public TimeRanges Buffered { get; }Property value
See also
Controls
HtmlElements.g.csGets or sets a value indicating whether the element has the controls content attribute.
public bool Controls { get; set; }CrossOrigin
HtmlElements.g.csGets or sets the value of the crossorigin content attribute, limited to the known values (the canonical keyword, or the default value).
public string? CrossOrigin { get; set; }Property value
See also
CurrentSrc
MediaElements.csGets the absolute URL of the current media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-currentsrc), or an empty string when there is none, or when it is a media provider object.
public string CurrentSrc { get; }CurrentTime
MediaElements.Playback.cshttps://html.spec.whatwg.org/multipage/media.html#dom-media-currenttime: the official playback position (or the default playback start position, without media data). Setting it seeks to the new position, limited to the seekable ranges of the media resource.
public double CurrentTime { get; set; }DefaultMuted
HtmlElements.g.csGets or sets a value indicating whether the element has the muted content attribute.
public bool DefaultMuted { get; set; }DefaultPlaybackRate
MediaElements.csGets or sets the default playback rate of the media (https://html.spec.whatwg.org/multipage/media.html#dom-media-defaultplaybackrate).
public double DefaultPlaybackRate { get; set; }Property value
See also
Duration
MediaElements.Playback.csGets the length of the media resource in seconds (https://html.spec.whatwg.org/multipage/media.html#dom-media-duration): NaN when no media data is available, positive infinity for an unbounded stream.
public double Duration { get; }Gets a value indicating whether the playback reached the end of the media resource, playing forwards (https://html.spec.whatwg.org/multipage/media.html#dom-media-ended).
public bool Ended { get; }Error
MediaElements.csGets the last error of the element since its resource selection algorithm was last invoked, or null (https://html.spec.whatwg.org/multipage/media.html#dom-media-error).
public MediaError? Error { get; }Loading
HtmlElements.g.csGets or sets the value of the loading content attribute, limited to the known values (the canonical keyword, or the default value).
public string Loading { get; set; }Gets or sets a value indicating whether the element has the loop content attribute.
public bool Loop { get; set; }Muted
MediaElements.cshttps://html.spec.whatwg.org/multipage/media.html#dom-media-muted: whether the element is muted (see HtmlMediaElement.IsMuted). The setter sets the muted state (initially "default": the muted content attribute).
public bool Muted { get; set; }NetworkState
MediaElements.csGets the current state of the network activity of the element (https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate).
public ushort NetworkState { get; }Property value
See also
Gets a value indicating whether the playback is paused (https://html.spec.whatwg.org/multipage/media.html#dom-media-paused).
public bool Paused { get; }PlaybackRate
MediaElements.csGets or sets the effective playback rate of the media (https://html.spec.whatwg.org/multipage/media.html#dom-media-playbackrate). The setter throws a NotSupportedError when the player does not support the rate (MediaPlayer.SupportsPlaybackRate).
public double PlaybackRate { get; set; }Property value
See also
Gets the time ranges of the media resource that were reached through the usual monotonic increase of the current playback position during normal playback (https://html.spec.whatwg.org/multipage/media.html#dom-media-played).
public TimeRanges Played { get; }Preload
HtmlElements.g.csGets or sets the value of the preload content attribute, limited to the known values (the canonical keyword, or the default value).
public string Preload { get; set; }PreservesPitch
MediaElements.csGets or sets a value indicating whether the pitch of the audio is preserved when the playback rate changes.
public bool PreservesPitch { get; set; }Property value
See also
ReadyState
MediaElements.Playback.csGets the readiness of the element to render the current playback position (https://html.spec.whatwg.org/multipage/media.html#dom-media-readystate).
public ushort ReadyState { get; }Seekable
MediaElements.Playback.csGets the time ranges of the media resource that the user agent can seek to (https://html.spec.whatwg.org/multipage/media.html#dom-media-seekable).
public TimeRanges Seekable { get; }Property value
See also
Seeking
MediaElements.Playback.csGets a value indicating whether the element is seeking (https://html.spec.whatwg.org/multipage/media.html#dom-media-seeking).
public bool Seeking { get; }Gets or sets the src content attribute, as a URL resolved against the base URL of the document.
public string Src { get; set; }SrcObject
MediaElements.csGets or sets the assigned media provider object (https://html.spec.whatwg.org/multipage/media.html#dom-media-srcobject): a Blob that contains the media resource, a MediaSource, or the MediaSourceHandle of a media source constructed in a dedicated worker (MediaStream is not implemented). It takes priority over the src attribute and the source elements. Setting it runs the media element load algorithm.
public object? SrcObject { get; set; }TextTracks
MediaElements.TextTracks.csGets the text tracks of the media element (https://html.spec.whatwg.org/multipage/media.html#dom-media-texttracks).
public TextTrackList TextTracks { get; }Property value
See also
VideoTracks
MediaElements.csGets the video tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-videotracks).
public VideoTrackList VideoTracks { get; }Property value
See also
Volume
MediaElements.cshttps://html.spec.whatwg.org/multipage/media.html#dom-media-volume
public double Volume { get; set; }Methods
| Name | Description |
|---|---|
| AddTextTrack(TextTrackKind, string, string) | Creates a text track and adds it to the list of text tracks of the media element (https://html.spec.whatwg.org/multipage/media.html#dom-media-addtexttrack): the track is loaded, its mode is TextTrackMode.Hidden and its list of cues is empty. An addtrack event is fired at the list. |
| CanPlayType(string) | https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype: the answer of the media backend (MediaBackend.CanPlayType) for a valid MIME type other than application/octet-stream, else the empty string. Without a media backend, no media type can be played. |
| FastSeek(double) | Seeks to near the given time, in seconds, as fast as possible (https://html.spec.whatwg.org/multipage/media.html#dom-media-fastseek). |
| GetStartDate() | Returns the date and time of the zero time of the media timeline (https://html.spec.whatwg.org/multipage/media.html#dom-media-getstartdate), or null when the media resource has none (the timeline offset is NaN: the scripts get a Date object whose time value is NaN, an "Invalid Date"). |
| Load() | https://html.spec.whatwg.org/multipage/media.html#dom-media-load |
| Pause() | https://html.spec.whatwg.org/multipage/media.html#dom-media-pause |
| Play() | https://html.spec.whatwg.org/multipage/media.html#dom-media-play: returns a task that completes when the playback starts, or fails with a NotAllowedError (the autoplay policy), a NotSupportedError (the media resource is not suitable, or there is no media backend) or an AbortError (the element was paused or loaded another resource). |
AddTextTrack(TextTrackKind, string, string)
MediaElements.TextTracks.csCreates a text track and adds it to the list of text tracks of the media element (https://html.spec.whatwg.org/multipage/media.html#dom-media-addtexttrack): the track is loaded, its mode is TextTrackMode.Hidden and its list of cues is empty. An addtrack event is fired at the list.
public TextTrack AddTextTrack(TextTrackKind kind, string label = "", string language = "")Parameters
kindTextTrackKind- The kind of the track.
labelstring- The label of the track.
languagestring- The language of the track (a BCP 47 language tag).
Returns
TextTrack The new track.
See also
CanPlayType(string)
MediaElements.cshttps://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype: the answer of the media backend (MediaBackend.CanPlayType) for a valid MIME type other than application/octet-stream, else the empty string. Without a media backend, no media type can be played.
FastSeek(double)
MediaElements.Playback.csSeeks to near the given time, in seconds, as fast as possible (https://html.spec.whatwg.org/multipage/media.html#dom-media-fastseek).
GetStartDate()
MediaElements.Playback.csReturns the date and time of the zero time of the media timeline (https://html.spec.whatwg.org/multipage/media.html#dom-media-getstartdate), or null when the media resource has none (the timeline offset is NaN: the scripts get a Date object whose time value is NaN, an "Invalid Date").
public DateTime? GetStartDate()Load()
MediaElements.Loading.cshttps://html.spec.whatwg.org/multipage/media.html#dom-media-load
public void Load()Pause()
MediaElements.Playback.cshttps://html.spec.whatwg.org/multipage/media.html#dom-media-pause
public void Pause()https://html.spec.whatwg.org/multipage/media.html#dom-media-play: returns a task that completes when the playback starts, or fails with a NotAllowedError (the autoplay policy), a NotSupportedError (the media resource is not suitable, or there is no media backend) or an AbortError (the element was paused or loaded another resource).
public Task Play()Constants
| Name | Description |
|---|---|
| HaveCurrentData | The HAVE_CURRENT_DATA constant (2). |
| HaveEnoughData | The HAVE_ENOUGH_DATA constant (4). |
| HaveFutureData | The HAVE_FUTURE_DATA constant (3). |
| HaveMetadata | The HAVE_METADATA constant (1). |
| HaveNothing | The HAVE_NOTHING constant (0). |
| NetworkEmpty | The NETWORK_EMPTY constant (0). |
| NetworkIdle | The NETWORK_IDLE constant (1). |
| NetworkLoading | The NETWORK_LOADING constant (2). |
| NetworkNoSource | The NETWORK_NO_SOURCE constant (3). |
HaveCurrentData
The HAVE_CURRENT_DATA constant (2).
public const ushort HaveCurrentData = 2HaveEnoughData
The HAVE_ENOUGH_DATA constant (4).
public const ushort HaveEnoughData = 4HaveFutureData
The HAVE_FUTURE_DATA constant (3).
public const ushort HaveFutureData = 3HaveMetadata
The HAVE_METADATA constant (1).
public const ushort HaveMetadata = 1HaveNothing
The HAVE_NOTHING constant (0).
public const ushort HaveNothing = 0NetworkEmpty
The NETWORK_EMPTY constant (0).
public const ushort NetworkEmpty = 0NetworkIdle
The NETWORK_IDLE constant (1).
public const ushort NetworkIdle = 1NetworkLoading
The NETWORK_LOADING constant (2).
public const ushort NetworkLoading = 2NetworkNoSource
The NETWORK_NO_SOURCE constant (3).
public const ushort NetworkNoSource = 3