Player state
You can get information about the video player state and parameters using a special object which contains fields with state values.
Video player parameters
Video types in the player
The video player supports three types of videos:
-
VOD
: Standard video with a fixed beginning, end, and duration.An example of such a video is a movie.
-
EVENT
: Live stream where only the beginning is fixed, and duration is constantly increasing as the right edge of the timeline keeps crawling forward.A user can rewind or fast forward to any point on the video timeline, from the beginning to what is now its right edge. If a user’s playback position matches the right edge, this user is considered to be online. At some point, the right edge may stop crawling, in which case the video type will change to
VOD
.An example of such a video is a soccer game live stream.
-
LIVE
: Live stream where the right and left edges of its timeline continiously change over time.A user can only rewind or fast forward between the current left and right timeline edges. As with
EVENT
videos, if a user’s playback position matches the right timeline edge, this user is considered to be online.An example of such a video is a live stream of a TV channel.
The video type is specified in the videoType field of the object with player states.
Current time
Current time marks the current playback position on the timeline. You can get the current time from the currentTime field of the object with player states.
Current time is measured in seconds.
LIVE
videos use Unix timestampsVOD
and EVENT
types, it is measured in seconds from the start of the video, which has the 0
value.
Example 1: For
VOD
andEVENT
video types,currentTime
may indicate10
. This means that the current playback position on the timeline is 10 seconds from the start of the video.
Example 2: For a
LIVE
video, thecurrentTime
field may indicate1600000000
. This means that the current playback position on the timeline matchesnew Date(1600000000 * 1000)
in absolute time, i.e.,Sep 13 2020 14:26:40 GMT+0200
.
Duration
Duration indicates the difference between the right and left edges of the video timeline. You can get the video duration from the duration field of the object with player states.
Duration is measured in seconds.
For the LIVE
video type, duration is always Infinity
.
Video start time in UTC .
Video start time in UTC indicates the start time of a live stream in UTC
Video start time is measured in seconds.
For LIVE
videos, the value is always 0
.
For the EVENT
video type, it is always a non-null value in Unix Timestamp
format.
Example: The
utcStartTime
field may indicate1600000000
. This means the video started atnew Date(1600000000 * 1000)
, orSep 13 2020 14:26:40 GMT+0200
.
For VOD
videos, this is an optional value. For example, a VOD
video may get this value if it was created from an EVENT
video. The value is undefined
when it is not specified. If specified, the value is in utcStartTime
format (same as for EVENT
).
Seekable range
Seekable range indicates the timeline range where the user can move the current playback position. You can get this value from the seekableRange field of the object with player states.
Format:
{
/** @type {number} left edge of the range in seconds */
start,
/** @type {number} right edge of the range in seconds */
end,
}
For VOD
and EVENT
videos, the start
field is always set to 0
. The end
field value matches the right edge of the timeline. In the case of EVENT
videos, this value is constantly increasing.
For the LIVE
type, the start
and end
values are specified in Unix Timestamp
format. The end
value is constantly increasing.
For example, if the
seekableRange
field of aLIVE
broadcast contains an object with thestart === 1600000000
andend === 1600001000
fields, the user’s seekable range has1600000000
and1600001000
as its left and right edges.
Playback status .
You can get the playback status value from the status field of the object with player states.
The playback status may take one of the following values:
idle
: Player is waiting for content to play.init
: Initializing the player after the first playable content is set.buffering
: Player is in buffering state and cannot play the video, e.g., due to lack of data.play
: Video playback is in progress.pause
: Player is paused.end
: Current video playback ended at the right edge of the timeline.fatal
: Current video cannot be played; the user gets an error screen. To start a video, the user can try switching to other content.broken
: Player is broken and cannot play the video, the user gets an error screen. Switching to other content is not possible.destroyed
:destroy
method was called, the player is destroyed and can no longer play the video.cancelled
: Live stream was cancelled.preparing
: Live stream is about to start.finished
: Live stream ended.
Player state object
A player state is an object with the following fields:
- source
- status
- error
- currentTime
- duration
- videoType
- muted
- volume
- utcStartTime
- seekableRange
- bufferedRanges.
source
Link to current content. If no content is provided, the source
field is set to undefined
.
status
It can take the following values:
'idle'
'init'
'buffering'
'play'
'pause'
'end'
'fatal'
'broken'
'destroyed'
'cancelled'
'preparing'
'finished'
The default value is 'idle'
.
error
Player error.
If there are no errors at the moment, this field is undefined
. In case of an error, its value is an object of the following format:
{
/** @type {string} error code */
code,
/** @type {string} error message */
message,
}
If the field contains an error object, this means, at the moment, the player cannot start or resume video playback. In this case, the status field value will be either 'fatal'
or 'broken'
.
The default value is undefined
.
currentTime
Current time (timeline position) in seconds.
The default value is NaN
.
duration
Video duration in seconds.
The default value is NaN
.
videoType
It can take the following values:
undefined
'VOD'
'EVENT'
'LIVE'
The default value is undefined
.
muted
Video muted
status. If true
, sound is off; if false
, sound is on.
The default value is the one provided in the configuration on player initialization. If no value was provided on initialization, the default value is true
.
volume
Video volume level ranging from 0
(muted) to 1
(maximum volume).
The default value is the one provided in the configuration on player initialization. If no value was provided on initialization, the default value is 1
.
utcStartTime
Video start time in UTC specified in seconds or undefined
.
The default value is undefined
.
seekableRange
The default value is { start: NaN, end: NaN }
.
bufferedRanges
Buffered ranges. This is an array of objects in the following format:
{
/** @type {number} buffer start in seconds */
start,
/** @type {number} buffer end in seconds */
end,
}
Array elements define the timeline ranges for which there is buffered data for playback.
The default value is an empty array ([]
).
See also
- Interface: PlayerSdkState in the API reference