Class: shaka.player.Player

Constructor

new Player(videonon-null)

Creates a Player.
Parameters:
Name Type Description
video HTMLVideoElement The video element.
Extends:
Source:
Fires:

Members

(private, static, constant) BUFFERED_FUDGE_FACTOR_ :number

A fudge factor to apply to buffered ranges and durations to determine if the video has buffered all available content.
Type:
  • number
Source:

(private, static, constant, non-null) MEDIA_ERROR_MAP_ :Object.<number, string>

A map of MediaError codes to error messages. The JS interpreter won't take a symbolic name as a key, so the symbolic names for these error codes appear in comments after the number.
Type:
  • Object.<number, string>
Source:

(private, static, constant) REWIND_UPDATE_INTERVAL_ :number

The number of seconds for each rewind update interval.
Type:
  • number
Source:

(private, static, constant) STYLE_ELEMENT_ID_ :string

The ID of a style element used to control text styles.
Type:
  • string
Source:

(private, static, constant) UNDERFLOW_THRESHOLD_ :number

The threshold for underflow, in seconds. If there is less than this amount of data buffered, we will consider the player to be out of data.
Type:
  • number
Source:

(static, constant) version :string

Type:
  • string
Source:

(private) buffering_ :boolean

Type:
  • boolean
Source:

(private) emeManager_ :shaka.media.EmeManager

Type:
Source:

(private, non-null) eventManager_ :shaka.util.EventManager

Type:
Source:

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

Type:
Inherited From:
Source:

(protected) parent :shaka.util.FakeEventTarget

Type:
Inherited From:
Source:

(private) playbackRate_ :number

Type:
  • number
Source:

(private, nullable) playbackStartTime_ :number

Type:
  • number
Source:

(private, nullable) rewindTimer_ :number

Type:
  • number
Source:

(private) seekRangeStart_ :number

Type:
  • number
Source:

(private, non-null) stats_ :shaka.player.Stats

Type:
Source:

(private, non-null) video_ :HTMLVideoElement

The video element.
Type:
  • HTMLVideoElement
Source:

(private) videoSource_ :shaka.player.IVideoSource

The video source object.
Type:
Source:

(private, non-null) videoSourceConfig_ :Object.<string, *>

Type:
  • Object.<string, *>
Source:

(private, nullable) watchdogTimer_ :number

Type:
  • number
Source:

Methods

(static) isBrowserSupported() → {boolean}

Determines if the browser has all of the necessary APIs to support the Shaka Player. This check may not pass if polyfills have not been installed.
Source:
Returns:
Type
boolean

(static) isTypeSupported(fullMimeType) → {boolean}

Determines if the specified MIME type and codec is supported by the browser.
Parameters:
Name Type Description
fullMimeType string A MIME type, which should include codec info.
Source:
Returns:
true if the type is supported.
Type
boolean

(static) setTextStyle(stylenon-null)

Sets style attributes for text tracks.
Parameters:
Name Type Description
style shaka.player.TextStyle
Source:

addEventListener(type, listener, opt_capturingopt)

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

(private) cancelRewindTimer_()

Cancels the rewind timer, if any.
Source:

(private) cancelWatchdogTimer_()

Cancels the watchdog timer, if any.
Source:

configure(config)

Configures the Player. Configuration options are set via key-value pairs. The default options are defined in shaka.player.Defaults.

The following configuration options are supported:
  • enableAdaptation: boolean
    Enables or disables automatic bitrate adaptation.
  • streamBufferSize: number
    Sets the maximum amount of content, in seconds, that audio and video streams will buffer ahead of the playhead. For DASH streams, this will be overridden if 'minBufferTime' is larger.
  • liveStreamEndTimeout: number
    Sets the amount of time that the player will wait after the last segment to determine if a live stream has ended.
  • licenseRequestTimeout: number
    Sets the license request timeout in seconds. A value of zero indicates no timeout.
  • mpdRequestTimeout: number
    Sets the MPD request timeout in seconds. A value of zero indicates no timeout.
  • segmentRequestTimeout: number
    Sets the segment request timeout in seconds. A value of zero indicates no timeout.
  • preferredLanguage: string
    Sets the preferred language (the default is 'en'). This affects which audio and video tracks are initially chosen.
    See IETF RFC 5646.
    See ISO 639.
  • restrictions: shaka.player.Restrictions
    Sets the video track restrictions. For example, if minBandwidth = 200000 and maxBandwidth = 700000 then the player will only permit switching to video tracks with bandwidths between 200000 and 700000.
  • disableCacheBustingEvenThoughItMayAffectBandwidthEstimation: boolean
    Disables all use of cache-busting parameters, even though it may affect bandwidth estimation. This is a stop-gap measure for Shaka v1, since many people have had issues with the cache-busting parameters we typically add to network requests. Shaka v2 will be cache-friendly by default.
    Please note that Shaka v1's bandwidth estimation algorithm can be adversely affected by caching, in particular when seeking in low-bandwidth environments, such as mobile devices.
    If cache-busting is a problem for your application or your CDN, use this parameter to disable it.
Parameters:
Name Type Description
config Object.<string, *> A configuration object, which contains the configuration options as key-value pairs.
Source:
Throws:
  • TypeError if a configuration option has the wrong type.
  • RangeError if a configuration option is out of range.
Example
player.configure({'enableAdaptation': false});
player.configure({'preferredLanguage': 'en',
                  'streamBufferSize': 15});

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

Destroys the player.
Source:
Returns:
A promise, resolved when destroy has finished.
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

enableTextTrack(enabled)

Enable or disable the text track. Has no effect if called before load() resolves.
Parameters:
Name Type Description
enabled boolean
Source:

(private) endBufferingState_()

Called to leave a buffering state, either due to unloading a video source, unpausing a video, or because of the watchdog's decision.
Source:

(private) enterBufferingState_()

Called to enter a buffering state.
Source:

getAudioTracks() → (non-null) {Array.<!shaka.player.AudioTrack>}

Gets the available audio tracks.
Source:
Returns:
Type
Array.<!shaka.player.AudioTrack>

getConfiguration() → (non-null) {Object.<string, *>}

Gets the Player's configuration.
Source:
See:
Returns:
A configuration object.
Type
Object.<string, *>

getPlaybackRate() → {number}

Returns the current playbackRate.
Source:
Returns:
Type
number

getStats() → (non-null) {shaka.player.Stats}

Gets updated stats about the player.
Source:
Returns:
Type
shaka.player.Stats

getTextTracks() → (non-null) {Array.<!shaka.player.TextTrack>}

Gets the available text tracks.
Source:
Returns:
Type
Array.<!shaka.player.TextTrack>

getVideoTracks() → (non-null) {Array.<!shaka.player.VideoTrack>}

Gets the available video tracks.
Source:
Returns:
Type
Array.<!shaka.player.VideoTrack>

isLive() → {boolean}

Source:
Returns:
Type
boolean

load(videoSourcenon-null) → (non-null) {Promise}

Loads the specified video source and starts playback. If a video source has already been loaded, this calls unload() for you before loading the new source.
Parameters:
Name Type Description
videoSource shaka.player.IVideoSource The IVideoSource object. The Player takes ownership of |videoSource|.
Source:
Returns:
Type
Promise

(private) onError_(eventnon-null)

Video error event handler.
Parameters:
Name Type Description
event Event
Source:

(private) onFirstTimestamp_(eventnon-null)

Time update event handler. Will be removed once the first update is seen.
Parameters:
Name Type Description
event Event
Source:

(private) onPause_(eventnon-null)

Video pause event handler. Fires any time the video stops for any reason, including before a 'seeking' or 'ended' event.
Parameters:
Name Type Description
event Event
Source:

(private) onPlaying_(eventnon-null)

Video playing event handler. Fires any time the video starts playing.
Parameters:
Name Type Description
event Event
Source:

(private) onRewindTimer_(startVideoTime, startWallTime, rate)

Called on a recurring timer to simulate rewind.
Parameters:
Name Type Description
startVideoTime number
startWallTime number
rate number
Source:

(private) onSeekRangeChanged_(eventnon-null)

Handler for seek range events.
Parameters:
Name Type Description
event Event
Source:

(private) onWatchdogTimer_()

Called on a recurring timer to detect buffering events.
Source:

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

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

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

Source:
Returns:
Type
Promise

removeEventListener(type, listener, opt_capturingopt)

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

selectAudioTrack(id, opt_clearBufferopt, opt_clearBufferOffsetopt) → {boolean}

Select an audio track by ID.
Parameters:
Name Type Attributes Description
id number The |id| field of the desired AudioTrack object.
opt_clearBuffer boolean <optional>
If true (and by default), removes the previous stream's content before switching to the new stream.
opt_clearBufferOffset number <optional>
if |clearBuffer| and |opt_clearBufferOffset| are truthy, clear the stream buffer from the given offset (relative to the audio's current time) to the end of the stream.
Source:
Returns:
True if the specified AudioTrack was found.
Type
boolean

selectTextTrack(id) → {boolean}

Select a text track by ID.
Parameters:
Name Type Description
id number The |id| field of the desired TextTrack object.
Source:
Returns:
True if the specified TextTrack was found.
Type
boolean

selectVideoTrack(id, opt_clearBufferopt) → {boolean}

Select a video track by ID. This can interfere with automatic bitrate adaptation, so you should disable adaptation, via shaka.player.Player#configure, if you intend to use manual video track selection.
Parameters:
Name Type Attributes Description
id number The |id| field of the desired VideoTrack object.
opt_clearBuffer boolean <optional>
If true (and by default), removes the previous stream's content before switching to the new stream.
Source:
Returns:
True if the specified VideoTrack was found.
Type
boolean

setPlaybackRate(rate)

Parameters:
Name Type Description
rate number The playback rate. Negative values will rewind the video. Positive values less than 1.0 will trigger slow-motion playback. Positive values greater than 1.0 will trigger fast-forward. 0.0 is similar to pausing the video. Some UAs will not play audio at rates less than 0.25 or 0.5 or greater than 4.0 or 5.0, but this behavior is not specified. No audio will be played while rewinding.
Source:

setPlaybackStartTime(startTime)

Parameters:
Name Type Description
startTime number Desired time (in seconds) for playback to begin from.
Source:

(private) setVideoEventListeners_()

Sets the video's event listeners.
Source:

(private) startWatchdogTimer_()

Starts the watchdog timer.
Source:

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

Stop playback and unload the current video source. Makes the player ready for reuse. Also resets any statistics gathered. MediaKeys must be unloaded asynchronously, but all other resources are removed synchronously.
Source:
Returns:
A promise, resolved when MediaKeys is removed.
Type
Promise

Events

BufferingEvent

Fired when the player's buffering state changes.
Properties:
Name Type Description
type string 'bufferingStart' or 'bufferingEnd'
Source:

ErrorEvent

Fired when a playback error occurs. Bubbles up through the Player.
Properties:
Name Type Description
type string 'error'
bubbles boolean true
detail Error An object which contains details on the error. The error's 'type' property will help you identify the specific error condition and display an appropriate message or error indicator to the user. The error's 'message' property contains English text which can be useful during debugging.
Source: