Class: shaka.Player

Constructor

new Player(videonon-null)

Construct a Player.
Parameters:
Name Type Description
video HTMLMediaElement Any existing TextTracks attached to this element that were not created by Shaka will be disabled. A new TextTrack may be created to display captions or subtitles.
Implements:
Extends:
Source:

Members

(private, static, constant) TextTrackId_ :string

Type:
  • string
Source:

(static, constant) version :string

Type:
  • string
Source:

(private) buffering_ :boolean

Type:
  • boolean
Source:

(private) bufferingTime_ :number

Type:
  • number
Source:

(private, nullable) config_ :shakaExtern.PlayerConfiguration

Type:
Source:

(private) defaultAbrManager_ :shakaExtern.AbrManager

Type:
Source:

(private, non-null) deferredSwitches_ :Object.<string, shakaExtern.Stream>

Type:
Source:

(private) drmEngine_ :shaka.media.DrmEngine

Type:
Source:

(private) eventManager_ :shaka.util.EventManager

Type:
Source:

(private) lastStatUpdateTimestamp_ :number

Type:
  • number
Source:

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

Type:
Inherited From:
Source:

(private) loadInProgress_ :boolean

Type:
  • boolean
Source:

(private, nullable) manifest_ :shakaExtern.Manifest

Type:
Source:

(private) mediaSource_ :MediaSource

Type:
  • MediaSource
Source:

(private) mediaSourceEngine_ :shaka.media.MediaSourceEngine

Type:
Source:

(private) mediaSourceOpen_ :Promise

Type:
  • Promise
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) parser_ :shakaExtern.ManifestParser

Type:
Source:

(private) playhead_ :shaka.media.Playhead

Type:
Source:

(private) playTime_ :number

Type:
  • number
Source:

(private) streamingEngine_ :shaka.media.StreamingEngine

Type:
Source:

(private, non-null) switchHistory_ :Array.<shakaExtern.StreamChoice>

Type:
Source:

(private) switchingPeriods_ :boolean

Type:
  • boolean
Source:

(private) textTrack_ :TextTrack

Type:
  • TextTrack
Source:

(private) video_ :HTMLMediaElement

Type:
  • HTMLMediaElement
Source:

Methods

(static) support() → (non-null) {Promise.<!shakaExtern.SupportType>}

Query the browser/platform and the plugins for manifest, media, and DRM support. Return a Promise to an object with details on what is supported. If returnValue.supported is 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
Promise.<!shakaExtern.SupportType>

addEventListener(type, listener, opt_capturingopt)

Add an event listener to this object.
Parameters:
Name Type Attributes Description
type string The event type to listen for.
listener shaka.util.FakeEventTarget.ListenerType The callback or listener object to invoke.
opt_capturing boolean <optional>
Ignored. FakeEventTargets do not have parents, so events neither capture nor bubble.
Inherited From:
Source:

addTextTrack(uri, language, kind, mime, opt_codecopt) → (non-null) {Promise.<shakaExtern.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 when the track can be switched to and will resolve with the track that was created.
Parameters:
Name Type Attributes Description
uri string
language string
kind string
mime string
opt_codec string <optional>
Source:
Returns:
Type
Promise.<shakaExtern.Track>

cancelTrickPlay()

Cancel trick-play.
Source:

(private) canSwitch_()

Callback from StreamingEngine.
Source:

(private) chooseStreams_(periodnon-null) → (non-null) {Object.<string, !shakaExtern.Stream>}

Chooses streams from the given Period.
Parameters:
Name Type Description
period shakaExtern.Period
Source:
Returns:
A map of stream types to streams.
Type
Object.<string, !shakaExtern.Stream>

configure(config)

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.
Parameters:
Name Type Description
config shakaExtern.PlayerConfiguration
Source:

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

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

createMediaSource() → (non-null) {Promise}

Create and open MediaSource. Potentially slow.
Source:
Returns:
Type
Promise

createMediaSourceEngine() → (non-null) {shaka.media.MediaSourceEngine}

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

createPlayhead(opt_startTimeopt) → (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
opt_startTime number <optional>
Source:
Returns:
Type
shaka.media.Playhead

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) defaultAdvancedDrmConfig_() → {shakaExtern.AdvancedDrmConfiguration}

Source:
Returns:
Type
shakaExtern.AdvancedDrmConfiguration

(private) defaultConfig_() → {shakaExtern.PlayerConfiguration}

Source:
Returns:
Type
shakaExtern.PlayerConfiguration

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

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

(private) destroyStreaming_() → (non-null) {Promise}

Destroy members responsible for streaming.
Source:
Returns:
Type
Promise

dispatchEvent(eventnon-null) → {boolean}

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

(private) filterPeriod_(period)

Parameters:
Name Type Description
period shakaExtern.Period
Source:

getConfiguration() → {shakaExtern.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
shakaExtern.PlayerConfiguration

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

getStats() → {shakaExtern.Stats}

Return playback and adaptation stats.
Source:
Returns:
Type
shakaExtern.Stats

getTracks() → (non-null) {Array.<shakaExtern.Track>}

Return a list of audio, video, and text tracks available for the current Period. If there are multiple Periods, then you must seek to the Period before being able to switch.
Source:
Returns:
Type
Array.<shakaExtern.Track>

(private) initialize_()

Initialize the Player.
Source:

isBuffering() → {boolean}

Source:
Returns:
True if the Player is in a buffering state.
Type
boolean

isLive() → {boolean}

Source:
Returns:
True if the current stream is live. False if the stream is VOD or if there is no active stream.
Type
boolean

isTextTrackVisible() → {boolean}

Source:
Returns:
True if the current text track is visible.
Type
boolean

load(manifestUri, opt_startTimeopt, opt_manifestParserFactoryopt) → (non-null) {Promise}

Load a manifest.
Parameters:
Name Type Attributes Description
manifestUri string
opt_startTime number <optional>
Optional start time, in seconds, to begin playback. Defaults to 0 for VOD and to the live edge for live.
opt_manifestParserFactory shakaExtern.ManifestParser.Factory <optional>
Optional manifest parser factory to override auto-detection or use an unregistered parser.
Source:
Returns:
Resolved when playback can begin.
Type
Promise

(private) mergeConfigObjects_(destinationnon-null, sourcenon-null, templatenon-null, path)

Parameters:
Name Type Description
destination Object
source Object
template Object supplies default values
path string to this part of the config
Source:

(private) onAdaptation_()

Dispatches a 'adaptation' event.
Source:

(private) onBuffering_(buffering)

Callback from Playhead.
Parameters:
Name Type Description
buffering boolean
Source:

(private) onChooseStreams_(periodnon-null) → (non-null) {Object.<string, !shakaExtern.Stream>}

Callback from StreamingEngine.
Parameters:
Name Type Description
period shakaExtern.Period
Source:
Returns:
A map of stream types to streams.
Type
Object.<string, !shakaExtern.Stream>

(private) onError_(errornon-null)

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

(private) onKeyStatus_(keyStatusMapnon-null)

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

(private) onSeek_()

Callback from Playhead.
Source:

(private) onSegmentDownloaded_(startTimeMs, endTimeMs, numBytes)

Callback from NetworkingEngine.
Parameters:
Name Type Description
startTimeMs number
endTimeMs number
numBytes number
Source:

(private) onTracksChanged_()

Dispatches a 'trackschanged' event.
Source:

(private) onVideoError_(eventnon-null)

Parameters:
Name Type Description
event Event
Source:

removeEventListener(type, listener, opt_capturingopt)

Remove an event listener from this object.
Parameters:
Name Type Attributes Description
type string The event type for which you wish to remove a listener.
listener shaka.util.FakeEventTarget.ListenerType The callback or listener object to remove.
opt_capturing boolean <optional>
Ignored. FakeEventTargets do not have parents, so events neither capture nor bubble.
Inherited From:
Source:

selectTrack(track, opt_clearBufferopt)

Select a specific track. For audio or video, this disables adaptation.
Parameters:
Name Type Attributes Description
track shakaExtern.Track
opt_clearBuffer boolean <optional>
Source:

setNetworkingEngine(netEnginenon-null)

Sets the current networking engine. Used for testing.
Parameters:
Name Type Description
netEngine shaka.net.NetworkingEngine
Source:

setTextTrackVisibility(on)

Set the visibility of the current text track, if any.
Parameters:
Name Type Description
on boolean
Source:

(private) switch_(streamsByTypenon-null)

Callback from AbrManager.
Parameters:
Name Type Description
streamsByType Object.<string, !shakaExtern.Stream>
Source:

trickPlay(rate)

Skip through the content without playing. Simulated using repeated seeks. 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 The playback rate to simulate. For example, a rate of 2.5 would result in 2.5 seconds of content being skipped every second. To trick-play backward, use a negative rate.
Source:

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

Unload the current manifest and make the Player available for re-use.
Source:
Returns:
Resolved when streaming has stopped and the previous content, if any, has been unloaded.
Type
Promise

(private) updateStats_()

Source:

Events

AdaptationEvent

Fired when the active tracks change.
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:

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 occured. In an uncompiled build, you can also use the 'message' and 'stack' properties to debug.
Source:

TracksChangedEvent

Fired when the list of tracks changes.
Properties:
Name Type Description
type string 'trackschanged'
Source: