Constructor
new Playhead(video, manifest, config, startTimenullable, onSeek, onEvent)
Creates a Playhead, which manages the video's current time.
The Playhead provides mechanisms for setting the presentation's start time,
restricting seeking to valid time ranges, and stopping playback for startup
and re- buffering.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
video |
HTMLMediaElement | ||
manifest |
shakaExtern.Manifest | ||
config |
shakaExtern.StreamingConfiguration | ||
startTime |
number |
<nullable> |
The playhead's initial position in seconds. If null, defaults to the start of the presentation for VOD and the live-edge for live. |
onSeek |
function() | Called when the user agent seeks to a time within the presentation timeline. | |
onEvent |
function(!Event) | Called when an event is raised to be sent to the application. |
- Implements:
- Source:
Members
-
(private) buffering_ :boolean
-
Type:
- boolean
- Source:
-
(private, nullable) config_ :shakaExtern.StreamingConfiguration
-
Type:
- Source:
-
(private) didFireLargeGap_ :boolean
-
Type:
- boolean
- Source:
-
(private) earlySeekTimer_ :shaka.util.Timer
-
Used to batch up early seeks and delay until video.currentTime is updated.
Type:
- Source:
-
(private) eventManager_ :shaka.util.EventManager
-
Type:
- Source:
-
(private, nullable) gapJumpTimer_ :shaka.util.Timer
-
Type:
- Source:
-
(private) hadSegmentAppended_ :boolean
-
Type:
- boolean
- Source:
-
(private, nullable) manifest_ :shakaExtern.Manifest
-
Type:
- Source:
-
(private, nullable) onEvent_ :?function(!Event)
-
Type:
- ?function(!Event)
- Source:
-
(private, nullable) onSeek_ :?function()
-
Type:
- ?function()
- Source:
-
(private) playbackRate_ :number
-
Type:
- number
- Source:
-
(private) prevReadyState_ :number
-
Type:
- number
- Source:
-
(private) seekingEventReceived_ :boolean
-
Type:
- boolean
- Source:
-
(private) stallCorrected_ :boolean
-
True if we have already flushed the pipeline at stallPlayheadTime_. Allows us to avoid flushing multiple times for the same stall.
Type:
- boolean
- Source:
-
(private) stallPlayheadTime_ :number
-
The playhead time where we think a stall occurred. When the ready state says we don't have enough data and the playhead stops too long, we assume we have stalled.
Type:
- number
- Source:
-
(private) stallWallTime_ :number
-
The wall-clock time (in milliseconds) that the stall occurred. This is used to ensure we don't flush the pipeline too often.
Type:
- number
- Source:
-
(private, nullable) startTime_ :number
-
The playhead's initial position in seconds, or null if it should automatically be calculated later.
Type:
- number
- Source:
-
(private, nullable) trickPlayTimer_ :shaka.util.Timer
-
Type:
- Source:
-
(private) video_ :HTMLMediaElement
-
Type:
- HTMLMediaElement
- Source:
Methods
-
(private) clampSeekToDuration_(time) → {number}
-
Clamp seek times and playback start times so that we never seek to the presentation duration. Seeking to or starting at duration does not work consistently across browsers. TODO: Clean up and simplify Playhead. There are too many layers of, methods for, and conditions on timestamp adjustment.
Parameters:
Name Type Description time
number Returns:
The adjusted seek time.- Type
- number
-
(private) clampTime_(time) → {number}
-
Clamps the given time to the segment availability window.
Parameters:
Name Type Description time
number The time in seconds. - Source:
Returns:
The clamped time in seconds.- Type
- number
-
destroy() → (non-null) {Promise}
-
Destroys the object, releasing all resources and shutting down all operations. Returns a Promise which is resolved when destruction is complete. This Promise should never be rejected.
- Implements:
- Source:
Returns:
- Type
- Promise
-
getPlaybackRate() → {number}
-
Gets the current effective playback rate. This may be negative even if the browser does not directly support rewinding.
- Source:
Returns:
- Type
- number
-
(private) getStartTime_() → {number}
-
Gets the playhead's initial position in seconds.
- Source:
Returns:
- Type
- number
-
getTime() → {number}
-
Gets the playhead's current (logical) position.
- Source:
Returns:
- Type
- number
-
(private) movePlayhead_(currentTime, targetTime)
-
Moves the playhead to the target time, triggering a call to onSeeking_().
Parameters:
Name Type Description currentTime
number targetTime
number - Source:
-
(private) onEarlySeek_()
-
Handles a 'timeupdate' event that occurs before metadata is loaded, which would indicate that the user is seeking. Note that a 'seeking' event will not fire before content is loaded. In this state, the playhead can only move as a result of a seek action, so timeupdate is a good choice.
- Source:
-
(private) onLoadedMetadata_()
-
Handles a 'loadedmetadata' event.
- Source:
-
(private) onPlaying_()
-
Handles a 'playing' event.
- Source:
-
(private) onPollGapJump_()
-
Called on a recurring timer to check for gaps in the media. This is also called in a 'waiting' event.
- Source:
-
(private) onRateChange_()
-
Handles a 'ratechange' event.
- Source:
-
(private) onSeeking_()
-
Handles a 'seeking' event.
- Source:
-
(private) onSeekingToStartTime_()
-
Handles the 'seeking' event from the initial jump to the start time (if there is one).
- Source:
-
onSegmentAppended()
-
Called when a segment is appended by StreamingEngine, but not when a clear is pending. This means StreamingEngine will continue buffering forward from what is buffered. So we know about any gaps before the start.
- Source:
-
(private) reposition_(currentTime) → {number}
-
Computes a new playhead position that's within the presentation timeline.
Parameters:
Name Type Description currentTime
number - Source:
Returns:
The time to reposition the playhead to.- Type
- number
-
setBuffering(buffering)
-
Stops the playhead for buffering, or resumes the playhead after buffering.
Parameters:
Name Type Description buffering
boolean True to stop the playhead; false to allow it to continue. - Source:
-
setPlaybackRate(rate)
-
Sets the playback rate.
Parameters:
Name Type Description rate
number - Source:
-
setStartTime(startTime)
-
Adjust the start time. Used by Player to implement the streaming.startAtSegmentBoundary configuration.
Parameters:
Name Type Description startTime
number - Source: