Table of Contents

Class MediaSource

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The MediaSource interface of the {{domxref("Media Source Extensions API", "Media Source Extensions API", "", "nocode")}} represents a source of media data for an HTMLMediaElement object. A MediaSource object can be attached to a HTMLMediaElement to be played in the user agent.

[Value("MediaSource")]
public class MediaSource : EventTarget
Inheritance
MediaSource
Derived
Inherited Members

Remarks

Constructors

MediaSource()

The MediaSource() constructor of the
MediaSource interface constructs and returns a new
MediaSource object with no associated source buffers.

public MediaSource()

Remarks

Properties

ActiveSourceBuffers

The activeSourceBuffers read-only property of the
MediaSource interface returns a SourceBufferList object
containing a subset of the SourceBuffer objects contained within
SourceBuffers — the list of objects
providing the selected video track, enabled audio tracks, and shown/hidden text tracks.

[Value("activeSourceBuffers")]
public SourceBufferList ActiveSourceBuffers { get; }

Property Value

SourceBufferList

A SourceBufferList containing the SourceBuffer objects
for each of the active tracks.

Remarks

CanConstructInDedicatedWorker

The canConstructInDedicatedWorker static property of the MediaSource interface returns true if MediaSource worker support is implemented, providing a low-latency feature detection mechanism.

[Value("canConstructInDedicatedWorker")]
public static bool CanConstructInDedicatedWorker { get; }

Property Value

bool

A boolean. Returns true if MediaSource worker support is implemented, or false otherwise.

Remarks

If this were not available, the alternative would be a much higher latency approach such as attempting the creation of a MediaSource object from a dedicated worker and transferring the result back to the main thread.

-MSE-in-Workers Demo by Matt Wolenetz
-{{domxref("Media Source Extensions API", "Media Source Extensions API", "", "nocode")}}
-MediaSource
-SourceBuffer

See also on MDN

Duration

The duration property of the MediaSource
interface gets and sets the duration of the current media being presented.

[Value("duration")]
public double Duration { get; set; }

Property Value

double

A double. A value in seconds is expected.

Remarks

Handle

The handle read-only property of the MediaSource interface returns a MediaSourceHandle object, a proxy for the MediaSource that can be transferred from a dedicated worker back to the main thread and attached to a media element via its SrcObject property.

[Value("handle")]
public MediaSourceHandle Handle { get; }

Property Value

MediaSourceHandle

A MediaSourceHandle object instance.

Remarks

NOTE

handle is only visible on MediaSource instances inside dedicated workers.

Each MediaSource object created inside a dedicated worker has its own distinct MediaSourceHandle. The handle getter will always return the MediaSourceHandle instance specific to the associated dedicated worker MediaSource instance. If the handle has already been transferred to the main thread using PostMessage(dynamic, List<Object>), the handle instance in the worker is technically detached and can't be transferred again.

-MSE-in-Workers Demo by Matt Wolenetz
-{{domxref(&quot;Media Source Extensions API&quot;, &quot;Media Source Extensions API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-MediaSource
-SourceBuffer

See also on MDN

Onsourceclose

[Value("onsourceclose")]
public EventHandlerNonNull Onsourceclose { get; set; }

Property Value

EventHandlerNonNull

Onsourceended

[Value("onsourceended")]
public EventHandlerNonNull Onsourceended { get; set; }

Property Value

EventHandlerNonNull

Onsourceopen

[Value("onsourceopen")]
public EventHandlerNonNull Onsourceopen { get; set; }

Property Value

EventHandlerNonNull

ReadyState

The readyState read-only property of the
MediaSource interface returns an enum representing the state of the
current MediaSource. The three possible values are:

[Value("readyState")]
public ReadyState ReadyState { get; }

Property Value

ReadyState

A string.

Remarks

SourceBuffers

The sourceBuffers read-only property of the
MediaSource interface returns a SourceBufferList object
containing the list of SourceBuffer objects associated with this
MediaSource.

[Value("sourceBuffers")]
public SourceBufferList SourceBuffers { get; }

Property Value

SourceBufferList

A SourceBufferList.

Remarks

Methods

AddSourceBuffer(string)

The addSourceBuffer() method of the
MediaSource interface creates a new SourceBuffer of the
given MIME type and adds it to the MediaSource&apos;s
SourceBuffers list. The new
SourceBuffer is also returned.

[Value("addSourceBuffer")]
public SourceBuffer AddSourceBuffer(string type)

Parameters

type string

Returns

SourceBuffer

A SourceBuffer object representing the new source buffer that has been
created and added to the media source.

Remarks

ClearLiveSeekableRange()

The clearLiveSeekableRange() method of the
MediaSource interface clears a seekable range previously set with a call
to SetLiveSeekableRange(Number, Number).

[Value("clearLiveSeekableRange")]
public GlobalObject.Undefined ClearLiveSeekableRange()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

EndOfStream(EndOfStreamError)

The endOfStream() method of the
MediaSource interface signals the end of the stream.

[Value("endOfStream")]
public GlobalObject.Undefined EndOfStream(EndOfStreamError error = EndOfStreamError.Network)

Parameters

error EndOfStreamError

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

IsTypeSupported(string)

The MediaSource.isTypeSupported() static method returns a boolean value which is true if the given MIME type and (optional) codec are likely to be supported by the current user agent.

[Value("isTypeSupported")]
public static bool IsTypeSupported(string type)

Parameters

type string

Returns

bool

A value of false if the media of the given type will not play.A value of true is returned if the browser can probably play media of the specified type.
This is not a guarantee, and your code must be prepared for the possibility that the media will not play correctly if at all.All web APIs that work with media files use a &quot;no/maybe/probably&quot; approach (or, in this case, &quot;no or probably&quot;) when determining if a media type can be used.
This is because media files are complex, intricate constructs with far too many subtle variations to be absolutely certain of anything until you actually use the contents of the media.

Remarks

That is, if it can successfully create SourceBuffer objects for that media type.
If the returned value is false, then the user agent is certain that it cannot access media of the specified format.

-Media Source Extensions API
-Guide to media types and formats on the web
-Codecs in common media types
-SourceBuffer
-SourceBufferList

See also on MDN

RemoveSourceBuffer(SourceBuffer)

The removeSourceBuffer() method of the MediaSource interface removes the given SourceBuffer from the SourceBufferList associated with this MediaSource object.

[Value("removeSourceBuffer")]
public GlobalObject.Undefined RemoveSourceBuffer(SourceBuffer sourceBuffer)

Parameters

sourceBuffer SourceBuffer

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

SetLiveSeekableRange(Number, Number)

The setLiveSeekableRange() method of the
MediaSource interface sets the range that the user can seek to in the
media element.

[Value("setLiveSeekableRange")]
public GlobalObject.Undefined SetLiveSeekableRange(Number start, Number end)

Parameters

start Number
end Number

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks