Web Player

Event listeners

Working with player listeners

Bind event

Add your custom listener and bind it to the start event of the player.

Example:

$bp().on('start', listener)

Attribute name

Description

event (string)

Name of the event, e.g. start

listener (function)

Function to call when the event fires

$bp() with no argument refers to the only player on the page. If the page has more than one player, use $bp('DIV_ID') with the ID of that player’s div.

Unbind event

Remove a listener you added. Pass the same function you passed to on() — calling off() with only the event name removes nothing.

Example:

function onStart() {
    console.log("Playback started");
}

$bp().on('start', onStart);

// later
$bp().off('start', onStart);

Bind event listener to execute only once

If you want to execute your custom callback only on the first occurrence of the event.
Example:

$bp().once('start', function() {
    console.log("Execute only once.");
});

Player ready listener example

Check if player is ready for API usage

Run any custom code that uses the player after this callback fires.
When it fires, all player components are loaded on the page and your custom code can run.

Example

function ready() {
    // Insert code to execute when player is ready for API usage
}

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"480",
	"video":"VIDEO_ID"
}, ready);
$bp("myDiv", {
    "id":"PLAYER_ID",
    "width":"640",
    "height":"480",
    "video":"VIDEO_ID"
});

$bp().on("ready", function() {
    console.log("I am ready!");
});
Event listeners · TargetVideo Developer Docs