Constructor
new MediaSourceEngine(video)
MediaSourceEngine wraps all operations on MediaSource and SourceBuffers.
All asynchronous operations return a Promise, and all operations are
internally synchronized and serialized as needed. Operations that can
be done in parallel will be done in parallel.
Parameters:
Name | Type | Description |
---|---|---|
video |
HTMLMediaElement | The video element, whose source is tied to MediaSource during the lifetime of the MediaSourceEngine. |
- Implements:
- Source:
Members
(private) mediaSource_ :MediaSource
Type:
- MediaSource
- Source:
(private, non-null) queues_ :Object.<string, !Array.<shaka.media.MediaSourceEngine.Operation>>
Type:
- Object.<string, !Array.<shaka.media.MediaSourceEngine.Operation>>
- Source:
(private, non-null) sourceBuffers_ :Object.<shaka.util.ManifestParserUtils.ContentType, SourceBuffer>
Type:
- Object.<shaka.util.ManifestParserUtils.ContentType, SourceBuffer>
- Source:
(private, non-null) transmuxers_ :Object.<string, !shaka.media.Transmuxer>
Type:
- Object.<string, !shaka.media.Transmuxer>
- Source:
Methods
(static) isBrowserSupported() → {boolean}
Returns true if the browser has the basic APIs we need.
- Source:
Returns:
- Type
- boolean
(static) isStreamSupported(stream) → {boolean}
Checks if a certain type is supported.
Parameters:
Name | Type | Description |
---|---|---|
stream |
shakaExtern.Stream |
- Source:
Returns:
- Type
- boolean
(static) probeSupport() → (non-null) {Object.<string, boolean>}
Returns a map of MediaSource support for well-known types.
- Source:
Returns:
- Type
- Object.<string, boolean>
(private) abort_(contentType)
Call abort() on the SourceBuffer.
This resets MSE's last_decode_timestamp on all track buffers, which should
trigger the splicing logic for overlapping segments.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
(private) append_(contentType, datanon-null)
Append data to the SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
data |
ArrayBuffer |
- Source:
Throws:
QuotaExceededError if the browser's buffer is full
appendBuffer(contentType, datanon-null, startTimenullable, endTimenullable) → (non-null) {Promise}
Enqueue an operation to append data to the SourceBuffer.
Start and end times are needed for TextEngine, but not for MediaSource.
Start and end times may be null for initialization segments; if present they
are relative to the presentation timeline.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | ||
data |
ArrayBuffer | ||
startTime |
number |
<nullable> |
|
endTime |
number |
<nullable> |
- Source:
Returns:
- Type
- Promise
bufferedAheadOf(contentType, time) → {number}
Computes how far ahead of the given timestamp is buffered for the given
content type.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
time |
number |
- Source:
Returns:
The amount of time buffered ahead in seconds.
- Type
- number
bufferEnd(contentType) → (nullable) {number}
Gets the last timestamp in buffer for the given content type.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
Returns:
The timestamp in seconds, or null if nothing is buffered.
- Type
- number
bufferStart(contentType) → (nullable) {number}
Gets the first timestamp in buffer for the given content type.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
Returns:
The timestamp in seconds, or null if nothing is buffered.
- Type
- number
clear(contentType) → (non-null) {Promise}
Enqueue an operation to clear the SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
Returns:
- Type
- Promise
createMediaSource(pnon-null) → (non-null) {MediaSource}
Create a MediaSource object, attach it to the video element, and return it.
Resolves the given promise when the MediaSource is ready.
Replaced by unit tests.
Parameters:
Name | Type | Description |
---|---|---|
p |
shaka.util.PublicPromise |
- Source:
Returns:
- Type
- MediaSource
(export) destroy() → (non-null) {Promise}
Destroys the object, releasing all resources and shutting down all
operations. Returns a Promise which is resolved when destruction is
complete. This Promise should never be rejected.
- Implements:
- Source:
Returns:
- Type
- Promise
ended() → {boolean}
- Source:
Returns:
True if the MediaSource is in an "ended" state, or if the
object has been destroyed.
- Type
- boolean
endOfStream(opt_reasonopt) → (non-null) {Promise}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opt_reason |
string |
<optional> |
Valid reasons are 'network' and 'decode'. |
- Source:
- See:
Returns:
- Type
- Promise
(private) enqueueBlockingOperation_(run) → (non-null) {Promise}
Enqueue an operation which must block all other operations on all
SourceBuffers.
Parameters:
Name | Type | Description |
---|---|---|
run |
function() |
- Source:
Returns:
- Type
- Promise
(private) enqueueOperation_(contentType, start) → (non-null) {Promise}
Enqueue an operation and start it if appropriate.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
start |
function() |
- Source:
Returns:
- Type
- Promise
flush(contentType) → (non-null) {Promise}
Enqueue an operation to flush the SourceBuffer.
This is a workaround for what we believe is a Chromecast bug.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
Returns:
- Type
- Promise
(private) flush_(contentType)
Nudge the playhead to force the media pipeline to be flushed.
This seems to be necessary on Chromecast to get new content to replace old
content.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
(private) getBuffered_(contentType) → {TimeRanges}
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
Returns:
The buffered ranges for the given content type, or
null if the buffered ranges could not be obtained.
- Type
- TimeRanges
getDuration() → {number}
Get the current MediaSource duration.
- Source:
Returns:
- Type
- number
getUseEmbeddedText() → {boolean}
Get whether we're using the embedded text cues.
- Source:
Returns:
- Type
- boolean
init(streamsByTypenon-null, forceTransmuxTS) → (non-null) {Promise}
Initialize MediaSourceEngine.
Note that it is not valid to call this multiple times, except to add or
reinitialize text streams.
Parameters:
Name | Type | Description |
---|---|---|
streamsByType |
Object.<shaka.util.ManifestParserUtils.ContentType, shakaExtern.Stream> | A map of content types to streams. All streams must be supported according to MediaSourceEngine.isStreamSupported. |
forceTransmuxTS |
boolean | If true, this will transmux TS content even if it is natively supported. |
- Source:
Throws:
-
InvalidAccessError if blank MIME types are given
-
NotSupportedError if unsupported MIME types are given
-
QuotaExceededError if the browser can't support that many buffers
Returns:
- Type
- Promise
isBuffered(contentType, time) → {boolean}
Determines if the given time is inside the buffered range of the given
content type.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
time |
number |
- Source:
Returns:
- Type
- boolean
(private) onError_(contentType, eventnon-null)
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
event |
Event |
- Source:
(private) onUpdateEnd_(contentType)
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
open() → (non-null) {Promise}
- Source:
Returns:
Resolved when MediaSource is open and attached to the
media element. This process is actually initiated by the constructor.
- Type
- Promise
(private) popFromQueue_(contentType)
Pop from the front of the queue and start a new operation.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
reinitText(mimeType)
Reinitialize the TextEngine for a new text type.
Parameters:
Name | Type | Description |
---|---|---|
mimeType |
string |
- Source:
remove(contentType, startTime, endTime) → (non-null) {Promise}
Enqueue an operation to remove data from the SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
startTime |
number | |
endTime |
number |
- Source:
Returns:
- Type
- Promise
(private) remove_(contentType, startTime, endTime)
Remove data from the SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
startTime |
number | |
endTime |
number |
- Source:
(private) setAppendWindow_(contentType, appendWindowStart, appendWindowEnd)
Set the SourceBuffer's append window end.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
appendWindowStart |
number | |
appendWindowEnd |
number |
- Source:
setDuration(duration) → (non-null) {Promise}
We only support increasing duration at this time. Decreasing duration
causes the MSE removal algorithm to run, which results in an 'updateend'
event. Supporting this scenario would be complicated, and is not currently
needed.
Parameters:
Name | Type | Description |
---|---|---|
duration |
number |
- Source:
Returns:
- Type
- Promise
setStreamProperties(contentType, timestampOffset, appendWindowStart, appendWindowEnd) → (non-null) {Promise}
Sets the timestamp offset and append window end for the given content type.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
timestampOffset |
number | The timestamp offset. Segments which start at time t will be inserted at time t + timestampOffset instead. This value does not affect segments which have already been inserted. |
appendWindowStart |
number | The timestamp to set the append window start to. Media before this value will be truncated. |
appendWindowEnd |
number | The timestamp to set the append window end to. Media beyond this value will be truncated. |
- Source:
Returns:
- Type
- Promise
setTextDisplayer(textDisplayer)
Parameters:
Name | Type | Description |
---|---|---|
textDisplayer |
shakaExtern.TextDisplayer |
- Source:
(private) setTimestampOffset_(contentType, timestampOffset)
Set the SourceBuffer's timestamp offset.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
timestampOffset |
number |
- Source:
setUseEmbeddedText(useEmbeddedText)
Set whether to use embedded text cues.
Used for CEA 608/708 captions data, which is embedded inside the video
stream.
Parameters:
Name | Type | Description |
---|---|---|
useEmbeddedText |
boolean |
- Source:
Type Definitions
Operation
An operation in queue.
Type:
- {start: function(), p: !shaka.util.PublicPromise}
Properties:
Name | Type | Description |
---|---|---|
start |
function | The function which starts the operation. |
p |
shaka.util.PublicPromise | The PublicPromise which is associated with this operation. |
- Source: