Class: shaka.Player

Constructor

new Player(videonon-null, opt_dependencyInjectoropt)

Construct a Player.
Parameters:
Name Type Attributes 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.
opt_dependencyInjector function(shaka.Player)= <optional>
Optional callback which is called to inject mocks into the Player. Used for testing.
Implements:
Extends:
Source:

Members

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

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

(private, static, constant) TextTrackLabel_ :string

Type:
  • string
Source:

(static, constant) version :string

Type:
  • string
Source:

(private, non-null) activeStreamsByPeriod_ :Object.<number, !Object.<string, number>>

A map of Period number to a map of content type to stream id.
Type:
  • Object.<number, !Object.<string, number>>
Source:

(private) buffering_ :boolean

Type:
  • boolean
Source:

(private, nullable) config_ :shakaExtern.PlayerConfiguration

Type:
Source:

(private) currentAudioLanguage_ :string

Type:
  • string
Source:

(private) currentTextLanguage_ :string

Type:
  • string
Source:

(private) currentTextRole_ :string

Type:
  • string
Source:

(private) currentVariantRole_ :string

Type:
  • string
Source:

(private) defaultAbrManager_ :shakaExtern.AbrManager

Type:
Source:

(private, non-null) deferredSwitches_ :Object.<shaka.util.ManifestParserUtils.ContentType, {stream: shakaExtern.Stream, clearBuffer: boolean}>

Type:
Source:

(private) destroyed_ :boolean

Type:
  • boolean
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) eventManager_ :shaka.util.EventManager

Type:
Source:

(private) lastTimeStatsUpdateTimestamp_ :number

Type:
  • number
Source:

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

Type:
Inherited From:
Source:

(private) loadChain_ :shaka.util.CancelableChain

Type:
Source:

(private, non-null) loadingTextStreamIds_ :Array.<number>

Type:
  • Array.<number>
Source:

(private, nullable) manifest_ :shakaExtern.Manifest

Type:
Source:

(private, nullable) manifestUri_ :string

Type:
  • string
Source:

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

Type:
  • {width: number, height: number}
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, non-null) pendingTimelineRegions_ :Array.<shakaExtern.TimelineRegionInfo>

Type:
Source:

(private) playhead_ :shaka.media.Playhead

Type:
Source:

(private) playheadObserver_ :shaka.media.PlayheadObserver

Type:
Source:

(private) stats_ :shakaExtern.Stats

Type:
Source:

(private) streamingEngine_ :shaka.media.StreamingEngine

Type:
Source:

(private) switchingPeriods_ :boolean

Type:
  • boolean
Source:

(private) textTrack_ :TextTrack

Type:
  • TextTrack
Source:

(private) unloadChain_ :Promise

Type:
  • Promise
Source:

(private) video_ :HTMLMediaElement

Type:
  • HTMLMediaElement
Source:

Methods

(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

(static) probeSupport() → (non-null) {Promise.<shakaExtern.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.<shakaExtern.SupportType>

(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:

addEventListener(type, listener, opt_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.
opt_options AddEventListenerOptions | boolean <optional>
Ignored.
Inherited From:
Source:

addTextTrack(uri, language, kind, mime, opt_codecopt, opt_labelopt) → (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>
opt_label string <optional>
Source:
Returns:
Type
Promise.<shakaExtern.Track>

(private) addToSwitchHistory_(streamnon-null, fromAdaptation)

Parameters:
Name Type Description
stream shakaExtern.Stream
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:

cancelTrickPlay()

Cancel trick-play.
Source:

(private) canSwitch_()

Callback from StreamingEngine.
Source:

(private) chooseCodecsAndFilterManifest_()

In case of multiple usable codecs, choose one based on lowest average bandwidth and filter out the rest.
Source:

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

Chooses streams from the given Period.
Parameters:
Name Type Attributes Description
period shakaExtern.Period
variants Array.<!shakaExtern.Variant>
textStreams Array.<!shakaExtern.Stream>
opt_chooseAll boolean <optional>
If true, choose streams of every type.
Source:
Returns:
A map of stream types to chosen streams.
Type
Object.<string, !shakaExtern.Stream>

(private) chooseStreamsAndSwitch_(periodnon-null)

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

(private) configOverrides_() → (non-null) {Object}

Source:
Returns:
Type
Object

configure(confignon-null)

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 Object This should follow the form of shakaExtern.PlayerConfiguration, but you may omit any field you do not wish to change.
Source:

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

Creates a new instance of DrmEngine. This can be replaced by tests to create fake 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

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

createPlayheadObserver() → (non-null) {shaka.media.PlayheadObserver}

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

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

Source:
Returns:
Type
shakaExtern.PlayerConfiguration

(private) deferredSwitch_(streamsByTypenon-null, opt_clearBufferopt)

Switches to the given streams, deferring switches if needed.
Parameters:
Name Type Attributes Description
streamsByType Object.<shaka.util.ManifestParserUtils.ContentType, shakaExtern.Stream>
opt_clearBuffer boolean <optional>
Source:

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

drmInfo() → (nullable) {shakaExtern.DrmInfo}

Get the DrmInfo used to initialize EME. This returns null when not using EME.
Source:
Returns:
Type
shakaExtern.DrmInfo

(private) filterPeriod_(period)

Parameters:
Name Type Description
period shakaExtern.Period
Source:

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

Return a list of audio languages available for the current Period.
Source:
Returns:
Type
Array.<string>

(private) getCleanStats_() → {shakaExtern.Stats}

Source:
Returns:
Type
shakaExtern.Stats

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

getExpiration() → {number}

The next known expiration time for any EME session. If the sessions never expire, or there are no EME sessions, this returns Infinity.
Source:
Returns:
Type
number

getManifestUri() → (nullable) {string}

Source:
Returns:
If a manifest is loaded, returns the manifest URI given in the last call to load(). Otherwise, returns null.
Type
string

getMediaElement() → {HTMLMediaElement}

Source:
Returns:
A reference to the HTML Media Element passed in during initialization.
Type
HTMLMediaElement

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}

Gets the current effective playback rate. If using trick play, it will return the current trick play rate; otherwise, it will return the video playback rate.
Source:
Returns:
Type
number

getPlayheadTimeAsDate() → {Date}

Returns current playhead time as a Date.
Source:
Returns:
Type
Date

getStats() → {shakaExtern.Stats}

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

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

Return a list of text languages available for the current Period.
Source:
Returns:
Type
Array.<string>

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

Return a list of 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>

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

Return a list of variant 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.
Deprecated:
  • Use getVariantTracks() or getTextTracks()
    Source:
    Returns:
    Type
    Array.<shakaExtern.Track>

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

    Return a list of variant 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:

    isAudioOnly() → {boolean}

    Source:
    Returns:
    True for audio-only content. False otherwise.
    Type
    boolean

    isBuffering() → {boolean}

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

    isInProgress() → {boolean}

    Source:
    Returns:
    True if the current stream is in-progress VOD. False otherwise.
    Type
    boolean

    isLive() → {boolean}

    Source:
    Returns:
    True if the current stream is live. False otherwise.
    Type
    boolean

    isTextTrackVisible() → {boolean}

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

    keySystem() → {string}

    Get the key system currently being used by EME. This returns the empty string if not using EME.
    Source:
    Returns:
    Type
    string

    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 the manifest has been loaded and playback has begun; rejected when an error occurs or the call was interrupted by destroy(), unload() or another call to load().
    Type
    Promise

    (private) onAdaptation_()

    Dispatches a 'adaptation' event.
    Source:

    (private) onBuffering_(buffering)

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

    (private) onChangePeriod_()

    Callback from PlayheadObserver.
    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 chosen streams.
    Type
    Object.<string, !shakaExtern.Stream>

    (private) onError_(errornon-null)

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

    (private) onEvent_(eventnon-null)

    Parameters:
    Name Type Description
    event Event
    Source:

    (private) onExpirationUpdated_(keyId, expiration)

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

    (private) onKeyStatus_(keyStatusMapnon-null)

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

    (private) onManifestUpdate_()

    Callback from StreamingEngine.
    Source:

    (private) onSeek_()

    Callback from Playhead.
    Source:

    (private) onSegmentAppended_()

    Callback from StreamingEngine.
    Source:

    (private) onSegmentDownloaded_(deltaTimeMs, numBytes)

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

    (private) onTextTrackVisibility_()

    Source:

    (private) onTimelineRegionAdded_(region)

    Parameters:
    Name Type Description
    region shakaExtern.TimelineRegionInfo
    Source:

    (private) onTracksChanged_()

    Dispatches a 'trackschanged' event.
    Source:

    (private) onVideoError_(eventnon-null)

    Parameters:
    Name Type Description
    event Event
    Source:

    removeEventListener(type, listener, opt_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.
    opt_options EventListenerOptions | boolean <optional>
    Ignored.
    Inherited From:
    Source:

    resetConfiguration()

    Reset configuration to default.
    Source:

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

    Reset the streaming system.
    Source:
    Returns:
    Type
    Promise

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

    Get the seekable range for the current stream.
    Source:
    Returns:
    Type
    {start: number, end: number}

    selectAudioLanguage(languagenon-null, opt_roleopt)

    Sets currentAudioLanguage to the selected language and chooses new variant in that language if need be.
    Parameters:
    Name Type Attributes Description
    language string
    opt_role string <optional>
    Source:

    selectTextLanguage(languagenon-null, opt_roleopt)

    Sets currentTextLanguage to the selected language and chooses new text stream in that language if need be.
    Parameters:
    Name Type Attributes Description
    language string
    opt_role string <optional>
    Source:

    selectTextTrack(track)

    Select a specific text track. Note that AdaptationEvents are not fired for manual track selections.
    Parameters:
    Name Type Description
    track shakaExtern.Track
    Source:

    selectTrack(track, opt_clearBufferopt)

    Select a specific track. For variant tracks, this disables adaptation. Note that AdaptationEvents are not fired for manual track selections.
    Parameters:
    Name Type Attributes Description
    track shakaExtern.Track
    opt_clearBuffer boolean <optional>
    Deprecated:
    • Use selectVariantTrack() or selectTextTrack()
      Source:

      selectVariantTrack(track, opt_clearBufferopt)

      Select a specific track. Note that AdaptationEvents are not fired for manual track selections.
      Parameters:
      Name Type Attributes Description
      track shakaExtern.Track
      opt_clearBuffer boolean <optional>
      Source:

      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:

      setTextTrackVisibility(on)

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

      (private) switch_(streamsByTypenon-null, opt_clearBufferopt)

      Callback from AbrManager.
      Parameters:
      Name Type Attributes Description
      streamsByType Object.<shaka.util.ManifestParserUtils.ContentType, !shakaExtern.Stream>
      opt_clearBuffer boolean <optional>
      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) updateActiveStreams_(streamnon-null)

      Parameters:
      Name Type Description
      stream shakaExtern.Stream
      Source:

      (private) updateState_()

      Called from potential initiators of state change, or before returning stats to the user. This method decides if state has actually changed, updates the last entry, and adds a new one if needed.
      Source:

      (private) updateTimeStats_()

      Source:

      Events

      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:

      EmsgEvent

      Fired when a non-typical emsg is found in a segment.
      Properties:
      Name Type Description
      type string 'emsg'
      detail shakaExtern.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:

      LoadingEvent

      Fired when the player begins loading. Used by the Cast receiver to determine idle state.
      Properties:
      Name Type Description
      type string 'loading'
      Source:

      TextTrackVisibilityEvent

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

      TimelineRegionAdded

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

      TimelineRegionEnter

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

      TimelineRegionExit

      Fired when the playhead exits a timeline region.
      Properties:
      Name Type Description
      type string 'timelineregionexit'
      detail shakaExtern.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: