MediaSource Class
A media source (https://w3c.github.io/media-source/#mediasource): a media resource whose data is appended by the scripts to its SourceBuffer objects, attached to a media element by a blob: URL (Url.CreateObjectUrl) or, for a source created in a dedicated worker, by its MediaSource.Handle (HtmlMediaElement.SrcObject).
public class MediaSource : EventTargetRemarks
The media backend of the browsing context parses the appended bytes (MediaBackend.CreateSegmentParser); the library implements the algorithms of the specification on the coded frames it reports. Without a backend, no type is supported.
See also
- Inheritance
EventTargetMediaSource
Constructors
| Name | Description |
|---|---|
| MediaSource() | Creates a media source (https://w3c.github.io/media-source/#dom-mediasource-constructor): it is closed until it is attached to a media element. |
MediaSource()
MediaSource.csCreates a media source (https://w3c.github.io/media-source/#dom-mediasource-constructor): it is closed until it is attached to a media element.
public MediaSource()Properties
| Name | Description |
|---|---|
| ActiveSourceBuffers | Gets the source buffers that provide the selected video track and the enabled audio tracks (https://w3c.github.io/media-source/#dom-mediasource-activesourcebuffers), in the order of MediaSource.SourceBuffers. |
| CanConstructInDedicatedWorker | Gets a value indicating whether a media source can be created in a dedicated worker (https://w3c.github.io/media-source/#dom-mediasource-canconstructindedicatedworker): always true. |
| Duration | Gets or sets the duration of the presentation in seconds (https://w3c.github.io/media-source/#dom-mediasource-duration): NaN while the source is closed. The setter throws a TypeError for a negative value or NaN, and an InvalidStateError when the source is not open, a source buffer is updating, or the value is less than the highest presentation timestamp of the buffered frames. |
| Handle | Gets the handle used to attach the source of a dedicated worker to a media element of its window (https://w3c.github.io/media-source/#dom-mediasource-handle): it is transferred to the window and assigned to srcObject. |
| OnSourceClose | Gets or sets the event handler of the sourceclose event. |
| OnSourceEnded | Gets or sets the event handler of the sourceended event. |
| OnSourceOpen | Gets or sets the event handler of the sourceopen event. |
| ReadyState | Gets the state of the source (https://w3c.github.io/media-source/#dom-mediasource-readystate). |
| SourceBuffers | Gets the source buffers of the source (https://w3c.github.io/media-source/#dom-mediasource-sourcebuffers). |
ActiveSourceBuffers
MediaSource.csGets the source buffers that provide the selected video track and the enabled audio tracks (https://w3c.github.io/media-source/#dom-mediasource-activesourcebuffers), in the order of MediaSource.SourceBuffers.
public SourceBufferList ActiveSourceBuffers { get; }Property value
See also
CanConstructInDedicatedWorker
MediaSource.csGets a value indicating whether a media source can be created in a dedicated worker (https://w3c.github.io/media-source/#dom-mediasource-canconstructindedicatedworker): always true.
public static bool CanConstructInDedicatedWorker { get; }Property value
See also
Duration
MediaSource.csGets or sets the duration of the presentation in seconds (https://w3c.github.io/media-source/#dom-mediasource-duration): NaN while the source is closed. The setter throws a TypeError for a negative value or NaN, and an InvalidStateError when the source is not open, a source buffer is updating, or the value is less than the highest presentation timestamp of the buffered frames.
public double Duration { get; set; }Handle
MediaSource.csGets the handle used to attach the source of a dedicated worker to a media element of its window (https://w3c.github.io/media-source/#dom-mediasource-handle): it is transferred to the window and assigned to srcObject.
public MediaSourceHandle Handle { get; }OnSourceClose
MediaSource.csGets or sets the event handler of the sourceclose event.
Property value
See also
OnSourceEnded
MediaSource.csGets or sets the event handler of the sourceended event.
Property value
See also
OnSourceOpen
MediaSource.csGets or sets the event handler of the sourceopen event.
Property value
See also
ReadyState
MediaSource.csGets the state of the source (https://w3c.github.io/media-source/#dom-mediasource-readystate).
public MediaSourceReadyState ReadyState { get; }Property value
See also
SourceBuffers
MediaSource.csGets the source buffers of the source (https://w3c.github.io/media-source/#dom-mediasource-sourcebuffers).
public SourceBufferList SourceBuffers { get; }Property value
See also
Methods
| Name | Description |
|---|---|
| AddSourceBuffer(string) | Creates a source buffer for a MIME type (https://w3c.github.io/media-source/#dom-mediasource-addsourcebuffer). Throws a TypeError for an empty type, a NotSupportedError when the media backend does not support the type, and an InvalidStateError when the source is not open. |
| ClearLiveSeekableRange() | Clears the live seekable range (https://w3c.github.io/media-source/#dom-mediasource-clearliveseekablerange). |
| EndOfStream(EndOfStreamError?) | Signals the end of the stream (https://w3c.github.io/media-source/#dom-mediasource-endofstream): without error, the duration becomes the end of the buffered data and the media element can play to the end; with an error, the media element fails. Throws an InvalidStateError when the source is not open or a source buffer is updating. |
| IsTypeSupported(string) | Returns whether a source buffer can be created for a MIME type (https://w3c.github.io/media-source/#dom-mediasource-istypesupported): the media backend of the current global object is confident that it can play the type (MediaBackend.CanPlayType is MediaTypeSupport.Probably: as in the browsers, a type that allows the codecs parameter and does not have it is not supported, though addSourceBuffer() accepts it) and creates a byte stream parser for it (MediaBackend.CreateSegmentParser). |
| RemoveSourceBuffer(SourceBuffer) | Removes a source buffer (https://w3c.github.io/media-source/#dom-mediasource-removesourcebuffer): its pending append is aborted, and its tracks are removed from the media element. Throws a NotFoundError when the buffer is not in MediaSource.SourceBuffers. |
| SetLiveSeekableRange(double, double) | Sets the range the media element can seek to when the duration is infinite (https://w3c.github.io/media-source/#dom-mediasource-setliveseekablerange). |
AddSourceBuffer(string)
MediaSource.csCreates a source buffer for a MIME type (https://w3c.github.io/media-source/#dom-mediasource-addsourcebuffer). Throws a TypeError for an empty type, a NotSupportedError when the media backend does not support the type, and an InvalidStateError when the source is not open.
public SourceBuffer AddSourceBuffer(string type)ClearLiveSeekableRange()
MediaSource.csClears the live seekable range (https://w3c.github.io/media-source/#dom-mediasource-clearliveseekablerange).
public void ClearLiveSeekableRange()EndOfStream(EndOfStreamError?)
MediaSource.csSignals the end of the stream (https://w3c.github.io/media-source/#dom-mediasource-endofstream): without error, the duration becomes the end of the buffered data and the media element can play to the end; with an error, the media element fails. Throws an InvalidStateError when the source is not open or a source buffer is updating.
public void EndOfStream(EndOfStreamError? error = null)IsTypeSupported(string)
MediaSource.csReturns whether a source buffer can be created for a MIME type (https://w3c.github.io/media-source/#dom-mediasource-istypesupported): the media backend of the current global object is confident that it can play the type (MediaBackend.CanPlayType is MediaTypeSupport.Probably: as in the browsers, a type that allows the codecs parameter and does not have it is not supported, though addSourceBuffer() accepts it) and creates a byte stream parser for it (MediaBackend.CreateSegmentParser).
RemoveSourceBuffer(SourceBuffer)
MediaSource.csRemoves a source buffer (https://w3c.github.io/media-source/#dom-mediasource-removesourcebuffer): its pending append is aborted, and its tracks are removed from the media element. Throws a NotFoundError when the buffer is not in MediaSource.SourceBuffers.
public void RemoveSourceBuffer(SourceBuffer sourceBuffer)SetLiveSeekableRange(double, double)
MediaSource.csSets the range the media element can seek to when the duration is infinite (https://w3c.github.io/media-source/#dom-mediasource-setliveseekablerange).