Class: shaka.Player

The main player object for Shaka Player.

Constructor

new Player(mediaElementopt, dependencyInjectoropt)

The main player object for Shaka 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 <optional>
Optional callback which is called to inject mocks into the Player. Used for testing.
Implements:
Source:

Members

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:

supportPlugins_ :Object.<string, function(): *>

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

TextTrackLabel :string

Type:
  • string
Source:

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:

version :string

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

abrManagerFactory_ :shaka.extern.AbrManager.Factory

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

assetUri_ :string

Type:
  • string
Source:

attachEventManager_ :shaka.util.EventManager

For listeners scoped to the lifetime of the media element attachment.
Type:
Source:

checkVariantsTimer_ :shaka.util.Timer

Type:
Source:

cleanupOnUnload_ :Array.<function(): (!Promise|undefined)>

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

completionPercent_ :number

Type:
  • number
Source:

currentTextForced_ :boolean

Type:
  • boolean
Source:

currentTextLanguage_ :string

Type:
  • string
Source:

currentTextRole_ :string

Type:
  • string
Source:

externalSrcEqualsThumbnailsStreams_ :Array.<shaka.extern.Stream>

Type:
Source:

fullyLoaded_ :boolean

Type:
  • boolean
Source:

globalEventManager_ :shaka.util.EventManager

For listeners scoped to the lifetime of the Player instance.
Type:
Source:

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:

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:

lcevcCanvas_ :HTMLCanvasElement

Type:
  • HTMLCanvasElement
Source:

loadEventManager_ :shaka.util.EventManager

For listeners scoped to the lifetime of the loaded content.
Type:
Source:

maxHwRes_ :{width: number, height: number}

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

mimeType_ :string

Type:
  • string
Source:

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:

operationId_ :number

Incremented whenever a top-level operation (load, attach, etc) is performed. Used to determine if a load operation has been interrupted.
Type:
  • number
Source:

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:

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:

startTime_ :number

Type:
  • number
Source:

trickPlayEventManager_ :shaka.util.EventManager

For listeners scoped to the lifetime of the loaded content.
Type:
Source:

video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

videoContainer_ :HTMLElement

Type:
  • HTMLElement
Source:

Methods

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:

getLanguageAndRolesFrom_(tracksnon-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>

getLanguagesFrom_(tracksnon-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>

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

makeEvent_(namenon-null, dataopt) → {shaka.util.FakeEvent}

Parameters:
Name Type Attributes Description
name shaka.util.FakeEvent.EventName
data Map.<string, Object> <optional>
Source:
Returns:
Type
shaka.util.FakeEvent

probeSupport(promptsOkayopt) → {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.

Parameters:
Name Type Attributes Default Description
promptsOkay boolean <optional>
true
Source:
See:
Returns:
Type
Promise.<shaka.extern.SupportType>

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:

setAdManagerFactory(factorynon-null)

Set a factory to create an ad manager during player construction time. This method needs to be called bafore instantiating the Player class.
Parameters:
Name Type Description
factory shaka.extern.IAdManager.Factory
Source:

activateChaptersTrack_(tracknullable)

Set the mode on a chapters track so that it loads.
Parameters:
Name Type Attributes Description
track TextTrack <nullable>
Source:

addChaptersTrack(uri, language, mimeTypeopt) → {Promise.<shaka.extern.Track>}

Adds the given chapters track to the loaded manifest. load() must resolve before calling. The presentation must have a duration. This returns the created track.
Parameters:
Name Type Attributes Description
uri string
language string
mimeType string <optional>
Source:
Returns:
Type
Promise.<shaka.extern.Track>

addSrcTrackElement_(uri, language, kind, mimeType, label, adCuePointsnon-null) → {Promise.<!HTMLTrackElement>}

Parameters:
Name Type Description
uri string
language string
kind string
mimeType string
label string
adCuePoints Array.<!shaka.extern.AdCuePoint>
Source:
Returns:
Type
Promise.<!HTMLTrackElement>

addTextStreamToSwitchHistory_(textStream, fromAdaptation)

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

addTextTrackAsync(uri, language, kind, mimeTypeopt, codecopt, labelopt, forcedopt) → {Promise.<shaka.extern.Track>}

Adds the given text track to the loaded manifest. load() must resolve before calling. The presentation must have a duration. This returns the created track, which can immediately be selected by the application. The track will not be automatically selected.
Parameters:
Name Type Attributes Default Description
uri string
language string
kind string
mimeType string <optional>
codec string <optional>
label string <optional>
forced boolean <optional>
false
Source:
Returns:
Type
Promise.<shaka.extern.Track>

addThumbnailsTrack(uri, mimeTypeopt) → {Promise.<shaka.extern.Track>}

Adds the given thumbnails track to the loaded manifest. load() must resolve before calling. The presentation must have a duration. This returns the created track, which can immediately be used by the application.
Parameters:
Name Type Attributes Description
uri string
mimeType string <optional>
Source:
Returns:
Type
Promise.<shaka.extern.Track>

addVariantToSwitchHistory_(variant, fromAdaptation)

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

adjustStartTime_(initialVariant, time) → {Promise.<number>}

Parameters:
Name Type Description
initialVariant shaka.extern.Variant
time number
Source:
Returns:
Type
Promise.<number>

applyConfig_()

Apply config changes.
Source:

atomicOperationAcquireMutex_(mutexIdentifier) → {Promise.<boolean>}

Tries to acquire the mutex, and then returns if the operation should end early due to someone else starting a mutex-acquiring operation. Meant for operations that can't be interrupted midway through (e.g. everything but load).
Parameters:
Name Type Description
mutexIdentifier string
Source:
Returns:
endEarly If false, the calling context will need to release the mutex.
Type
Promise.<boolean>

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

Attaches the player to a media element. If the player was already attached to a media element, first detaches from that media element.
Parameters:
Name Type Attributes Default Description
mediaElement HTMLMediaElement
initializeMediaSource boolean <optional>
true
Source:
Returns:
Type
Promise

attachCanvas(canvas)

Calling attachCanvas will tell the player to set canvas element for LCEVC decoding.
Parameters:
Name Type Description
canvas HTMLCanvasElement
Source:

cancelTrickPlay()

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

checkVariants_()

Checks to re-enable variants that were temporarily disabled due to network errors. If any variants are enabled this way, a new variant may be chosen for playback.
Source:

chooseTextStream_() → {shaka.extern.Stream}

Choose a text stream from all possible text streams while taking into account user preference.
Source:
Returns:
Type
shaka.extern.Stream

chooseVariant_(initialSelectionopt) → {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 Attributes Default Description
initialSelection boolean <optional>
false
Source:
Returns:
Type
shaka.extern.Variant

chooseVariantAndSwitch_(clearBufferopt, safeMarginopt)

Chooses a new Variant. If the new variant differs from the old one, it adds the new one to the switch history and switches to it. Called after a config change, a key status event, or an explicit language change.
Parameters:
Name Type Attributes Default Description
clearBuffer boolean <optional>
true Optional clear buffer or not when switch to new variant Defaults to true if not provided
safeMargin number <optional>
0 Optional amount of buffer (in seconds) to retain when clearing the buffer. Defaults to 0 if not provided. Ignored if clearBuffer is false.
Source:

closeLcevcDec_()

Close a shaka.lcevc.Dec object if present and hide the canvas.
Source:

configure(config, valueopt) → {boolean}

Changes configuration settings on the Player. This checks the names of keys and the types of values to avoid coding errors. If there are errors, this logs them to the console and returns false. Correct fields are still applied even if there are other errors. You can pass an explicit undefined value to restore the default value. This has two modes of operation:

First, this can be passed a single "plain" object. This object should follow the shaka.extern.PlayerConfiguration object. Not all fields need to be set; unset fields retain their old values.

Second, this can be passed two arguments. The first is the name of the key to set. This should be a '.' separated path to the key. For example, 'streaming.alwaysStreamText'. The second argument is the value to set.

Parameters:
Name Type Attributes Description
config string | Object This should either be a field name or an object.
value * <optional>
In the second mode, this is the value to set.
Source:
Returns:
True if the passed config object was valid, false if there were invalid entries.
Type
boolean

convertToWebVTT_(buffer, mimeType, adCuePointsnon-null) → {string}

Converts an input string to a WebVTT format string.
Parameters:
Name Type Description
buffer BufferSource
mimeType string
adCuePoints Array.<!shaka.extern.AdCuePoint>
Source:
Returns:
Type
string

createAbortLoadError_() → {shaka.util.Error}

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

createCmcd_()

Create a new CMCD manager.
Source:

createCmsd_()

Create a new CMSD manager.
Source:

createDrmEngine(playerInterface) → {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

createLcevcDec_(config)

Create a shaka.lcevc.Dec object
Parameters:
Name Type Description
config shaka.extern.LcevcConfiguration
Source:

createMediaSourceEngine(mediaElementnon-null, textDisplayernon-null, onMetadatanon-null, lcevcDec) → {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
textDisplayer shaka.extern.TextDisplayer
onMetadata !function(!Array.<shaka.extern.ID3Metadata>, number, ?number)
lcevcDec shaka.lcevc.Dec
Source:
Returns:
Type
shaka.media.MediaSourceEngine

createNetworkingEngine(getPreloadManageropt) → {shaka.net.NetworkingEngine}

Creates a new instance of NetworkingEngine. This can be replaced by tests to create fake instances instead.
Parameters:
Name Type Attributes Description
getPreloadManager function <optional>
Source:
Returns:
Type
shaka.net.NetworkingEngine

createPlayhead(startTimenullable) → {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

createPlayheadObserversForMSE_(startTimeOfLoad) → {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.
Parameters:
Name Type Description
startTimeOfLoad number
Source:
Returns:
Type
shaka.media.PlayheadObserverManager

createStreamingEngine() → {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

defaultStreamingFailureCallback_(errornon-null)

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

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:

destroy() → {Promise}

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

detach(keepAdManageropt) → {Promise}

Detach the player from the current media element. Leaves the player in a state where it cannot play media, until it has been attached to something else.
Parameters:
Name Type Attributes Default Description
keepAdManager boolean <optional>
false
Source:
Returns:
Type
Promise

disableStream(stream, disableTime) → {boolean}

Temporarily disable all variants containing |stream|
Parameters:
Name Type Description
stream shaka.extern.Stream
disableTime number
Source:
Returns:
Type
boolean

dispatchMetadataEvent_(startTime, endTimenullable, metadataType, payload)

Construct and fire a Player.Metadata event
Parameters:
Name Type Attributes Description
startTime number
endTime number <nullable>
metadataType string
payload shaka.extern.MetadataFrame
Source:

drmInfo() → {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

getActiveSessionsMetadata() → {Array.<shaka.extern.DrmSessionMetadata>}

Returns the active sessions metadata
Source:
Returns:
Type
Array.<shaka.extern.DrmSessionMetadata>

getAdManager() → {shaka.extern.IAdManager}

Returns a shaka.ads.AdManager instance, responsible for Dynamic Ad Insertion functionality.
Source:
Returns:
Type
shaka.extern.IAdManager

getAllThumbnails(trackId) → {Promise.<?Array.<!shaka.extern.Thumbnail>>}

Returns Thumbnail objects for each thumbnail for a given image track ID. If the player has not loaded content, this will return a null.
Parameters:
Name Type Description
trackId number
Source:
Returns:
Type
Promise.<?Array.<!shaka.extern.Thumbnail>>

getAssetUri() → {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

getAudioLanguages() → {Array.<string>}

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

getAudioLanguagesAndRoles() → {Array.<shaka.extern.LanguageRole>}

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

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

getBufferFullness() → {number}

Returns the ratio of video length buffered compared to buffering Goal
Source:
Returns:
Type
number

getChapters(language) → {Array.<shaka.extern.Chapter>}

This returns the list of chapters.
Parameters:
Name Type Description
language string
Source:
Returns:
Type
Array.<shaka.extern.Chapter>

getChaptersTracks() → {Array.<shaka.extern.Track>}

Return a list of chapters tracks.
Source:
Returns:
Type
Array.<shaka.extern.Track>

getChaptersTracks_() → {Array.<TextTrack>}

Get the TextTracks with the 'chapters' kind.
Source:
Returns:
Type
Array.<TextTrack>

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

getDrmEngine() → {shaka.media.DrmEngine}

Get the drm engine. This method should only be used for testing. Applications SHOULD NOT use this in production.
Source:
Returns:
Type
shaka.media.DrmEngine

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

getFilteredTextTracks_() → {Array.<TextTrack>}

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

getImageTracks() → {Array.<shaka.extern.Track>}

Return a list of image tracks that can be switched to. If the player has not loaded content, this will return an empty list.
Source:
Returns:
Type
Array.<shaka.extern.Track>

getKeyStatuses() → {Object.<string, string>}

Gets a map of EME key ID to the current key status.
Source:
Returns:
Type
Object.<string, string>

getLoadMode() → {shaka.Player.LoadMode}

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

getManifest() → {shaka.extern.Manifest}

Get the manifest that the player has loaded. If the player has not loaded any content, this will return null. NOTE: This structure is NOT covered by semantic versioning compatibility guarantees. It may change at any time! This is marked as deprecated to warn Closure Compiler users at compile-time to avoid using this method.
Deprecated:
  • Yes
Source:
Returns:
Type
shaka.extern.Manifest

getManifestParserFactory() → {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

getManifestType() → {string}

Get the current manifest type.
Source:
Returns:
Type
string

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

getMetadataTracks_() → {Array.<TextTrack>}

Get the TextTracks with the 'metadata' kind.
Source:
Returns:
Type
Array.<TextTrack>

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

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 the expected playback rate once the video starts playing.

If the player has not loaded content, this will return a playback rate of 0.

Source:
Returns:
Type
number

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

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

getSegmentAvailabilityDuration() → {number}

Get the presentation segment availability duration. 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
number

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

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

getTextData_(uri, netEnginenon-null, retryParams) → {Promise.<BufferSource>}

Parameters:
Name Type Description
uri string
netEngine shaka.net.NetworkingEngine
retryParams shaka.extern.RetryParameters
Source:
Returns:
Type
Promise.<BufferSource>

getTextLanguages() → {Array.<string>}

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

getTextLanguagesAndRoles() → {Array.<shaka.extern.LanguageRole>}

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

getTextMimetype_(uri) → {Promise.<string>}

Parameters:
Name Type Description
uri string
Source:
Returns:
Type
Promise.<string>

getTextTracks() → {Array.<shaka.extern.Track>}

Return a list of text tracks that can be switched to.

If the player has not loaded content, this will return an empty list.

Source:
Returns:
Type
Array.<shaka.extern.Track>

getThumbnails(trackId, time) → {Promise.<?shaka.extern.Thumbnail>}

Return a Thumbnail object from a image track Id and time. If the player has not loaded content, this will return a null.
Parameters:
Name Type Description
trackId number
time number
Source:
Returns:
Type
Promise.<?shaka.extern.Thumbnail>

getVariantTracks() → {Array.<shaka.extern.Track>}

Return a list of variant tracks that can be switched to.

If the player has not loaded content, this will return an empty list.

Source:
Returns:
Type
Array.<shaka.extern.Track>

goToLive()

Go to live in a live stream.
Source:

guessMimeType_(assetUri) → {Promise.<?string>}

Determines the mimeType of the given asset, if we are not told that inside the loading process.
Parameters:
Name Type Description
assetUri string
Source:
Returns:
mimeType
Type
Promise.<?string>

initializeMediaSourceEngineInner_() → {Promise}

Initializes the media source engine.
Source:
Returns:
Type
Promise

initializeSrcEqualsDrmInner_(mimeType) → {Promise}

Initializes the DRM engine for use by src equals.
Parameters:
Name Type Description
mimeType string
Source:
Returns:
Type
Promise

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

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

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

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

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

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

isTextTrackVisible() → {boolean}

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

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

load(assetUriOrPreloader, startTimeopt, nullable, mimeTypeopt, nullable) → {Promise}

Loads a new stream. If another stream was already playing, first unloads that stream.
Parameters:
Name Type Attributes Default Description
assetUriOrPreloader string | shaka.media.PreloadManager
startTime number <optional>
<nullable>
null When startTime is null or undefined, playback will start at the default start time (0 for VOD and liveEdge for LIVE).
mimeType string <optional>
<nullable>
Source:
Returns:
Type
Promise

loadInner_(startTimeOfLoad, prefetchedVariantnullable, segmentPrefetchByIdnon-null) → {Promise}

Starts loading the content described by the parsed manifest.
Parameters:
Name Type Attributes Description
startTimeOfLoad number
prefetchedVariant shaka.extern.Variant <nullable>
segmentPrefetchById Map.<number, shaka.media.SegmentPrefetch>
Source:
Returns:
Type
Promise

makeManifestAudioOnly_()

Modifies the current manifest so that it is audio-only.
Source:

makePreloadManager_(assetUri, startTimenullable, mimeTypenullable, startTimeOfLoad, allowPrefetchopt, disableVideoopt, allowMakeAbrManageropt) → {Promise.<!shaka.media.PreloadManager>}

Parameters:
Name Type Attributes Default Description
assetUri string
startTime number <nullable>
mimeType string <nullable>
startTimeOfLoad number
allowPrefetch boolean <optional>
true
disableVideo boolean <optional>
false
allowMakeAbrManager boolean <optional>
true
Source:
Returns:
Type
Promise.<!shaka.media.PreloadManager>

makeStateChangeEvent_(nodeName)

Makes a fires an event corresponding to entering a state of the loading process.
Parameters:
Name Type Description
nodeName string
Source:

makeTextStreamsForClosedCaptions_(manifestnon-null)

For CEA closed captions embedded in the video streams, create dummy text stream. This can be safely called again on existing manifests, for manifest updates.
Parameters:
Name Type Description
manifest shaka.extern.Manifest
Source:

onAbrStatusChanged_()

Source:

onAdaptation_(fromnullable, to)

Dispatches an 'adaptation' event.
Parameters:
Name Type Attributes Description
from shaka.extern.Track <nullable>
to shaka.extern.Track
Source:

onError_(errornon-null)

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

onKeyStatus_(keyStatusMapnon-null)

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

onManifestUpdate_()

Callback from StreamingEngine.
Source:

onMediaQualityChange_(mediaQuality, position)

When notified of a media quality change we need to emit a MediaQualityChange event to the app.
Parameters:
Name Type Description
mediaQuality shaka.extern.MediaQualityInfo
position number
Source:

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:

onRegionEvent_(eventNamenon-null, region, eventTargetopt)

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 Attributes Description
eventName shaka.util.FakeEvent.EventName
region shaka.extern.TimelineRegionInfo
eventTarget shaka.util.FakeEventTarget <optional>
Source:

onSeek_()

Callback from Playhead.
Source:

onSegmentAppended_()

Callback from StreamingEngine.
Source:

onTextChanged_()

Dispatches a 'textchanged' event.
Source:

onTextTrackVisibility_()

Source:

onTimeUpdate_()

Callback for liveSync and vodDynamicPlaybackRate
Source:

onTracksChanged_()

Dispatches a 'trackschanged' event.
Source:

onVariantChanged_(fromnullable, to)

Dispatches a 'variantchanged' event.
Parameters:
Name Type Attributes Description
from shaka.extern.Track <nullable>
to shaka.extern.Track
Source:

onVideoError_(eventnon-null)

Parameters:
Name Type Description
event Event
Source:

onVideoProgress_()

Callback for video progress events
Source:

parseTilesLayout_(tilesLayout) → {?{ columns: number, rows: number}}

Parses a tiles layout.
Parameters:
Name Type Description
tilesLayout string | undefined
Source:
Returns:
Type
?{ columns: number, rows: number}

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:

preload(assetUri, startTimeopt, nullable, mimeTypeopt, nullable) → {Promise.<?shaka.media.PreloadManager>}

Starts to preload a given asset, and returns a PreloadManager object that represents that preloading process. The PreloadManager will load the manifest for that asset, as well as the initialization segment. It will not preload anything more than that; this feature is intended for reducing start-time latency, not for fully downloading assets before playing them (for that, use |shaka.offline.Storage|). You can pass that PreloadManager object in to the |load| method on this Player instance to finish loading that particular asset, or you can call the |destroy| method on the manager if the preload is no longer necessary. If this returns null rather than a PreloadManager, that indicates that the asset must be played with src=, which cannot be preloaded.
Parameters:
Name Type Attributes Default Description
assetUri string
startTime number <optional>
<nullable>
null When startTime is null or undefined, playback will start at the default start time (0 for VOD and liveEdge for LIVE).
mimeType string <optional>
<nullable>
Source:
Returns:
Type
Promise.<?shaka.media.PreloadManager>

preloadInner_(assetUri, startTimenullable, mimeTypeopt, nullable, standardLoadopt) → {Promise.<?shaka.media.PreloadManager>}

Parameters:
Name Type Attributes Default Description
assetUri string
startTime number <nullable>
mimeType string <optional>
<nullable>
standardLoad boolean <optional>
false
Source:
Returns:
Type
Promise.<?shaka.media.PreloadManager>

processTimedMetadataMediaSrc_(metadatanon-null, offset, segmentEndTimenullable)

Parameters:
Name Type Attributes Description
metadata Array.<shaka.extern.ID3Metadata>
offset number
segmentEndTime number <nullable>
Source:

processTimedMetadataSrcEqls_(tracknon-null)

We're looking for metadata tracks to process id3 tags. One of the uses is for ad info on LIVE streams
Parameters:
Name Type Description
track TextTrack
Source:

releaseAllMutexes()

Releases all of the mutexes of the player. Meant for use by the tests.
Source:

resetConfiguration()

Reset configuration to default.
Source:

restoreDisabledVariants_(updateAbrManager)

Parameters:
Name Type Default Description
updateAbrManager boolean true
Source:

retryStreaming(retryDelaySecondsopt) → {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.

Parameters:
Name Type Attributes Default Description
retryDelaySeconds number <optional>
0.1
Source:
Returns:
Type
boolean

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

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

selectAudioLanguage(language, roleopt, channelsCountopt, safeMarginopt)

Sets the current audio language and current variant role to the selected language, role and channel count, 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 Default Description
language string
role string <optional>
channelsCount number <optional>
0
safeMargin number <optional>
0
Source:

selectTextLanguage(language, roleopt, forcedopt)

Sets the current text language and current text role 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 Default Description
language string
role string <optional>
forced boolean <optional>
false
Source:

selectTextTrack(track)

Select a specific text track. track should come from a call to getTextTracks. If the track is not found, 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:

selectVariantsByLabel(label, clearBufferopt, safeMarginopt)

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 Attributes Default Description
label string
clearBuffer boolean <optional>
true Optional clear buffer or not when switch to new variant Defaults to true if not provided
safeMargin number <optional>
0 Optional amount of buffer (in seconds) to retain when clearing the buffer. Defaults to 0 if not provided. Ignored if clearBuffer is false.
Source:

selectVariantTrack(track, clearBufferopt, safeMarginopt)

Select a specific variant track to play. track should come from a call to getVariantTracks. If track cannot be found, 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 Default Description
track shaka.extern.Track
clearBuffer boolean <optional>
false
safeMargin number <optional>
0 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:

setInitialTextState_()

Decide during startup if text should be streamed/shown.
Source:

setMaxHardwareResolution(width, height)

Set the maximum resolution that the platform's hardware can handle.
Parameters:
Name Type Description
width number
height number
Source:

setTextTrackVisibility(isVisible)

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:

setupLcevc_(confignullable)

Setup shaka.lcevc.Dec object
Parameters:
Name Type Attributes Description
config shaka.extern.PlayerConfiguration <nullable>
Source:

setupPreferredAudioOnSrc_()

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

setupPreferredTextOnSrc_()

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

setVideoContainer(videoContainer)

Set the videoContainer to construct UITextDisplayer.
Parameters:
Name Type Description
videoContainer HTMLElement
Source:

shouldInitiallyShowText_(audioStream, textStream) → {boolean}

Check if we should show text on screen automatically.
Parameters:
Name Type Description
audioStream shaka.extern.Stream
textStream shaka.extern.Stream
Source:
Returns:
Type
boolean

shouldStreamText_() → {boolean}

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

shouldUseSrcEquals_(assetUri, mimeTypeopt, nullable) → {boolean}

Determines if we should use src equals, based on the the mimeType (if known), the URI, and platform information.
Parameters:
Name Type Attributes Description
assetUri string
mimeType string <optional>
<nullable>
Source:
Returns:
|true| if the content should be loaded with src=, |false| if the content should be loaded with MediaSource.
Type
boolean

srcEqualsInner_(startTimeOfLoad, mimeType) → {Promise}

Passes the asset URI along to the media element, so it can be played src equals style.
Parameters:
Name Type Description
startTimeOfLoad number
mimeType string
Source:
Returns:
Type
Promise

startBufferManagement_(mediaElementnon-null, rebufferingGoal)

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

switch_(variant, clearBufferopt, safeMarginopt)

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

switchHtml5Track_(track)

Parameters:
Name Type Description
track AudioTrack
Source:

switchVariant_(variant, fromAdaptation, clearBuffer, safeMargin, forceopt)

Parameters:
Name Type Attributes Default Description
variant shaka.extern.Variant
fromAdaptation boolean
clearBuffer boolean
safeMargin number
force boolean <optional>
false
Source:

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:

unload(initializeMediaSourceopt, keepAdManageropt) → {Promise}

Unloads the currently playing stream, if any.
Parameters:
Name Type Attributes Default Description
initializeMediaSource boolean <optional>
true
keepAdManager boolean <optional>
false
Source:
Returns:
Type
Promise

updateAbrManagerVariants_() → {boolean}

Update AbrManager with variants while taking into account restrictions, preferences, and ABR. On error, this dispatches an error event and returns false.
Source:
Returns:
True if successful.
Type
boolean

updateBufferingSettings_(rebufferingGoal)

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

updateBufferState_()

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

updateStartTime(startTime)

Provides a way to update the stream start position during the media loading process. Can for example be called from the manifestparsed event handler to update the start position based on information in the manifest.
Parameters:
Name Type Description
startTime number
Source:

updateStateHistory_()

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

videoErrorToShakaError_() → {shaka.util.Error}

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

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'
oldTrack shaka.extern.Track
newTrack shaka.extern.Track
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:

Complete

Fires when the content completes playing. Only for VoD.
Properties:
Name Type Description
type string 'complete'
Source:

DownloadFailed

Fired when a download has failed, for any reason. 'downloadfailed'
Parameters:
Name Type Description
httpResponseCode number
aborted boolean
Properties:
Name Type Attributes Description
request shaka.extern.Request
error shaka.util.Error <nullable>
Source:

DownloadHeadersReceived

Fired when the networking engine has received the headers for a download, but before the body has been downloaded. If the HTTP plugin being used does not track this information, this event will default to being fired when the body is received, instead.
Properties:
Name Type Description
headers Object.<string, string>
request shaka.extern.Request
type shaka.net.NetworkingEngine.RequestType 'downloadheadersreceived'
Source:

DrmSessionUpdateEvent

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

EmsgEvent

Fired when an emsg box is found in a segment. If the application calls preventDefault() on this event, further parsing will not happen, and no 'metadata' event will be raised for ID3 payloads.
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:

FirstQuartile

Fires when the content playhead crosses first quartile. Only for VoD.
Properties:
Name Type Description
type string 'firstquartile'
Source:

GapJumpedEvent

Fired when the GapJumpingController jumps over a gap in the buffered ranges.
Properties:
Name Type Description
type string 'gapjumped'
Source:

KeyStatusChanged

Fired when the key status changed.
Properties:
Name Type Description
type string 'keystatuschanged'
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:

ManifestUpdatedEvent

Fired after the manifest has been updated (live streams).
Properties:
Name Type Description
type string 'manifestupdated'
isLive boolean True when the playlist is live. Useful to detect transition from live to static playlist..
Source:

MediaQualityChangedEvent

Fired when the media quality changes at the playhead. That may be caused by an adaptation change or a DASH period transition. Separate events are emitted for audio and video contentTypes. This is supported for only DASH streams at this time.
Properties:
Name Type Description
type string 'mediaqualitychanged'
mediaQuality shaka.extern.MediaQualityInfo Information about media quality at the playhead position.
position number The playhead position.
Source:

MetadataEvent

Triggers after metadata associated with the stream is found. Usually they are metadata of type ID3.
Properties:
Name Type Attributes Description
type string 'metadata'
startTime number The time that describes the beginning of the range of the metadata to which the cue applies.
endTime number <nullable>
The time that describes the end of the range of the metadata to which the cue applies.
metadataType string Type of metadata. Eg: org.id3 or org.mp4ra
payload shaka.extern.MetadataFrame The metadata itself
Source:

Midpoint

Fires when the content playhead crosses midpoint. Only for VoD.
Properties:
Name Type Description
type string 'midpoint'
Source:

RateChangeEvent

Fired when the video's playback rate changes. This allows the PlayRateController to update it's internal rate field, before the UI updates playback button with the newest playback rate.
Properties:
Name Type Description
type string 'ratechange'
Source:

SegmentAppended

Fired when a segment is appended to the media element.
Properties:
Name Type Description
type string 'segmentappended'
start number The start time of the segment.
end number The end time of the segment.
contentType string The content type of the segment. E.g. 'video', 'audio', or 'text'.
Source:

SessionDataEvent

Fired when the manifest parser find info about session data. Specification: https://tools.ietf.org/html/rfc8216#section-4.3.4.4
Properties:
Name Type Description
type string 'sessiondata'
id string The id of the session data.
uri string The uri with the session data info.
language string The language of the session data.
value string The value of the session data.
Source:

StallDetectedEvent

Fired when a stall in playback is detected by the StallDetector. Not all stalls are caused by gaps in the buffered ranges.
Properties:
Name Type Description
type string 'stalldetected'
Source:

Started

Fires when the content starts playing. Only for VoD.
Properties:
Name Type Description
type string 'started'
Source:

StateChanged

Fired when player state is changed.
Properties:
Name Type Description
type string 'statechanged'
newstate string The new state.
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:

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:

ThirdQuartile

Fires when the content playhead crosses third quartile. Only for VoD.
Properties:
Name Type Description
type string 'thirdquartile'
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 new tracks are added/removed 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'
oldTrack shaka.extern.Track
newTrack shaka.extern.Track
Source: