Class: shaka.Player

Constructor

(export) new Player(mediaElementopt, dependencyInjectoropt)

Construct a Player.
Parameters:
Name Type Attributes Description
mediaElement HTMLMediaElement <optional>
When provided, the player will attach to |mediaElement|, similar to calling |attach|. When not provided, the player will remain detached.
dependencyInjector function(shaka.Player)= <optional>
Optional callback which is called to inject mocks into the Player. Used for testing.
Implements:
Extends:
Source:

Extends

Members

(export, static) LoadMode :number

In order to know what method of loading the player used for some content, we have this enum. It lets us know if content has not been loaded, loaded with media source, or loaded with src equals. This enum has a low resolution, because it is only meant to express the outer limits of the various states that the player is in. For example, when someone calls a public method on player, it should not matter if they have initialized drm engine, it should only matter if they finished loading content.
Type:
  • number
Properties:
Name Value Type Description
DESTROYED 0 number
NOT_LOADED 1 number
MEDIA_SOURCE 2 number
SRC_EQUALS 3 number
Source:

(private, static, constant, non-null) restrictedStatuses_ :Array.<string>

These are the EME key statuses that represent restricted playback. 'usable', 'released', 'output-downscaled', 'status-pending' are statuses of the usable keys. 'expired' status is being handled separately in DrmEngine.
Type:
  • Array.<string>
Source:

(private, static, non-null) supportPlugins_ :Object.<string, function(): *>

Type:
  • Object.<string, function(): *>
Source:

(static, constant) TextTrackLabel :string

Type:
  • string
Source:

(private, static, constant) TYPICAL_BUFFERING_THRESHOLD_ :number

The typical buffering threshold. When we have less than this buffered (in seconds), we enter a buffering state. This specific value is based on manual testing and evaluation across a variety of platforms. To make the buffering logic work in all cases, this "typical" threshold will be overridden if the rebufferingGoal configuration is too low.
Type:
  • number
Source:

(export, static, constant) version :string

A version number taken from git at compile time.
Type:
  • string
Source:

(private, nullable) abrManagerFactory_ :shaka.extern.AbrManager.Factory

The factory that was used to create the abrManager_ instance.
Type:
Source:

(private, non-null) activeStreams_ :shaka.media.ActiveStreamMap

A mapping of which streams are/were active in each period. Used when the current period (the one containing playhead) differs from the active period (the one being streamed in by streaming engine).
Type:
Source:

(private, nullable) assetUri_ :string

Type:
  • string
Source:

(private) attachNode_ :shaka.routing.Node

Type:
Source:

(private) bufferPoller_ :shaka.util.Timer

Type:
Source:

(private, non-null) cleanupOnUnload_ :Array.<function(): (!Promise|undefined)>

Type:
  • Array.<function(): (!Promise|undefined)>
Source:

(private, non-null) currentAdaptationSetCriteria_ :shaka.media.AdaptationSetCriteria

Type:
Source:

(private) currentTextLanguage_ :string

Type:
  • string
Source:

(private) currentTextRole_ :string

Type:
  • string
Source:

(private, nullable) deferredTextStream_ :shaka.extern.Stream

Type:
Source:

(private, nullable) deferredVariant_ :shaka.extern.Variant

Type:
Source:

(private) deferredVariantClearBuffer_ :boolean

Type:
  • boolean
Source:

(private) deferredVariantClearBufferSafeMargin_ :number

Type:
  • number
Source:

(private) detachNode_ :shaka.routing.Node

Type:
Source:

dispatchTarget :EventTarget

The target of all dispatched events. Defaults to |this|.
Type:
  • EventTarget
Inherited From:
Source:

(private) drmEngine_ :shaka.media.DrmEngine

Type:
Source:

(private) drmNode_ :shaka.routing.Node

Type:
Source:

(private) eventManager_ :shaka.util.EventManager

Type:
Source:

(private) isTextVisible_ :boolean

Since we may not always have a text displayer created (e.g. before |load| is called), we need to track what text visibility SHOULD be so that we can ensure that when we create the text displayer. When we create our text displayer, we will use this to show (or not show) text as per the user's requests.
Type:
  • boolean
Source:

(private, nullable) lastTextFactory_ :shaka.extern.TextDisplayer.Factory

The TextDisplayerFactory that was last used to make a text displayer. Stored so that we can tell if a new type of text displayer is desired.
Type:
Source:

(private, non-null) loadingTextStreams_ :Set.<shaka.extern.Stream>

Type:
Source:

(private) loadNode_ :shaka.routing.Node

Type:
Source:

(private, nullable) manifest_ :shaka.extern.Manifest

Type:
Source:

(private) manifestNode_ :shaka.routing.Node

Type:
Source:

(private) maxHwRes_ :{width: number, height: number}

Type:
  • {width: number, height: number}
Source:

(private) mediaSourceNode_ :shaka.routing.Node

Type:
Source:

(private) networkingEngine_ :shaka.net.NetworkingEngine

Type:
Source:

(private) nextExternalStreamId_ :number

Contains an ID for use with creating streams. The manifest parser should start with small IDs, so this starts with a large one.
Type:
  • number
Source:

(private) parserNode_ :shaka.routing.Node

Type:
Source:

(private) playhead_ :shaka.media.Playhead

Type:
Source:

(private) playheadObservers_ :shaka.media.PlayheadObserverManager

The playhead observers are used to monitor the position of the playhead and some other source of data (e.g. buffered content), and raise events.
Type:
Source:

(private) playRateController_ :shaka.media.PlayRateController

This is our control over the playback rate of the media element. This provides the missing functionality that we need to provide trick play, for example a negative playback rate.
Type:
Source:

(private) srcEqualsDrmNode_ :shaka.routing.Node

Type:
Source:

(private) srcEqualsNode_ :shaka.routing.Node

Type:
Source:

(private) stats_ :shaka.util.Stats

Type:
Source:

(private) switchingPeriods_ :boolean

Type:
  • boolean
Source:

(private) unloadNode_ :shaka.routing.Node

Type:
Source:

(private) video_ :HTMLMediaElement

Type:
Source:

video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

(non-null) video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

(private, inner, constant) walkerImplementation :shaka.routing.Walker.Implementation

Type:
Source:

Methods

(private, static) applyPlayRange_(timeline, playRangeStart, playRangeEnd)

Applies playRangeStart and playRangeEnd to the given timeline. This will only affect non-live content.
Parameters:
Name Type Description
timeline shaka.media.PresentationTimeline
playRangeStart number
playRangeEnd number
Source:

(private, static) filterForAVVariants_(periodsnon-null)

Take a series of periods and ensure that they only contain one type of variant. The different options are: 1. Audio-Video 2. Audio-Only 3. Video-Only A manifest can only contain a single type because once we initialize media source to expect specific streams, it must always have content for those streams. If we were to start period 1 with audio+video but period 2 only had audio, media source would block waiting for video content.
Parameters:
Name Type Description
periods Array.<shaka.extern.Period>
Source:

(private, static) getLanguageAndRolesFrom_(tracksnon-null) → (non-null) {Array.<shaka.extern.LanguageRole>}

Get all permutations of normalized languages and role for a group of tracks.
Parameters:
Name Type Description
tracks Array.<?shaka.extern.Track>
Source:
Returns:
Type
Array.<shaka.extern.LanguageRole>

(private, static) getLanguagesFrom_(tracksnon-null) → (non-null) {Set.<string>}

Get the normalized languages for a group of tracks.
Parameters:
Name Type Description
tracks Array.<?shaka.extern.Track>
Source:
Returns:
Type
Set.<string>

(export, static) isBrowserSupported() → {boolean}

Return whether the browser provides basic support. If this returns false, Shaka Player cannot be used at all. In this case, do not construct a Player instance and do not use the library.
Source:
Returns:
Type
boolean

(export, static) probeSupport() → (non-null) {Promise.<shaka.extern.SupportType>}

Probes the browser to determine what features are supported. This makes a number of requests to EME/MSE/etc which may result in user prompts. This should only be used for diagnostics. NOTE: This may show a request to the user for permission.
Source:
See:
Returns:
Type
Promise.<shaka.extern.SupportType>

(export, static) registerSupportPlugin(name, callback)

Registers a plugin callback that will be called with support(). The callback will return the value that will be stored in the return value from support().
Parameters:
Name Type Description
name string
callback function():*
Source:

(export) addEventListener(type, listener, optionsopt)

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.
options AddEventListenerOptions | boolean <optional>
Ignored.
Inherited From:
Source:

(private) addTextStreamToSwitchHistory_(period, textStream, fromAdaptation)

Parameters:
Name Type Description
period shaka.extern.Period
textStream shaka.extern.Stream
fromAdaptation boolean
Source:

(export) addTextTrack(uri, language, kind, mime, codecopt, labelopt) → (non-null) {Promise.<shaka.extern.Track>}

Adds the given text track to the current Period. load() must resolve before calling. The current Period or the presentation must have a duration. This returns a Promise that will resolve with the track that was created, when that track can be switched to.
Parameters:
Name Type Attributes Description
uri string
language string
kind string
mime string
codec string <optional>
label string <optional>
Source:
Returns:
Type
Promise.<shaka.extern.Track>

(private) addVariantToSwitchHistory_(period, variant, fromAdaptation)

Parameters:
Name Type Description
period shaka.extern.Period
variant shaka.extern.Variant
fromAdaptation boolean
Source:

(private) adjustStartTime_(time) → {number}

Parameters:
Name Type Description
time number
Source:
Returns:
Type
number

(private) applyConfig_()

Apply config changes.
Source:

(private) assertCorrectActiveStreams_()

Verifies that the active streams according to the player match those in StreamingEngine.
Source:

(export) attach(mediaElementnon-null, initializeMediaSourceopt) → (non-null) {Promise}

Tell the player to use |mediaElement| for all |load| requests until |detach| or |destroy| are called. Calling |attach| with |initializedMediaSource=true| will tell the player to take the initial load step and initialize media source. Calls to |attach| will interrupt any in-progress calls to |load| but cannot interrupt calls to |attach|, |detach|, or |unload|.
Parameters:
Name Type Attributes Description
mediaElement HTMLMediaElement
initializeMediaSource boolean <optional>
Source:
Returns:
Type
Promise

(export) cancelTrickPlay()

Cancel trick-play. If the player has not loaded content or is still loading content this will be a no-op.
Source:

(private) canSwitch_()

Callback from StreamingEngine, invoked when the period is set up.
Source:

(private) checkRestrictedVariants_(variantsnon-null)

Checks the given variants and if they are all restricted, throw an appropriate exception.
Parameters:
Name Type Description
variants Array.<shaka.extern.Variant>
Source:

(private) chooseStreams_(period) → {shaka.media.StreamingEngine.ChosenStreams}

This is the internal logic for |onChooseStreams_|. This separation is done to allow this implementation to throw errors without consequence.
Parameters:
Name Type Description
period shaka.extern.Period The period that we are selecting streams from.
Source:
Returns:
An object containing the chosen variant and text stream.
Type
shaka.media.StreamingEngine.ChosenStreams

(private) chooseStreamsAndSwitch_(periodnon-null)

Chooses streams from the given Period and switches to them. Called after a config change, a new text stream, a key status event, or an explicit language change.
Parameters:
Name Type Description
period shaka.extern.Period
Source:

(private) chooseTextAndSwitch_(periodnon-null) → {boolean}

If text should be streamed, chooses a text stream from the given Period and switches to it.
Parameters:
Name Type Description
period shaka.extern.Period
Source:
Returns:
Type
boolean

(private) chooseTextStream_(textStreamsnon-null) → (nullable) {shaka.extern.Stream}

Choose a text stream from all possible text streams while taking into account user preference.
Parameters:
Name Type Description
textStreams Array.<shaka.extern.Stream>
Source:
Returns:
Type
shaka.extern.Stream

(private) chooseVariant_(allVariantsnon-null) → (nullable) {shaka.extern.Variant}

Chooses a variant from all possible variants while taking into account restrictions, preferences, and ABR. On error, this dispatches an error event and returns null.
Parameters:
Name Type Description
allVariants Array.<shaka.extern.Variant>
Source:
Returns:
Type
shaka.extern.Variant

(private) chooseVariantAndSwitch_(periodnon-null, fireAdaptationEventopt) → {boolean}

Chooses a variant from the given Period and switches to it.
Parameters:
Name Type Attributes Description
period shaka.extern.Period
fireAdaptationEvent boolean <optional>
Source:
Returns:
Type
boolean

(export) configure(config, valueopt) → {boolean}

Configure the Player instance. The config object passed in need not be complete. It will be merged with the existing Player configuration. Config keys and types will be checked. If any problems with the config object are found, errors will be reported through logs and this returns false. If there are errors, valid config objects are still set.
Parameters:
Name Type Attributes Description
config string | Object This should either be a field name or an object following the form of shaka.extern.PlayerConfiguration, where you may omit any field you do not wish to change.
value * <optional>
This should be provided if the previous parameter was a string field name.
Source:
Returns:
True if the passed config object was valid, false if there were invalid entries.
Type
boolean

(private) createAbortLoadError_() → (non-null) {shaka.util.Error}

Create an error for when we purposely interrupt a load operation.
Source:
Returns:
Type
shaka.util.Error

createDrmEngine(playerInterface) → (non-null) {shaka.media.DrmEngine}

Create a new DrmEngine instance. This may be replaced by tests to create fake instances. Configuration and initialization will be handled after |createDrmEngine|.
Parameters:
Name Type Description
playerInterface shaka.media.DrmEngine.PlayerInterface
Source:
Returns:
Type
shaka.media.DrmEngine

(private) createEmptyPayload_() → {shaka.routing.Payload}

Source:
Returns:
Type
shaka.routing.Payload

createMediaSourceEngine(mediaElementnon-null, closedCaptionsParsernon-null, textDisplayernon-null) → (non-null) {shaka.media.MediaSourceEngine}

Create a new media source engine. This will ONLY be replaced by tests as a way to inject fake media source engine instances.
Parameters:
Name Type Description
mediaElement HTMLMediaElement
closedCaptionsParser shaka.media.IClosedCaptionParser
textDisplayer shaka.extern.TextDisplayer
Source:
Returns:
Type
shaka.media.MediaSourceEngine

createNetworkingEngine() → (non-null) {shaka.net.NetworkingEngine}

Creates a new instance of NetworkingEngine. This can be replaced by tests to create fake instances instead.
Source:
Returns:
Type
shaka.net.NetworkingEngine

createPlayhead(startTimenullable) → (non-null) {shaka.media.Playhead}

Creates a new instance of Playhead. This can be replaced by tests to create fake instances instead.
Parameters:
Name Type Attributes Description
startTime number <nullable>
Source:
Returns:
Type
shaka.media.Playhead

(private) createPlayheadObserversForMSE_() → (non-null) {shaka.media.PlayheadObserverManager}

Create the observers for MSE playback. These observers are responsible for notifying the app and player of specific events during MSE playback.
Source:
Returns:
Type
shaka.media.PlayheadObserverManager

createStreamingEngine() → (non-null) {shaka.media.StreamingEngine}

Creates a new instance of StreamingEngine. This can be replaced by tests to create fake instances instead.
Source:
Returns:
Type
shaka.media.StreamingEngine

(private) createTextStreamsForClosedCaptions_(periodsnon-null)

For CEA closed captions embedded in the video streams, create dummy text stream.
Parameters:
Name Type Description
periods Array.<!shaka.extern.Period>
Source:

(private) defaultConfig_() → {shaka.extern.PlayerConfiguration}

Source:
Returns:
Type
shaka.extern.PlayerConfiguration

(private) defaultStreamingFailureCallback_(errornon-null)

Parameters:
Name Type Description
error shaka.util.Error
Source:

(private) delayDispatchEvent_(eventnon-null)

Fire an event, but wait a little bit so that the immediate execution can complete before the event is handled.
Parameters:
Name Type Description
event shaka.util.FakeEvent
Source:

(export) destroy() → (non-null) {Promise}

After destruction, a Player object cannot be used again.
Implements:
Source:
Returns:
Type
Promise

(export) detach() → (non-null) {Promise}

Tell the player to stop using its current media element. If the player is: - detached, this will do nothing, - attached, this will release the media element, - loading, this will abort loading, unload, and release the media element, - playing content, this will stop playback, unload, and release the media element. Calls to |detach| will interrupt any in-progress calls to |load| but cannot interrupt calls to |attach|, |detach|, or |unload|.
Source:
Returns:
Type
Promise

(export) 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

(export) drmInfo() → (nullable) {shaka.extern.DrmInfo}

Get the drm info used to initialize EME. If EME is not being used, this will return |null|. If the player is idle or has not initialized EME yet, this will return |null|.
Source:
Returns:
Type
shaka.extern.DrmInfo

(private) filterAllPeriods_(periodsnon-null)

Filters a list of periods.
Parameters:
Name Type Description
periods Array.<!shaka.extern.Period>
Source:

(private) filterNewPeriod_(period)

Filters a new period.
Parameters:
Name Type Description
period shaka.extern.Period
Source:

(private) filterTextTracks_() → (non-null) {Array.<TextTrack>}

Ignore the TextTracks with the 'metadata' kind, or the one generated by the SimpleTextDisplayer.
Source:
Returns:
Type
Array.<TextTrack>

(private) findPeriodWithVariant_(variant) → (nullable) {shaka.extern.Period}

Find the period in |this.manifest_| that contains |variant|. If no period contains |variant| this will return |null|.
Parameters:
Name Type Description
variant shaka.extern.Variant
Source:
Returns:
Type
shaka.extern.Period

(export) getAssetUri() → (nullable) {string}

Get the uri to the asset that the player has loaded. If the player has not loaded content, this will return |null|.
Source:
Returns:
Type
string

(export) getAudioLanguages() → (non-null) {Array.<string>}

Return a list of audio languages available for the current period. If the player has not loaded any content, this will return an empty list.
Source:
Returns:
Type
Array.<string>

(export) getAudioLanguagesAndRoles() → (non-null) {Array.<shaka.extern.LanguageRole>}

Return a list of audio language-role combinations available for the current period. If the player has not loaded any content, this will return an empty list.
Source:
Returns:
Type
Array.<shaka.extern.LanguageRole>

(export) getBufferedInfo() → {shaka.extern.BufferedInfo}

Get information about what the player has buffered. If the player has not loaded content or is currently loading content, the buffered content will be empty.
Source:
Returns:
Type
shaka.extern.BufferedInfo

(export) getConfiguration() → {shaka.extern.PlayerConfiguration}

Return a copy of the current configuration. Modifications of the returned value will not affect the Player's active configuration. You must call player.configure() to make changes.
Source:
Returns:
Type
shaka.extern.PlayerConfiguration

(export) getExpiration() → {number}

Get the next known expiration time for any EME session. If the session never expires, this will return |Infinity|. If there are no EME sessions, this will return |Infinity|. If the player has not loaded content, this will return |Infinity|.
Source:
Returns:
Type
number

(export) getLoadMode() → {shaka.Player.LoadMode}

Get the current load mode.
Source:
Returns:
Type
shaka.Player.LoadMode

(export) getManifest() → (nullable) {shaka.extern.Manifest}

Get the manifest that the player has loaded. If the player has not loaded any content, this will return |null|.
Source:
Returns:
Type
shaka.extern.Manifest

(export) getManifestParserFactory() → (nullable) {shaka.extern.ManifestParser.Factory}

Get the type of manifest parser that the player is using. If the player has not loaded any content, this will return |null|.
Source:
Returns:
Type
shaka.extern.ManifestParser.Factory

(export) getManifestUri() → (nullable) {string}

Get the uri to the asset that the player has loaded. If the player has not loaded content, this will return |null|.
Deprecated:
  • Yes
Source:
Returns:
Type
string

(export) getMediaElement() → {HTMLMediaElement}

Get the media element that the player is currently using to play loaded content. If the player has not loaded content, this will return |null|.
Source:
Returns:
Type
HTMLMediaElement

(export) getNetworkingEngine() → {shaka.net.NetworkingEngine}

Source:
Returns:
A reference to the Player's networking engine. Applications may use this to make requests through Shaka's networking plugins.
Type
shaka.net.NetworkingEngine

(private) getNextAfterAttach_(goingTonon-null, has, wants) → (nullable) {shaka.routing.Node}

Parameters:
Name Type Description
goingTo shaka.routing.Node
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
shaka.routing.Node

(private) getNextAfterMediaSource_(goingTonon-null, has, wants) → (nullable) {shaka.routing.Node}

Parameters:
Name Type Description
goingTo shaka.routing.Node
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
shaka.routing.Node

(private) getNextAfterUnload_(goingTonon-null, has, wants) → (nullable) {shaka.routing.Node}

After unload there are only two options, attached or detached. This choice is based on whether or not we have a media element. If we have a media element, then we go to attach. If we don't have a media element, we go to detach.
Parameters:
Name Type Description
goingTo shaka.routing.Node
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
shaka.routing.Node

(private) getNextMatchingAllDependencies_(destinationNodenon-null, nextNodenon-null, resetNodenon-null, goingTonon-null, has, wants) → {shaka.routing.Node}

A general method used to handle routing when we can either than one step toward our destination (while all our dependencies match) or go to a node that will reset us so we can try again.
Parameters:
Name Type Description
destinationNode shaka.routing.Node What |goingTo| must be for us to step toward |nextNode|. Otherwise we will go to |resetNode|.
nextNode shaka.routing.Node The node we will go to next if |goingTo == destinationNode| and all dependencies match.
resetNode shaka.routing.Node The node we will go to next if |goingTo != destinationNode| or any dependency does not match.
goingTo shaka.routing.Node The node that the walker is trying to go to.
has shaka.routing.Payload The payload that the walker currently has.
wants shaka.routing.Payload The payload that the walker wants to have when iy gets to |goingTo|.
Source:
Returns:
Type
shaka.routing.Node

(private) getNextStep_(currentlyAtnon-null, currentlyWith, wantsToBeAtnon-null, wantsToHave) → (nullable) {shaka.routing.Node}

Key ---------------------- D : Detach Node A : Attach Node MS : Media Source Node P : Manifest Parser Node M : Manifest Node DRM : Drm Engine Node L : Load Node U : Unloading Node SRC : Src Equals Node Graph Topology ---------------------- [SRC]-----+ ^ | | v [D]<-->[A]<-----[U] | ^ v | [MS]------+ | | v | [P]-------+ | | v | [M]-------+ | | v | [DRM]-----+ | | v | [L]-------+
Parameters:
Name Type Description
currentlyAt shaka.routing.Node
currentlyWith shaka.routing.Payload
wantsToBeAt shaka.routing.Node
wantsToHave shaka.routing.Payload
Source:
Returns:
Type
shaka.routing.Node

(export) getPlaybackRate() → {number}

Get the playback rate of what is playing right now. If we are using trick play, this will return the trick play rate. If no content is playing, this will return 0. If content is buffering, this will return 0. If the player has not loaded content, this will return a playback rate of |0|.
Source:
Returns:
Type
number

(export) getPlayheadTimeAsDate() → {Date}

Get the current playhead position as a date. This should only be called when the player has loaded a live stream. If the player has not loaded a live stream, this will return |null|.
Source:
Returns:
Type
Date

(private) getPresentationPeriod_() → {shaka.extern.Period}

Get the period that is on the screen. This will return |null| if nothing is loaded.
Source:
Returns:
Type
shaka.extern.Period

(export) getPresentationStartTimeAsDate() → {Date}

Get the presentation start time as a date. This should only be called when the player has loaded a live stream. If the player has not loaded a live stream, this will return |null|.
Source:
Returns:
Type
Date

(private) getPresentationText_() → (nullable) {shaka.extern.Stream}

Get the text stream that we are either currently presenting to the user or will be presenting will captions are enabled. If we have no text to display, this will return |null|.
Source:
Returns:
Type
shaka.extern.Stream

(private) getPresentationVariant_() → (nullable) {shaka.extern.Variant}

Get the variant that we are currently presenting to the user. If we are not showing anything, then we will return |null|.
Source:
Returns:
Type
shaka.extern.Variant

(private) getSelectableText_() → (non-null) {Array.<shaka.extern.Stream>}

Get the text streams that the user can select. The streams will be based on the period that the playhead is in and what streams have finished loading.
Source:
Returns:
Type
Array.<shaka.extern.Stream>

(private) getSelectableVariants_() → (non-null) {Array.<shaka.extern.Variant>}

Get the variants that the user can select. The variants will be based on the period that the playhead is in and what variants are playable.
Source:
Returns:
Type
Array.<shaka.extern.Variant>

getSharedConfiguration() → {shaka.extern.PlayerConfiguration}

Return a reference to the current configuration. Modifications to the returned value will affect the Player's active configuration. This method is not exported as sharing configuration with external objects is not supported.
Source:
Returns:
Type
shaka.extern.PlayerConfiguration

(export) getStats() → {shaka.extern.Stats}

Get statistics for the current playback session. If the player is not playing content, this will return an empty stats object.
Source:
Returns:
Type
shaka.extern.Stats

(export) getTextLanguages() → (non-null) {Array.<string>}

Return a list of text languages available for the current period. If the player has not loaded any content, this will return an empty list.
Source:
Returns:
Type
Array.<string>

(export) getTextLanguagesAndRoles() → (non-null) {Array.<shaka.extern.LanguageRole>}

Return a list of text language-role combinations available for the current period. If the player has not loaded any content, this will be return an empty list.
Source:
Returns:
Type
Array.<shaka.extern.LanguageRole>

(export) getTextTracks() → (non-null) {Array.<shaka.extern.Track>}

Return a list of text tracks that can be switched to in the current period. If there are multiple periods, you must seek to a period in order to get text tracks from that period. If the player has not loaded content, this will return an empty list.
Source:
Returns:
Type
Array.<shaka.extern.Track>

(export) getVariantTracks() → (non-null) {Array.<shaka.extern.Track>}

Return a list of variant tracks that can be switched to in the current period. If there are multiple periods, you must seek to the period in order to get variants from that period. If the player has not loaded content, this will return an empty list.
Source:
Returns:
Type
Array.<shaka.extern.Track>

(export) isAudioOnly() → {boolean}

Check if the manifest contains only audio-only content. If the player has not loaded content, this will return |false|. The player does not support content that contain more than one type of variants (i.e. mixing audio-only, video-only, audio-video). Content will be filtered to only contain one type of variant.
Source:
Returns:
Type
boolean

(private) isBufferedToEndMS_() → {boolean}

Assuming the player is playing content with media source, check if the player has buffered enough content to make it to the end of the presentation.
Source:
Returns:
Type
boolean

(private) isBufferedToEndSrc_() → {boolean}

Assuming the player is playing content with src=, check if the player has buffered enough content to make it to the end of the presentation.
Source:
Returns:
Type
boolean

(export) isBuffering() → {boolean}

Check if the player is currently in a buffering state (has too little content to play smoothly). If the player has not loaded content, this will return |false|.
Source:
Returns:
Type
boolean

(export) isInProgress() → {boolean}

Get if the player is playing in-progress content. If the player has not loaded content, this will return |false|.
Source:
Returns:
Type
boolean

(export) isLive() → {boolean}

Get if the player is playing live content. If the player has not loaded content, this will return |false|.
Source:
Returns:
Type
boolean

(export) isTextTrackVisible() → {boolean}

Check if the text displayer is enabled.
Source:
Returns:
Type
boolean

(export) keySystem() → {string}

Get the key system currently used by EME. If EME is not being used, this will return an empty string. If the player has not loaded content, this will return an empty string.
Source:
Returns:
Type
string

(export) load(assetUri, startTimeopt, nullable, mimeType) → (non-null) {Promise}

Tell the player to load the content at |assetUri| and start playback at |startTime|. Before calling |load|, a call to |attach| must have succeeded. Calls to |load| will interrupt any in-progress calls to |load| but cannot interrupt calls to |attach|, |detach|, or |unload|.
Parameters:
Name Type Attributes Description
assetUri string
startTime number <optional>
<nullable>
When |startTime| is |null| or |undefined|, playback will start at the default start time (startTime=0 for VOD and startTime=liveEdge for LIVE).
mimeType string | shaka.extern.ManifestParser.Factory
Source:
Returns:
Type
Promise

(private) onAbrStatusChanged_()

Source:

(private) onAdaptation_()

Dispatches an 'adaptation' event.
Source:

(private) onAttach_(has, wants) → (non-null) {Promise}

This should only be called by the load graph when it is time to attach to a media element. The only times this may be called are when we are being asked to re-attach to the current media element, or attach to a new media element while not attached to a media element. This method assumes that it is safe for it to execute, the load-graph is responsible for ensuring all assumptions are true. Attaching to a media element is defined as: - Registering error listeners to the media element. - Caching the video element for use outside of the load graph.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

(private) onChangePeriod_()

Callback from PlayheadObserver.
Source:

(private) onChooseStreams_(periodnon-null) → {shaka.media.StreamingEngine.ChosenStreams}

Callback from StreamingEngine, invoked when a period starts. This method must always "succeed" so it may not throw an error. Any errors must be routed to |onError|.
Parameters:
Name Type Description
period shaka.extern.Period
Source:
Returns:
An object containing the chosen variant and text stream.
Type
shaka.media.StreamingEngine.ChosenStreams

(private) onDetach_(has, wants) → (non-null) {Promise}

This should only be called by the load graph when it is time to detach from a media element. The only times this may be called are when we are being asked to detach from the current media element, or detach when we are already detached. This method assumes that it is safe for it to execute, the load-graph is responsible for ensuring all assumptions are true. Detaching from a media element is defined as: - Removing error listeners from the media element. - Dropping the cached reference to the video element.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

(private) onError_(errornon-null)

Parameters:
Name Type Description
error shaka.util.Error
Source:

(private) onExpirationUpdated_(keyId, expiration)

Callback from DrmEngine
Parameters:
Name Type Description
keyId string
expiration number
Source:

onInitializeDrm_(has, wants) → (non-null) {Promise}

This should only be called by the load graph when it is time to initialize drmEngine. The only time this may be called is when we are attached a media element and have parsed a manifest. The load-graph is responsible for ensuring all assumptions made by this method are valid before executing it.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

(private) onInitializeMediaSourceEngine_(has, wants) → (non-null) {Promise}

This should only be called by the load graph when it is time to initialize media source engine. The only time this may be called is when we are attached to the same media element as in the request. This method assumes that it is safe for it to execute. The load-graph is responsible for ensuring all assumptions are true.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

(private) onInitializeParser_(has, wants) → (non-null) {Promise}

Create the parser for the asset located at |wants.uri|. This should only be called as part of the load graph. This method assumes that it is safe for it to execute, the load-graph is responsible for ensuring all assumptions are true.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

onInitializeSrcEqualsDrm_(has, wants) → (non-null) {Promise}

This should only be called by the load graph when it is time to initialize drmEngine for src= playbacks. The load-graph is responsible for ensuring all assumptions made by this method are valid before executing it.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

(private) onKeyStatus_(keyStatusMapnon-null)

Parameters:
Name Type Description
keyStatusMap Object.<string, string> A map of hex key IDs to statuses.
Source:

(private) onLoad_(has, wants)

This should only be called by the load graph when it is time to load all playback components needed for playback. The only times this may be called is when we are attached to the same media element as in the request. This method assumes that it is safe for it to execute, the load-graph is responsible for ensuring all assumptions are true. Loading is defined as: - Attaching all playback-related listeners to the media element - Initializing playback and observers - Initializing ABR Manager - Initializing Streaming Engine - Starting playback at |wants.startTime|
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:

(private) onManifestUpdate_()

Callback from StreamingEngine.
Source:

(private) onParseManifest_(has, wants) → (non-null) {shaka.util.AbortableOperation}

Parse the manifest at |has.uri| using the parser that should have already been created. This should only be called as part of the load graph. This method assumes that it is safe for it to execute, the load-graph is responsible for ensuring all assumptions are true.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
shaka.util.AbortableOperation

(private) onRateChange_()

A callback for when the playback rate changes. We need to watch the playback rate so that if the playback rate on the media element changes (that was not caused by our play rate controller) we can notify the controller so that it can stay in-sync with the change.
Source:

(private) onRegionEvent_(eventName, region)

When we fire region events, we need to copy the information out of the region to break the connection with the player's internal data. We do the copy here because this is the transition point between the player and the app.
Parameters:
Name Type Description
eventName string
region shaka.extern.TimelineRegionInfo
Source:

(private) onSeek_()

Callback from Playhead.
Source:

(private) onSegmentAppended_()

Callback from StreamingEngine.
Source:

(private) onSrcEquals_(has, wants) → (non-null) {shaka.util.AbortableOperation}

This should only be called by the load graph when it is time to set-up the media element to play content using src=. The only times this may be called is when we are attached to the same media element as in the request. This method assumes that it is safe for it to execute, the load-graph is responsible for ensuring all assumptions are true.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
shaka.util.AbortableOperation

(private) onTextChanged_()

Dispatches a 'textchanged' event.
Source:

(private) onTextTrackVisibility_()

Source:

(private) onTracksChanged_()

Dispatches a 'trackschanged' event.
Source:

(private) onUnload_(has, wants) → (non-null) {Promise}

This should only be called by the load graph when it is time to unload all currently initialized playback components. Unlike the other load actions, this action is built to be more general. We need to do this because we don't know what state the player will be in before unloading (including after an error occurred in the middle of a transition). This method assumes that any component could be |null| and should be safe to call from any point in the load graph.
Parameters:
Name Type Description
has shaka.routing.Payload
wants shaka.routing.Payload
Source:
Returns:
Type
Promise

(private) onVariantChanged_()

Dispatches a 'variantchanged' event.
Source:

(private) onVideoError_(eventnon-null)

Parameters:
Name Type Description
event Event
Source:

(private) pollBufferState_()

This method is called periodically to check what the buffering observer says so that we can update the rest of the buffering behaviours.
Source:

(export) removeEventListener(type, listener, optionsopt)

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.
options EventListenerOptions | boolean <optional>
Ignored.
Inherited From:
Source:

(export) resetConfiguration()

Reset configuration to default.
Source:

(export) retryStreaming() → {boolean}

Retry streaming after a streaming failure has occurred. When the player has not loaded content or is loading content, this will be a no-op and will return |false|. If the player has loaded content, and streaming has not seen an error, this will return |false|. if the player has loaded content, and streaming seen an error, but the could not resume streaming, this will return |false|.
Source:
Returns:
Type
boolean

(export) seekRange() → {{start: number, end: number}}

Get the range of time (in seconds) that seeking is allowed. If the player has not loaded content, this will return a range from 0 to 0.
Source:
Returns:
Type
{start: number, end: number}

(export) selectAudioLanguage(language, roleopt)

Sets currentAudioLanguage and currentVariantRole to the selected language and role, and chooses a new variant if need be. If the player has not loaded any content, this will be a no-op.
Parameters:
Name Type Attributes Description
language string
role string <optional>
Source:

(export) selectEmbeddedTextTrack()

Find the CEA 608/708 text stream embedded in video, and switch to it.
Deprecated:
  • Yes
Source:

(export) selectTextLanguage(language, roleopt)

Sets currentTextLanguage and currentTextRole to the selected language and role, and chooses a new variant if need be. If the player has not loaded any content, this will be a no-op.
Parameters:
Name Type Attributes Description
language string
role string <optional>
Source:

(export) selectTextTrack(track)

Select a specific text track from the current period. |track| should come from a call to |getTextTracks|. If the track is not found in the current period, this will be a no-op. If the player has not loaded content, this will be a no-op. Note that AdaptationEvents are not fired for manual track selections.
Parameters:
Name Type Description
track shaka.extern.Track
Source:

(export) selectVariantsByLabel(label)

Select variant tracks that have a given label. This assumes the label uniquely identifies an audio stream, so all the variants are expected to have the same variant.audio.
Parameters:
Name Type Description
label string
Source:

(export) selectVariantTrack(track, clearBufferopt, safeMarginopt)

Select a specific variant track to play from the current period. |track| should come from a call to |getVariantTracks|. If |track| cannot be found in the current variant, this will be a no-op. If the player has not loaded content, this will be a no-op. Changing variants will take effect once the currently buffered content has been played. To force the change to happen sooner, use |clearBuffer| with |safeMargin|. Setting |clearBuffer| to |true| will clear all buffered content after |safeMargin|, allowing the new variant to start playing sooner. Note that AdaptationEvents are not fired for manual track selections.
Parameters:
Name Type Attributes Description
track shaka.extern.Track
clearBuffer boolean <optional>
safeMargin number <optional>
Optional amount of buffer (in seconds) to retain when clearing the buffer. Useful for switching variant quickly without causing a buffering event. Defaults to 0 if not provided. Ignored if clearBuffer is false. Can cause hiccups on some browsers if chosen too small, e.g. The amount of two segments is a fair minimum to consider as safeMargin value.
Source:

(export) setMaxHardwareResolution(width, height)

Set the maximum resolution that the platform's hardware can handle. This will be called automatically by shaka.cast.CastReceiver to enforce limitations of the Chromecast hardware.
Parameters:
Name Type Description
width number
height number
Source:

(export) setTextTrackVisibility(isVisible) → (non-null) {Promise}

Enable or disable the text displayer. If the player is in an unloaded state, the request will be applied next time content is loaded.
Parameters:
Name Type Description
isVisible boolean
Source:
Returns:
Type
Promise

(private) setupPreferredAudioOnSrc_()

This method setup the preferred audio using src=..
Source:

(private) setupPreferredTextOnSrc_()

This method setup the preferred text using src=.
Source:

(private) shouldShowText_(audioStream, textStream) → {boolean}

Check if we should show text on screen automatically. The text should automatically be shown if the text is language-compatible with the user's text language preference, but not compatible with the audio. For example: preferred | chosen | chosen | text | text | audio | show ----------------------------------- en-CA | en | jp | true en | en-US | fr | true fr-CA | en-US | jp | false en-CA | en-US | en-US | false
Parameters:
Name Type Description
audioStream shaka.extern.Stream
textStream shaka.extern.Stream
Source:
Returns:
Type
boolean

(private) shouldStreamText_() → {boolean}

Source:
Returns:
true if we should stream text right now.
Type
boolean

(private) shouldUseSrcEquals_(payload) → {boolean}

Check if src= should be used to load the asset at |uri|. Assume that media source is the default option, and that src= is for special cases.
Parameters:
Name Type Description
payload shaka.routing.Payload
Source:
Returns:
|true| if the content should be loaded with src=, |false| if the content should be loaded with MediaSource.
Type
boolean

startBufferManagement_(rebufferingGoal)

Initialize and start the buffering system (observer and timer) so that we can monitor our buffer lead during playback.
Parameters:
Name Type Description
rebufferingGoal number
Source:

(private) switch_(variant, clearBufferopt, safeMarginopt)

Callback from AbrManager.
Parameters:
Name Type Attributes Description
variant shaka.extern.Variant
clearBuffer boolean <optional>
safeMargin number <optional>
Optional amount of buffer (in seconds) to retain when clearing the buffer. Defaults to 0 if not provided. Ignored if clearBuffer is false.
Source:

(private) switchTextStream_(textStream) → {boolean}

Switches to the given text stream, deferring if needed.
Parameters:
Name Type Description
textStream shaka.extern.Stream
Source:
Returns:
Type
boolean

(private) switchVariant_(variant, clearBufferopt, safeMarginopt) → {boolean}

Switches to the given variant, deferring if needed.
Parameters:
Name Type Attributes Description
variant shaka.extern.Variant
clearBuffer boolean <optional>
safeMargin number <optional>
Source:
Returns:
Type
boolean

(export) trickPlay(rate)

Enable trick play to skip through content without playing by repeatedly seeking. For example, a rate of 2.5 would result in 2.5 seconds of content being skipped every second. A negative rate will result in moving backwards. If the player has not loaded content or is still loading content this will be a no-op. Wait until |load| has completed before calling. Trick play will be canceled automatically if the playhead hits the beginning or end of the seekable range for the content.
Parameters:
Name Type Description
rate number
Source:

(export) unload(initializeMediaSourceopt) → (non-null) {Promise}

Tell the player to either return to: - detached (when it does not have a media element), - attached (when it has a media element and |initializedMediaSource=false|) - media source initialized (when it has a media element and |initializedMediaSource=true|) Calls to |unload| will interrupt any in-progress calls to |load| but cannot interrupt calls to |attach|, |detach|, or |unload|.
Parameters:
Name Type Attributes Description
initializeMediaSource boolean <optional>
Source:
Returns:
Type
Promise

(private) updateBufferingSettings_(rebufferingGoal)

Updates the buffering thresholds based on the new rebuffering goal.
Parameters:
Name Type Description
rebufferingGoal number
Source:

(private) updateBufferState_()

Update the buffering state to be either "we are buffering" or "we are not buffering", firing events to the app as needed.
Source:

(private) updateStateHistory_()

Try updating the state history. If the player has not finished initializing, this will be a no-op.
Source:

(export) usingEmbeddedTextTrack() → {boolean}

Deprecated:
  • Yes
Source:
Returns:
True if we are using any embedded text tracks present.
Type
boolean

(private) videoErrorToShakaError_() → {shaka.util.Error}

Turn the media element's error object into a Shaka Player error object.
Source:
Returns:
Type
shaka.util.Error

(private) wrapWalkerListenersWithPromise_(listeners) → (non-null) {Promise}

Using a promise, wrap the listeners returned by |Walker.startNewRoute|. This will work for most usages in |Player| but should not be used for special cases. This will connect |onCancel|, |onEnd|, |onError|, and |onSkip| with |resolve| and |reject| but will leave |onStart| unset.
Parameters:
Name Type Description
listeners shaka.routing.Walker.Listeners
Source:
Returns:
Type
Promise

Events

AbrStatusChangedEvent

Fired when the state of abr has been changed. (Enabled or disabled).
Properties:
Name Type Description
type string 'abrstatuschanged'
newStatus boolean The new status of the application. True for 'is enabled' and false otherwise.
Source:

AdaptationEvent

Fired when an automatic adaptation causes the active tracks to change. Does not fire when the application calls selectVariantTrack() selectTextTrack(), selectAudioLanguage() or selectTextLanguage().
Properties:
Name Type Description
type string 'adaptation'
Source:

BufferingEvent

Fired when the player's buffering state changes.
Properties:
Name Type Description
type string 'buffering'
buffering boolean True when the Player enters the buffering state. False when the Player leaves the buffering state.
Source:

DrmSessionUpdateEvent

Fired when the CDM has accepted the license response.
Properties:
Name Type Description
type string 'drmsessionupdate'
Source:

EmsgEvent

Fired when a non-typical emsg is found in a segment.
Properties:
Name Type Description
type string 'emsg'
detail shaka.extern.EmsgInfo An object which contains the content of the emsg box.
Source:

ErrorEvent

Fired when a playback error occurs.
Properties:
Name Type Description
type string 'error'
detail shaka.util.Error An object which contains details on the error. The error's 'category' and 'code' properties will identify the specific error that occurred. In an uncompiled build, you can also use the 'message' and 'stack' properties to debug.
Source:

ExpirationUpdatedEvent

Fired when there is a change in the expiration times of an EME session.
Properties:
Name Type Description
type string 'expirationupdated'
Source:

LargeGapEvent

Fired when the playhead enters a large gap. If |config.streaming.jumpLargeGaps| is set, the default action of this event is to jump the gap; this can be prevented by calling preventDefault() on the event object.
Properties:
Name Type Description
type string 'largegap'
currentTime number The current time of the playhead.
gapSize number The size of the gap, in seconds.
Source:

LoadedEvent

Fired when the player ends the load.
Properties:
Name Type Description
type string 'loaded'
Source:

LoadingEvent

Fired when the player begins loading. The start of loading is defined as when the user has communicated intent to load content (i.e. Player.load has been called).
Properties:
Name Type Description
type string 'loading'
Source:

ManifestParsedEvent

Fired after the manifest has been parsed, but before anything else happens. The manifest may contain streams that will be filtered out, at this stage of the loading process.
Properties:
Name Type Description
type string 'manifestparsed'
Source:

StateChangeEvent

Fired when the player changes load states.
Properties:
Name Type Description
type string 'onstatechange'
state string The name of the state that the player just entered.
Source:

StateIdleEvent

Fired when the player has stopped changing states and will remain idle until a new state change request (e.g. load, attach, etc.) is made.
Properties:
Name Type Description
type string 'onstateidle'
state string The name of the state that the player stopped in.
Source:

StreamingEvent

Fired after the manifest has been parsed and track information is available, but before streams have been chosen and before any segments have been fetched. You may use this event to configure the player based on information found in the manifest.
Properties:
Name Type Description
type string 'streaming'
Source:

TextChangedEvent

Fired when a call from the application caused a text stream change. Can be triggered by calls to selectTextTrack() or selectTextLanguage().
Properties:
Name Type Description
type string 'textchanged'
Source:

TextTrackVisibilityEvent

Fired when text track visibility changes.
Properties:
Name Type Description
type string 'texttrackvisibility'
Source:

TimelineRegionAddedEvent

Fired when a media timeline region is added.
Properties:
Name Type Description
type string 'timelineregionadded'
detail shaka.extern.TimelineRegionInfo An object which contains a description of the region.
Source:

TimelineRegionEnterEvent

Fired when the playhead enters a timeline region.
Properties:
Name Type Description
type string 'timelineregionenter'
detail shaka.extern.TimelineRegionInfo An object which contains a description of the region.
Source:

TimelineRegionExitEvent

Fired when the playhead exits a timeline region.
Properties:
Name Type Description
type string 'timelineregionexit'
detail shaka.extern.TimelineRegionInfo An object which contains a description of the region.
Source:

TracksChangedEvent

Fired when the list of tracks changes. For example, this will happen when changing periods or when track restrictions change.
Properties:
Name Type Description
type string 'trackschanged'
Source:

UnloadingEvent

Fired when the player unloads or fails to load. Used by the Cast receiver to determine idle state.
Properties:
Name Type Description
type string 'unloading'
Source:

VariantChangedEvent

Fired when a call from the application caused a variant change. Can be triggered by calls to selectVariantTrack() or selectAudioLanguage(). Does not fire when an automatic adaptation causes a variant change.
Properties:
Name Type Description
type string 'variantchanged'
Source: