MediaBackend Class
The media pipeline plugged into the browsing contexts (BrowsingContextOptions.MediaBackend): it tells which media types can be played, reads the media resources fetched by the audio and video elements (their duration, their dimensions, their tracks) and plays them. The library never decodes audio or video by itself: it implements the processing model of the media elements (the resource selection, the fetch of the resource, the ready states, the events, the promises of play(), seeking, looping...) on top of the MediaPlayer the backend creates for each media resource.
public abstract class MediaBackendRemarks
Without a backend (the default), the media elements have no media resource: nothing is fetched, no media event is fired, canPlayType() returns the empty string and play() returns a promise rejected with a NotSupportedError.
A backend can be shared by several browsing contexts. Its methods are called on the thread of the event loop of the browsing context that uses them.
Constructors
| Name | Description |
|---|---|
| MediaBackend() |
MediaBackend()
protected MediaBackend()No documentation is available.
Methods
| Name | Description |
|---|---|
| CanPlayType(string, IReadOnlyList<string>) | Returns how confident the backend is that it can play the media resources of a type (https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype): the result of canPlayType(), and the source elements whose type attribute is MediaTypeSupport.NotSupported are skipped by the resource selection algorithm. As in the specification, a backend should not return MediaTypeSupport.Probably for a type that allows the codecs parameter when there is no codec. |
| CreatePlayer(MediaResource) | Opens a media resource fetched by a media element: the backend inspects the data (the format is sniffed, the Content-Type is only a hint) and returns the player of the resource once its metadata is known (its duration, its dimensions and its tracks), or null when the resource is in an unsupported format or cannot be rendered at all (the element then fails with MEDIA_ERR_SRC_NOT_SUPPORTED, or tries its next source element). |
| CreateSegmentParser(string, IReadOnlyList<string>) | Creates the byte stream parser of a SourceBuffer of the Media Source Extensions (https://w3c.github.io/media-source/): the backend parses the initialization segments and the media segments appended by the scripts (MediaSegmentParser), and the library implements MediaSource and SourceBuffer on top of it. The method also answers MediaSource.isTypeSupported(): the parser created to answer it is disposed at once. |
CanPlayType(string, IReadOnlyList<string>)
Returns how confident the backend is that it can play the media resources of a type (https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype): the result of canPlayType(), and the source elements whose type attribute is MediaTypeSupport.NotSupported are skipped by the resource selection algorithm. As in the specification, a backend should not return MediaTypeSupport.Probably for a type that allows the codecs parameter when there is no codec.
public abstract MediaTypeSupport CanPlayType(string mimeType, IReadOnlyList<string> codecs)Parameters
mimeTypestring- The essence of the MIME type, in ASCII lowercase (e.g.
video/webm). codecsIReadOnlyList<string>- The codecs of the
codecsparameter of the MIME type (e.g.vp9andopusforvideo/webm; codecs="vp9, opus"), or an empty list.
Returns
CreatePlayer(MediaResource)
Opens a media resource fetched by a media element: the backend inspects the data (the format is sniffed, the Content-Type is only a hint) and returns the player of the resource once its metadata is known (its duration, its dimensions and its tracks), or null when the resource is in an unsupported format or cannot be rendered at all (the element then fails with MEDIA_ERR_SRC_NOT_SUPPORTED, or tries its next source element).
public abstract MediaPlayer? CreatePlayer(MediaResource resource)Parameters
resourceMediaResource- The media resource.
Returns
MediaPlayer? The player of the resource, or null. The media element disposes it when it selects another resource.
Remarks
The method is called when the response arrives. For a response that arrives over time (MediaResource.IsComplete is false), a backend that cannot read the metadata from the first bytes returns null: the method is called again with the bytes received so far each time more bytes arrive, and the resource is unsupported when the complete resource gives no player.
CreateSegmentParser(string, IReadOnlyList<string>)
MediaBackend.csCreates the byte stream parser of a SourceBuffer of the Media Source Extensions (https://w3c.github.io/media-source/): the backend parses the initialization segments and the media segments appended by the scripts (MediaSegmentParser), and the library implements MediaSource and SourceBuffer on top of it. The method also answers MediaSource.isTypeSupported(): the parser created to answer it is disposed at once.
public virtual MediaSegmentParser? CreateSegmentParser(string mimeType, IReadOnlyList<string> codecs)Parameters
mimeTypestring- The essence of the MIME type, in ASCII lowercase (e.g.
video/mp4). codecsIReadOnlyList<string>- The codecs of the
codecsparameter of the MIME type, or an empty list.
Returns
MediaSegmentParser? The parser, or null when the backend cannot create a SourceBuffer for the type and its codecs.
Remarks
The default implementation returns null: no type is supported, so addSourceBuffer() throws a NotSupportedError. The position of a media element attached to a MediaSource advances with the clock of the event loop within the buffered ranges (the default playback of MediaPlayer): the coded frames are not decoded.