HtmlMediaElement Class

https://html.spec.whatwg.org/multipage/media.html#htmlmediaelement

public abstract class HtmlMediaElement : HtmlElement
Inheritance
HtmlElement HtmlMediaElement

Properties

NameDescription
AudioTracksGets the audio tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-audiotracks).
AutoplayGets or sets a value indicating whether the element has the autoplay content attribute.
BufferedGets the time ranges of the media resource that are buffered (https://html.spec.whatwg.org/multipage/media.html#dom-media-buffered).
ControlsGets or sets a value indicating whether the element has the controls content attribute.
CrossOriginGets or sets the value of the crossorigin content attribute, limited to the known values (the canonical keyword, or the default value).
CurrentSrcGets 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.
CurrentTimehttps://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.
DefaultMutedGets or sets a value indicating whether the element has the muted content attribute.
DefaultPlaybackRateGets or sets the default playback rate of the media (https://html.spec.whatwg.org/multipage/media.html#dom-media-defaultplaybackrate).
DurationGets 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.
EndedGets 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).
ErrorGets 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).
LoadingGets or sets the value of the loading content attribute, limited to the known values (the canonical keyword, or the default value).
LoopGets or sets a value indicating whether the element has the loop content attribute.
Mutedhttps://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).
NetworkStateGets the current state of the network activity of the element (https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate).
PausedGets a value indicating whether the playback is paused (https://html.spec.whatwg.org/multipage/media.html#dom-media-paused).
PlaybackRateGets 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).
PlayedGets 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).
PreloadGets or sets the value of the preload content attribute, limited to the known values (the canonical keyword, or the default value).
PreservesPitchGets or sets a value indicating whether the pitch of the audio is preserved when the playback rate changes.
ReadyStateGets the readiness of the element to render the current playback position (https://html.spec.whatwg.org/multipage/media.html#dom-media-readystate).
SeekableGets 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).
SeekingGets a value indicating whether the element is seeking (https://html.spec.whatwg.org/multipage/media.html#dom-media-seeking).
SrcGets or sets the src content attribute, as a URL resolved against the base URL of the document.
SrcObjectGets 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.
TextTracksGets the text tracks of the media element (https://html.spec.whatwg.org/multipage/media.html#dom-media-texttracks).
VideoTracksGets the video tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-videotracks).
Volumehttps://html.spec.whatwg.org/multipage/media.html#dom-media-volume

AudioTracks

MediaElements.cs

Gets the audio tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-audiotracks).

public AudioTrackList AudioTracks { get; }

Gets or sets a value indicating whether the element has the autoplay content attribute.

public bool Autoplay { get; set; }

Gets 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; }

Gets or sets a value indicating whether the element has the controls content attribute.

public bool Controls { get; set; }

Gets 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; }

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.

public string CurrentSrc { get; }

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.

public double CurrentTime { get; set; }

DefaultMuted

HtmlElements.g.cs

Gets or sets a value indicating whether the element has the muted content attribute.

public bool DefaultMuted { get; set; }

DefaultPlaybackRate

MediaElements.cs

Gets 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; }

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.

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; }

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).

public MediaError? Error { get; }

Gets 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; }

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).

public bool Muted { get; set; }

NetworkState

MediaElements.cs

Gets 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; }

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.cs

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).

public double PlaybackRate { get; set; }

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; }

Gets 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.cs

Gets or sets a value indicating whether the pitch of the audio is preserved when the playback rate changes.

public bool PreservesPitch { get; set; }

Gets 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; }

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).

public TimeRanges Seekable { get; }

Gets 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; }

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.

public object? SrcObject { get; set; }

Property value

object?

Exceptions

ArgumentException
The value is not a media provider object.

See also

Gets the text tracks of the media element (https://html.spec.whatwg.org/multipage/media.html#dom-media-texttracks).

public TextTrackList TextTracks { get; }

VideoTracks

MediaElements.cs

Gets the video tracks of the media resource (https://html.spec.whatwg.org/multipage/media.html#dom-media-videotracks).

public VideoTrackList VideoTracks { get; }

https://html.spec.whatwg.org/multipage/media.html#dom-media-volume

public double Volume { get; set; }

Methods

NameDescription
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.cs

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.

public TextTrack AddTextTrack(TextTrackKind kind, string label = "", string language = "")

Parameters

kind TextTrackKind
The kind of the track.
label string
The label of the track.
language string
The language of the track (a BCP 47 language tag).

Returns

TextTrack The new track.

See also

CanPlayType(string)

MediaElements.cs

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.

public string CanPlayType(string type)

Seeks to near the given time, in seconds, as fast as possible (https://html.spec.whatwg.org/multipage/media.html#dom-media-fastseek).

public void FastSeek(double time)

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").

public DateTime? GetStartDate()

https://html.spec.whatwg.org/multipage/media.html#dom-media-load

public void Load()

https://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

NameDescription
HaveCurrentDataThe HAVE_CURRENT_DATA constant (2).
HaveEnoughDataThe HAVE_ENOUGH_DATA constant (4).
HaveFutureDataThe HAVE_FUTURE_DATA constant (3).
HaveMetadataThe HAVE_METADATA constant (1).
HaveNothingThe HAVE_NOTHING constant (0).
NetworkEmptyThe NETWORK_EMPTY constant (0).
NetworkIdleThe NETWORK_IDLE constant (1).
NetworkLoadingThe NETWORK_LOADING constant (2).
NetworkNoSourceThe NETWORK_NO_SOURCE constant (3).

HaveCurrentData

The HAVE_CURRENT_DATA constant (2).

public const ushort HaveCurrentData = 2

HaveEnoughData

The HAVE_ENOUGH_DATA constant (4).

public const ushort HaveEnoughData = 4

HaveFutureData

The HAVE_FUTURE_DATA constant (3).

public const ushort HaveFutureData = 3

HaveMetadata

The HAVE_METADATA constant (1).

public const ushort HaveMetadata = 1

HaveNothing

The HAVE_NOTHING constant (0).

public const ushort HaveNothing = 0

NetworkEmpty

The NETWORK_EMPTY constant (0).

public const ushort NetworkEmpty = 0

NetworkIdle

The NETWORK_IDLE constant (1).

public const ushort NetworkIdle = 1

NetworkLoading

The NETWORK_LOADING constant (2).

public const ushort NetworkLoading = 2

NetworkNoSource

The NETWORK_NO_SOURCE constant (3).

public const ushort NetworkNoSource = 3