Class: shaka.media.Stream

Constructor

new Stream(parentnon-null, videonon-null, mediaSourcenon-null, fullMimeType, estimatornon-null)

Creates a Stream, which presents audio and video streams via an HTMLVideoElement.
Parameters:
Name Type Description
parent shaka.util.FakeEventTarget The parent for event bubbling.
video HTMLVideoElement
mediaSource MediaSource The MediaSource, which must be in the 'open' state.
fullMimeType string The full MIME type of the SourceBuffer to create, which |mediaSource| must support.
estimator shaka.util.IBandwidthEstimator A bandwidth estimator to attach to all segment requests.
Implements:
Extends:
Source:
Fires:
Throws:
if another SourceBuffer is not allowed.
Type
QuotaExceededError

Members

(private, static, constant) NUDGE_ :number

A tiny amount of time, in seconds, used to nudge the video element. This is used when the buffer has been cleared to get the media pipeline unstuck.
Type:
  • number
Source:
See:

(private) bufferSizeSeconds_ :number

Type:
  • number
Source:

(private) ended_ :boolean

Type:
  • boolean
Source:

(private, non-null) estimator_ :shaka.util.IBandwidthEstimator

Type:
Source:

(private) fetching_ :boolean

Type:
  • boolean
Source:

(private) initData_ :ArrayBuffer

Type:
  • ArrayBuffer
Source:

(private) initialBufferSizeSeconds_ :number

Type:
  • number
Source:

(private, non-null) listeners_ :shaka.util.MultiMap.<shaka.util.FakeEventTarget.ListenerType>

Type:
Inherited From:
Source:

(private) mimeType_ :string

Type:
  • string
Source:

(private) needsNudge_ :boolean

Work-around for MSE issues where the stream can get stuck after clearing the buffer or starting mid-stream (as is done for live). Nudging the playhead seems to get the browser's media pipeline moving again.
Type:
  • boolean
Source:

(protected) parent :shaka.util.FakeEventTarget

Type:
Inherited From:
Source:

(private) proceeded_ :boolean

Type:
  • boolean
Source:

(private) resyncing_ :boolean

Type:
  • boolean
Source:

(private, non-null) sbm_ :shaka.media.SourceBufferManager

Type:
Source:

(private) segmentIndex_ :shaka.media.SegmentIndex

Type:
Source:

(private) started_ :boolean

Type:
  • boolean
Source:

(private, non-null) startedPromise_ :shaka.util.PublicPromise

Type:
Source:

(private) streamInfo_ :shaka.media.StreamInfo

Type:
Source:

(private) switched_ :boolean

Type:
  • boolean
Source:

(private, nullable) timestampCorrection_ :number

Type:
  • number
Source:

(private, nullable) updateTimer_ :number

Type:
  • number
Source:

(private, non-null) video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

Methods

(private, static) createAdaptationEvent_(streamInfonon-null) → (non-null) {Event}

Creates an event object for an AdaptationEvent using the given StreamInfo.
Parameters:
Name Type Description
streamInfo shaka.media.StreamInfo
Source:
Returns:
Type
Event

addEventListener(type, listener, opt_capturingopt)

Add an event listener to this object.
Parameters:
Name Type Attributes Description
type string The event type to listen for.
listener shaka.util.FakeEventTarget.ListenerType The callback or listener object to invoke.
opt_capturing boolean <optional>
True to listen during the capturing phase, false to listen during the bubbling phase. Note that FakeEventTarget does not support the capturing phase from the standard event model.
Inherited From:
Source:

(private) cancelUpdateTimer_()

Cancels the update timer if it is running.
Source:

configure(confignon-null)

Configures the Stream options.

The following configuration options are supported:
  • initialStreamBufferSize: number
    Sets the amount of content, in seconds, that the Stream must buffer to ensure smooth playback.
  • streamBufferSize: number
    Sets the maximum amount of content, in seconds, that the Stream will buffer ahead of the playhead. If 'initialStreamBufferSize' is larger, then that value is used.
  • segmentRequestTimeout: number
    Sets the segment request timeout in seconds.
Parameters:
Name Type Description
config Object.<string, *> A configuration object, which contains the configuration options as key-value pairs. All fields should have already been validated.
Implements:
Source:
Example
stream.configure({'streamBufferSize': 20});

destroy()

Destroys the Stream.
Implements:
Source:

dispatchEvent(eventnon-null) → {boolean}

Dispatch an event from this object.
Parameters:
Name Type Description
event Event The event to be dispatched from this object.
Inherited From:
Source:
Returns:
True if the default action was prevented.
Type
boolean

(private) fireAdaptationEvent_(streamInfonon-null)

Fires an AdaptationEvent for the given StreamInfo.
Parameters:
Name Type Description
streamInfo shaka.media.StreamInfo
Source:

(private) fireEndedEvent_()

Fires an EndedEvent
Source:

(private) getBufferingGoal_() → {number}

Gets the Stream's buffering goal, which is the amount of content, in seconds, that the Stream attempts to buffer ahead of the Stream's current position.
Source:
Returns:
The buffering goal.
Type
number

getEnabled() → {boolean}

Always returns true since audio and video streams are always enabled.
Implements:
Source:
Returns:
True if the stream is enabled; otherwise, return false.
Type
boolean

(private) getNext_(currentTime, segmentIndexnon-null) → {shaka.media.SegmentReference}

Finds the next segment that starts at or after |currentTime| from |segmentIndex| that has not been inserted.
Parameters:
Name Type Description
currentTime number The time in seconds.
segmentIndex shaka.media.SegmentIndex
Source:
Returns:
Type
shaka.media.SegmentReference

getSegmentIndex() → {shaka.media.SegmentIndex}

Gets the SegmentIndex of the StreamInfo that corresponds to the stream that is currently being processed or presented. Note that this SegmentIndex may be different than the SegmentIndex of the last StreamInfo that was passed to switch() (see shaka.media.IStream#switch).
Implements:
Source:
Returns:
Type
shaka.media.SegmentIndex

getStreamInfo() → {shaka.media.StreamInfo}

Gets the StreamInfo that corresponds to the stream that is currently being processed or presented. Note that this StreamInfo may be different than the last StreamInfo that was passed to switch() (see shaka.media.IStream#switch).
Implements:
Source:
Returns:
Type
shaka.media.StreamInfo

hasEnded() → {boolean}

Returns true if the stream has ended; otherwise, returns false.

The Stream will not modify its underlying SourceBuffer while it's in the 'ended' state.

Implements:
Source:
Returns:
True if the stream has ended; otherwise, return false.
Type
boolean

isBuffered(time) → {boolean}

Gets whether the given time is currently buffered by the stream.
Parameters:
Name Type Description
time number The time in seconds to check.
Implements:
Source:
Returns:
Type
boolean

(private) logPrefix_() → {string}

Returns a string with the form 'Stream MIME_TYPE:' for logging purposes.
Source:
Returns:
Type
string

(private) onUpdate_()

Update callback.
Source:

(private) recursiveDispatch_(eventnon-null) → {boolean}

Dispatches an event recursively without changing its original target.
Parameters:
Name Type Description
event Event
Inherited From:
Source:
Returns:
True if the default action was prevented.
Type
boolean

removeEventListener(type, listener, opt_capturingopt)

Remove an event listener from this object.
Parameters:
Name Type Attributes Description
type string The event type for which you wish to remove a listener.
listener shaka.util.FakeEventTarget.ListenerType The callback or listener object to remove.
opt_capturing boolean <optional>
True to remove a listener for the capturing phase, false to remove a listener for the bubbling phase. Note that FakeEventTarget does not support the capturing phase from the standard event model.
Inherited From:
Source:

resync()

Resynchronizes the Stream's current position to the video's playhead. This must be called when the user seeks.
Implements:
Source:

(private) resync_(forceClear, opt_clearBufferOffsetopt)

Parameters:
Name Type Attributes Description
forceClear boolean
opt_clearBufferOffset number <optional>
if |forceClear| and |opt_clearBufferOffset| are truthy, clear the stream buffer from the given offset (relative to the video's current time) to the end of the stream.
Source:

setEnabled(enabled)

Does nothing since audio and video streams are always enabled.
Parameters:
Name Type Description
enabled boolean
Implements:
Source:

(private) setUpdateTimer_(ms)

Sets the update timer.
Parameters:
Name Type Description
ms number The timeout in milliseconds.
Source:

started(proceednon-null) → (non-null) {Promise.<number>}

Returns a promise that the Stream will resolve after it has buffered 'initialStreamBufferSize' seconds of content (see shaka.media.Stream#configure).

The Stream will not modify its underlying SourceBuffer while it's in the 'waiting' state (see shaka.media.IStream).

The caller should apply the timestamp correction to the Stream's current StreamInfo's SegmentIndex and future StreamInfo's passed to switch() before it resolves |proceed|.

Parameters:
Name Type Description
proceed Promise A Promise that the caller must resolve after startup completes to signal the Stream that it can proceed. The Stream will idle while in the 'waiting' state. Callers must never reject |proceed|.
Implements:
Source:
Returns:
A promise to a timestamp correction, which is the number of seconds that the media timeline (the sequence of timestamps in the stream's media segments) is offset from the Stream's initial StreamInfo's SegmentIndex (which is an approximation of the stream's media timeline). For example, if the timestamp correction is 5 then a SegmentReference that has a start time of 10 would correspond to a segment that actually starts at 15. For well formed content, the absolute value of the timestamp correction should be small, specifically, less than the duration of any one segment in the stream.
Type
Promise.<number>

(private) startIfNeeded_()

Corrects the SBM and resolves |startedPromise_| if needed.
Source:

switch(streamInfonon-null, clearBuffer, opt_clearBufferOffsetopt)

Starts presenting the specified stream asynchronously. The stream's MIME type must be compatible with the Stream's underlying SourceBuffer, i.e., the stream must have the same content type, container, and codec as the SourceBuffer, but the stream's codec's profile may vary.

Note: |opt_clearBufferOffset| is relative to the video's playhead.

Parameters:
Name Type Attributes Description
streamInfo shaka.media.StreamInfo
clearBuffer boolean If true, removes the previous stream's content before switching to the new stream.
opt_clearBufferOffset number <optional>
if |clearBuffer| and |opt_clearBufferOffset| are truthy, clear the stream buffer from the given offset (relative to the Stream's current position) to the end of the stream.
Implements:
Source:

Events

EndedEvent

Fired when the stream ends.
Properties:
Name Type Description
type string 'ended'
bubbles boolean false
Source:
Listeners of This Event: