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 newMediaSource 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
trueifMediaSourceworker support is implemented, orfalseotherwise.
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
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
handleis 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("Media Source Extensions API", "Media Source Extensions API", "", "nocode")}}
-MediaSource
-SourceBuffer
Onsourceclose
[Value("onsourceclose")]
public EventHandlerNonNull Onsourceclose { get; set; }
Property Value
Onsourceended
[Value("onsourceended")]
public EventHandlerNonNull Onsourceended { get; set; }
Property Value
Onsourceopen
[Value("onsourceopen")]
public EventHandlerNonNull Onsourceopen { get; set; }
Property Value
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 thisMediaSource.
[Value("sourceBuffers")]
public SourceBufferList SourceBuffers { get; }
Property Value
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's
SourceBuffers list. The newSourceBuffer is also returned.
[Value("addSourceBuffer")]
public SourceBuffer AddSourceBuffer(string type)
Parameters
typestring
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
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
errorEndOfStreamError
Returns
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
typestring
Returns
- bool
A value of
falseif the media of the given type will not play.A value oftrueis 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 "no/maybe/probably" approach (or, in this case, "no or probably") 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
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
sourceBufferSourceBuffer
Returns
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)