Bitrate and Buffer JavaScript APIs (Player V2 Deprecated)

The Bitrate Selection API allows developers to programmatically obtain buffer information, as well as get and set bitrates.

JavaScript Bitrate Selection API

Note: Ooyala Player V2 has been deprecated and is scheduled to be disabled. For details and alternatives, see the OVP Release Notes.
To select a bitrate, you can use either of the following options:
  • select a bitrate based on its quality (auto, low, medium, or high). For example, if you set the bitrate quality to high, the player will decide which is the highest available encoding.
  • select a bitrate based on its kbps number (sum of both audio and video encodings). For example, consider a video with the following available bitrates: [600 kbps, 1000 kbps, 3000 kbps, 4000 kbps]. You can set the bitrate quality to be any of those values.

JavaScript Bitrate Selection Functions

The following table describes all the JavaScript methods (a function invoked through an object) that are associated with bitrates and buffers.

Function Description
getBitrateQualitiesAvailable()

Returns an array of strings.

Format: read-only.

Type: string array

The size of the array is dependent on the number of encodings available:

  • When only one encoding is available, the function returns [‘auto’]
  • When two encodings are available, the function returns [‘auto’,’low’,’high’]
  • When three or more encodings are available, the function returns [‘auto’,’low’, ‘medium’, ’high’]
  • When no bitrate quality information is available, the function returns [‘auto’]
getBitratesAvailable()

Returns an array with the total number of bitrates, in kbps, or an empty array when the number of encodings is not available. For example, [250, 500, 1000] indicates that three bitrates are available: 250 kbps, 500 kbps and 1000 kbps.

Format: read-only

Type: integer array

Examples: [250, 500, 1000] indicates that three bitrates are available: 250 kbps, 500 kbps and 1000 kbps.

getTargetBitrate()

Get the target bitrate, in kbps, when target bitrate was previously set, or -1 otherwise.

Format: read-only

Type: Number Return Values: kbps | -1

getTargetBitrateQuality()

Get the target bitrate quality.

Format: Read-only.

Type: String

Return Values: One of auto, low, medium or high.

setTargetBitrate(bitrate)

Set the target bitrate, in kbps. The input needs to be an available bitrate. Available bitrates can be determined by a call to getBitratesAvailable().

Note: This setting does not carry over from video to video.

Format: Write-only.

Type: Number

Example: Consider a channel with two videos, the first with highest bitrate of 1000 kbps, and the second with medium bitrate of 1000 kbps and highest bitrate of 2000 kbps. If you set bitrate to 1000 kbps, we convert this number to a bitrate quality, which in this case in high. Since bitrate quality carries over, the first video will play at 1000 kbps, and the second video will play at 2000 kbps, which is its highest bitrate.

getBufferLength()

Returns the current size of the buffer in seconds, when buffer length is supported, or 0 otherwise. Currently, YouTube Assets and Remote Assets do not support buffer length.

Type: Number.

Return Values: time in seconds | 0

setTargetBitrateQuality(quality)

Set the target bitrate quality.

Format: Write-only.

Valid Values: One of the following:

  • auto—use adaptive bitrate algorithms to provide the best bitrate given the user’s current bandwidth and CPU usage. This setting carries over from video to video within a particular embed.
  • low—lowest bitrate available
  • medium—median of all bitrates available
  • high—highest bitrate available

Example: Consider a channel with two videos, the first with highest bitrate of 1000 kbps, and the second with medium bitrate of 1000 kbps and highest bitrate of 2000 kbps. If you set bitrate quality to high, the first video will play at 1000 kbps, and the second video will play at 2000 kbps, which is its highest bitrate.

JavaScript Bitrate Selection Events

The following table describes all the JavaScript events that are associated with bitrates.
Function Description
changeCurrentItem(embedCode)

The target bitrate quality has changed.

targetBitrateQualityChanged The target bitrate quality has changed.

Related Information

The following list provides links to Backlot documentation that provides some general information about bitrates and buffers.

Was this article helpful?