Web Player

JavaScript API Reference

HTML5 Player JavaScript API method details

❗ Important

Load the player script before you call the API: targetvideo.min.js for players, targetvideo.outstream.min.js for outstream units (full URLs below). With the asynchronous embed (_bp.push), the script can load later. See Asynchronous embed code.

Player:
https://player.target-video.com/player/build/targetvideo.min.js

Outstream:
https://player.target-video.com/player/build/targetvideo.outstream.min.js

Referencing a player

Every method on this page is called on a player reference that $bp() returns. There are two ways to get it:

  • $bp("DIV_ID") returns the player set up in the div with that ID. Use it when the page has more than one player, so the action runs on that player only. You can also pass the div element itself, or the ID with a leading #.

  • $bp() with no argument returns the first player on the page. This is a shortcut for pages with a single player: with several players it still returns the first one and logs a warning in the console; with no players it logs “No players found on the page.” and returns undefined.

// The player in the div with ID "DIV_ID"
$bp("DIV_ID").play();

// The only player on the page
$bp().play();

An ID that no player uses throws a TypeError. Called with a configuration object, $bp("DIV_ID", config) sets up a new player instead (see Player Initialization below). Inside a ready callback, this is the player too.

Player Initialization

TargetVideo Player can be configured differently depending on your requirements. To learn more about the player configuration please read our Player configuration reference guide.

$bp(div, options)

Initialize TargetVideo Player

Property

Description

Required

div (string)

The target div that TargetVideo Player will display in

required

config (string)

Configuration object that will tell your player how to render itself

required

Example TargetVideo player embed code:

$bp("DIV_ID", {
    "id":"PLAYER_ID",
    "width":"640",
    "height":"360",
    "video":"VIDEO_ID"
});
<script type="text/javascript" src="https://player.target-video.com/player/build/targetvideo.min.js"></script>

<div id="DIV_ID"> </div>

<script type="text/javascript">
    $bp("DIV_ID", {
        "id":"PLAYER_ID",
        "width":"640",
        "height":"360",
        "video":"VIDEO_ID"
    });
</script>

List of embed code (config) parameters:

Parameter

Description

Required

id (string)

Unique ID that each player in TargetVideo platform has

required

width (string)

Width of the player

required

height (string)

Height of the player

required

video (string)

Unique video ID in TargetVideo platform

required

$bp().destroy(boolDiv)

This call will remove a TargetVideo Player from the page. Player playback will be stopped, the DOM will be re-set to the original state and all event listeners and timers will be cleaned up. If another player is setup on the page after calling destroy() method all event listeners will need to be re-instantiated.

Example

$bp().destroy();        // Remove player and HTML element in which the player is being rendered
$bp().destroy(true);    // Remove just the player, keep the HTML element in which the player is being rendered

Attribute

Description

Required

boolDiv (bool)

If you pass a true param to destroy method, the player will not remove the div HTML element in which it is being rendered. If left empty, the div HTML element in which it renders will be removed from the page.

optional

$bp().isReady

This call will check if the player is ready for API manipulation. Will return true or false depending on the player status.

Example

$bp("DIV_ID", {"id":"PLAYER_ID","width":"480","height":"270","video":"VIDEO_ID"}, function(){
    console.log('Am I ready?', this.isReady);
});

$bp('div', config, onReady)

This is the suggested method to check if a player is ready for API usage via a callback function.

Property

Description

Required

div (string)

The target div that TargetVideo Player will display in

required

config (string)

Object that contains all required params to render a player

required

onReady (function)

Callback function

required

Example

$bp("DIV_ID", config, function(){
    console.log("I am ready!");
});

Event Listeners

📘 Note

on, once and off add and remove event listeners. The older names add, addOnce and remove still work, but this documentation uses only the new ones.

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

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

Attribute

Description

Required

ready (string)

Name of the event

required

listener (function)

Function which will be called when ready event is dispatched from the player

required

$bp().once('ready', listener)

Add your custom listener only once and bind it to the 'ready' event of the player.

$bp().off('ready', listener)

Remove your custom event listener from the players 'ready' event.

Here is an example of how to check if a TargetVideo player is ready for API usage - recommended callback example.

Example:

<script type="text/javascript">
    function ready() {
        // Insert code here to execute when player is ready for API usage
    }
</script>

<div id="DIV_ID" style="width:640px; height:360px;"></div>
<script type="text/javascript">
    $bp("DIV_ID", config, ready);
</script>
<div id="DIV_ID" style="width:640px; height:360px;"></div>
<script type="text/javascript">
    var _bp = _bp || [];
    _bp.push({
        "div": "DIV_ID",
        "obj": {"id":"PLAYER_ID","width":"640","height":"360","video":"VIDEO_ID"},
        "onReady": function () {
            // Insert code here to execute when the player is ready for API usage
        }
    });
</script>

<script type="text/javascript" async src="https://player.target-video.com/player/build/targetvideo.min.js"></script>
<div id="DIV_ID" style="width:640px; height:360px;"></div>
<!-- Check that a TargetVideo outstream unit is ready for API usage (async embed code) -->
<script type="text/javascript">
    var _bos = _bos || [];
    _bos.push({
        "div": "DIV_ID",
        "obj": {"id":"UNIT_ID","width":"640","height":"360"},
        "onReady": function () {
            // Insert code here to execute when the unit is ready for API usage
        }
    });
</script>
<script type="text/javascript" async src="https://player.target-video.com/player/build/targetvideo.outstream.min.js"></script>

Playback

These API calls are used to change the current playback state of the player.

$bp().play()

This call will start video playback. Calling play() while media is playing does nothing.

⚠️ Warning

If you use custom code to start video playback and have ads enabled, on mobile browsers and the latest Chrome and Safari, you should dispatch a user interaction before calling the play method.

$bp().pause()

This call will pause video playback.

$bp().stop()

This call will stop the player and return the player to its initial state.

These API calls are used to change the playback volume of the player.

⚠️ Warning

Setting volume will only work on desktop browsers, not on mobile devices.

$bp().volume(volume)

This call will set a custom value for the player volume (values range from 0 to 1). Also returns current volume.

Attribute

Description

Required

volume (float)

Sets volume of the video element - valid range is between 0 and 1.

optional

Return

Description

volume (float)

Returns the volume value.

Example:

// Set volume to 15%
$bp("DIV_ID", config, function(){
    this.volume(0.15);
});

$bp().muted(muted)

Use as a true/false switch to mute the player and also returns the current mute state.

Attribute

Description

Required

muted (bool)

Sets or gets the current volume.

optional

Return

Description

muted (bool)

Gets the current mute state.

Example:

// Set video state to muted
$bp("DIV_ID", config, function(){
    this.muted(true);
});
// Get video muted state
$bp("DIV_ID", config, function(){
    var muted = this.muted();
});

⚠️ Warning

Keep in mind that due to the current state of VPAID ad creatives, they can have sole control over how sound is being controlled depending on browser restrictions that are set. Due to this, our player does have custom mute handling built-in to force mute behaviors in certain conditions but due to the above, under certain circumstances (latency, lag, client machine etc.) a VPAID ad can force sound for a split-second until our custom mute handling kicks in. This is only true for autoplay-start muted implementations.

$bp().currentTime(int)

This call will return the current time.

Return

Description

time (float)

Return current time of the playback or if an integer is passed will seek the player to that amount of seconds.

Example:

$bp().currentTime();
// 10.413225

$bp().currentTime(25);
// Will seek the player to the 25th second of the video.

$bp().duration()

This call will return the duration of the video.

Return

Description

duration (float)

Returns the duration of the media element

Example:

$bp().duration();
// 184.5

$bp().currentChapter(chapter)

Returns an object that has the current running chapter number, name and start and end time of the current chapter. This method will return null if a video has no video chapters.

Attribute

Description

Required

chapter (int)

Passing an integer to the method will seek the player to the start of the chapter. Chapter numbers start at 0 for the first chapter.

optional

Return

Description

chapterInfo (object)

Current chapter object

Example:

$bp().currentChapter();
// {num: 2, name: "Chapter 3", start: 120, end: 185.5}
// Will seek the player to the start of the third chapter
$bp().currentChapter(2);

$bp().setHD(toggle)

This call will set the player to playback the video in HD (If video has an HD preset).

Attribute

Description

Required

toggle (bool)

(Require) Switch between HD and SD rendition of the media element.

optional

Example:

$bp().setHD(true);
// Switch rendition to HD resolution
$bp().setHD(false);
// Switch rendition back to SD resolution

$bp().isHD()

This call will return true or false depending on if the currently playing video is playing an HD rendition or not.

Return

Description

status (bool)

True/False if current media is playing a HD rendition.

Example:

$bp().isHD();
// true

$bp().setVideoSource(rendition)

This call will set the selected video rendition quality inside the player.

Property

Description

Required

rendition (string)

Change the rendition of the media element. Limitations can apply depending on the account owner’s plan. See the below available values.

optional

Rendition source available values:

Video Source Abbervation

Source Description

ld

Low definition video

sd

Standard definition video

hsd

High standard definition video

fhd

Full high definition video

hd

High definition video

Example:

$bp().setVideoSource("hd");

💡 Tip

For the available renditions and how to switch quality, see Video playback.

$bp().paused()

This call returns true or false depending on if playback is paused. While an ad is playing, it returns the state of the ad.

Return

Description

paused (bool)

true if playback is paused.

Example:

$bp().paused();
// false

$bp().ended()

This call returns true or false depending on if the current video has played to the end.

Return

Description

ended (bool)

true if the video has ended.

Example:

$bp().ended();
// true

$bp().togglePlay()

This call does the same as the player’s play button: it starts playback when the video is paused, pauses it when it is playing, and replays the video when it has ended. While an ad is playing, it plays or pauses the ad.

Example:

// Play or pause the player from your own button
document.getElementById("BUTTON_ID").addEventListener("click", function(){
    $bp().togglePlay();
});

$bp().playbackRate(rate)

This call gets or sets the playback speed: 1 is normal speed, 0.5 half speed and 2 double speed. Called without an argument, it returns the current speed.

Attribute

Description

Required

rate (number)

New playback speed

optional

Return

Description

rate (number)

Current playback speed

Example:

$bp().playbackRate(1.5);
// Play at one and a half times the normal speed
$bp().playbackRate();
// 1.5

$bp().loop(loop)

This call gets or sets whether the current video starts again from the beginning when it ends. Called without an argument, it returns the current setting.

Attribute

Description

Required

loop (bool)

true to loop the video, false to stop at the end.

optional

Return

Description

loop (bool)

true if the video loops.

Example:

$bp().loop(true);
// The video starts again when it ends
$bp().loop();
// true

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

$bp().once('qualityChange', listener)

$bp().off('qualityChange', listener)

The qualitychange event is fired from the player whenever a player switches the video rendition used for playback.

Property

Description

Required

event (string)

Name of the event - qualityChange.

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('chapterChange', listener)

$bp().off('chapterChange', listener)

The chapterChange event is fired from the player whenever playback moves into a different chapter of the video. The event data holds the new chapter, or null when the new video has no chapters.

Property

Description

Required

event (string)

Name of the event - chapterChange

required

listener (function)

Function which will be called when the event fires

required

Event data

Description

index (int)

Chapter number, starting at 0 for the first chapter

name (string)

Chapter name

start (number)

Chapter start time in seconds

end (number)

Chapter end time in seconds

Example:

$bp().on('chapterChange', function(e){
    if (e.data) {
        console.log('Chapter', e.data.index, e.data.name);
    }
});

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

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

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

The start event is fired from the player when a video starts playing back first time.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('start', function(){
    console.log('Video started!');
});

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

$bp().once('beforeStart', listener)

$bp().off('beforeStart', listener)

The beforeStart event is fired from the player right before an ad starts playback or before a video starts playback if no ad exists.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('beforeStart', function(){
    console.log('Before video started!');
});

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

$bp().once('play', listener)

$bp().off('play', listener)

The play event is fired from the player whenever the video is in a played state.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('play', function(){
    console.log('Play video!');
});

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

$bp().once('pause', listener)

$bp().off('pause', listener)

The pause event is fired from the player whenever the video is in a paused state.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('pause', function(){
    console.log('Pause video!');
});

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

$bp().once('ended', listener)

$bp().off('ended', listener)

The ended event is fired from the player whenever the video has finished playback.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('ended', function(){
    console.log('Video ended!');
});

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

$bp().once('stopped', listener)

$bp().off('stopped', listener)

The stopped event is fired from the player whenever the player is forcefull stopped. This can only be done via an API call.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('stopped', function(){
    console.log('Video stopped!');
});

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

$bp().once('lastSecond', listener)

$bp().off('lastSecond', listener)

The lastSecond event is fired from the player whenever a video in the player reaches its last second of playback.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('lastSecond', function(){
    console.log('Last second of the video!');
});

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

$bp().once('videoFirstQuartile', listener)

$bp().off('videoFirstQuartile', listener)

The videoFirstQuartile event is fired from the player when playback reaches 25% of the video. It fires once per video, and only when playback passes that point; if the viewer seeks past it, the event does not fire.

Property

Description

Required

event (string)

Name of the event - videoFirstQuartile

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('videoMidpoint', listener)

$bp().off('videoMidpoint', listener)

The videoMidpoint event is fired from the player when playback reaches 50% of the video. It fires once per video, and only when playback passes that point; if the viewer seeks past it, the event does not fire.

Property

Description

Required

event (string)

Name of the event - videoMidpoint

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('videoThirdQuartile', listener)

$bp().off('videoThirdQuartile', listener)

The videoThirdQuartile event is fired from the player when playback reaches 75% of the video. It fires once per video, and only when playback passes that point; if the viewer seeks past it, the event does not fire.

Property

Description

Required

event (string)

Name of the event - videoThirdQuartile

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on(['videoFirstQuartile', 'videoMidpoint', 'videoThirdQuartile'], function(e){
    console.log('Video progress:', e.type);
});

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

$bp().once('playbackerror', listener)

$bp().off('playbackerror', listener)

This event is fired from the player when a video errors out for any reason.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('playbackerror', function(){
    console.log('Video playback error!');
});

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

$bp().once('clickedThrough', listener)

$bp().off('clickedThrough', listener)

This event is fired from the player whenever the user clicks on a video.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('clickedThrough', function(){
    console.log('Video was clicked.');
});

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

$bp().once('livestreamstopped', listener)

$bp().off('livestreamstopped', listener)

This event is fired from the player whenever a live stream is not running for any reason.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('livestreamstopped', function(){
    console.log('A livestream has stopped working.');
});

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

$bp().once('livestreamstarted', listener)

$bp().off('livestreamstarted', listener)

This event is fired from the player whenever a livestream that had stopped is running again and playback resumes.

Property

Description

Required

event (string)

Name of the event - livestreamstarted

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('livestreamstarted', function(){
    console.log('The livestream is running again.');
});

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

$bp().once('destroyBefore', listener)

$bp().off('destroyBefore', listener)

This event is triggered by the player just before the destroy method is called, which will remove a TargetVideo Player from the page. This functionality is particularly handy for outstream players, as the player will not be displayed unless a valid ad is returned.

Parameter

Description

Required

event (string)

Name of the event

required

listener (function)

Function which will be called when the event fires

required

Example:

$bos("DIV_ID", config, function(){
    var impression = false;
    this.on("adImpression", function() {
        impression = true;
    });
    this.on("destroyBefore", function() {
        if (!impression) {
            // Outstream closed, no impression fired
        }
    });
});

Playlist

$bp().src(source)

This call will set a custom video source via a String or Object.
Here's a small subset of accepted values that you can use to set a custom playlist.

Parameter

Description

Required

source (string|object)

Provide source URL or object defined as in below format.

required

source object details:

Property

Description

Required

src (string)

Direct URL to media file

optional

title (string)

The title of the playlist item

optional

description (string)

The description of the playlist item

optional

monetize (bool)

Monetization state of playlist item

optional

❗ Important

src needs to be wrapped into a ready callback.

Example:

$bp("DIV_ID", config, function(){
    $bp().src({
        "src" : "https://cdn.target-video.com/live/partners/264/sd/685723.mp4",
        "title" : "Test video title",
        "monetize" : false
    });
});
$bp().src("https://cdn.target-video.com/live/partners/264/sd/685723.mp4");

$bp().loadPlaylist(source)

This call will load a custom playlist of videos via a direct URL to a JSON playlist file.

Property

Description

Required

source (string)

Direct URL to media file

required

Example:

$bp().loadPlaylist("https://player.target-video.com/services/get/video/1/633599.json");

$bp().currentSrc()

This call will return the URL to the video that is currently playing.

Return

Description

URL (string)

URL to the media element.

Example:

$bp().currentSrc();
// https://cdn.target-video.com/live/partners/264/sd/685723.mp4

$bp().playlistLength

Get the number of videos in a playlist.

Return

Description

items (int)

Number of videos in a playlist.

Example:

$bp().playlistLength;
// 4

$bp().next()

This call will playback the next video in a playlist.

$bp().previous()

This call will playback the previous video in a playlist.

$bp().playByIndex(index)

This call will playback the n-th video in a playlist. Index starts at 0.

Property

Description

Required

index (int)

Index of the playlist. Index starts at 0.

required

$bp().currentIndex

Get the index of the video file that is currently playing in a playlist.

Return

Description

index (int)

Current index in the playlist

Example:

$bp().currentIndex;
// 0 - first item in playlist

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

$bp().once('playlistStart', listener)

$bp().off('playlistStart', listener)

The playlistStart event is fired from the player whenever a playlist starts playback.

Property

Description

Required

event (string)

Name of the event

required

callback (function)

Function which will be called when the event fires

required

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

$bp().once('skipped', listener)

$bp().off('skipped', listener)

The skipped event is fired from the player whenever the previous or next buttons in the player are called or the player goes automatically to the next video in your playlist.

Property

Description

Required

event (string)

Name of the event

required

callback (function)

Function which will be called when the event fires

required

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

$bp().once('playlistComplete', listener)

$bp().off('playlistComplete', listener)

The playlistComplete event is fired from the player when a playlist finishes playback.

Property

Description

Required

event (string)

Name of the event

required

callback (function)

Function which will be called when the event fires

required

Seek

These API calls are used to the current status of the players progress bar.

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

$bp().once('timeupdate', listener)

$bp().off('timeupdate', listener)

The timeupdate event is fired from the player whenever a time update occurs in the player. Frequency depends on browser.

Property

Description

Required

event (string)

Name of the event

required

callback (function)

Function which will be called when the event fires

required

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

$bp().once('progress', listener)

$bp().off('progress', listener)

The progress event is fired from the player whenever a player is buffering your video content. Frequency depends on browser.

Property

Description

Required

event (string)

Name of the event

required

callback (function)

Function which will be called when the event fires

required

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

$bp().once('seeked', listener)

$bp().off('seeked', listener)

The seeked event is fired from the player whenever a user seeks on the players timeline.

Property

Description

Required

event (string)

Name of the event

required

callback (function)

Function which will be called when the event fires

required

Advertising

These API calls provide check various states an ad can have inside the TargetVideo player.
The adSkip and adComplete events in this category provide two additional params that give you information about the ad pod and ad waterfall position.

Example:

$bp().on('adComplete', function(e){

    console.log(e.type, e.data);
    // adComplete {wp: 1, pod: 0, pods: 2}

});

Sample response (e.data):

{"wp": 1, "pod": 0, "pods": 2}

Property

Description

Required

wp (integer)

Waterfall position

optional

pod (integer)

Current pod position of ad

optional

pods (integer)

Number of pods set on the player level

optional

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

$bp().once('requestAd', listener)

$bp().off('requestAd', listener)

The requestAd event is fired from the player whenever an ad request is made.

Property

Description

Required

event (string)

Name of the event - requestAd

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('AdsManagerLoadedEvent', listener)

$bp().off('AdsManagerLoadedEvent', listener)

The AdsManagerLoadedEvent event is fired from the player whenever Google IMA SDK fires their AdsManagerLoadedEvent event.

Property

Description

Required

event (string)

Name of the event - AdsManagerLoadedEvent

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('bidWon', listener)

$bp().off('bidWon', listener)

The bidWon event is fired from the player whenever Prebid returns a winning bid.

Property

Description

Required

event (string)

Name of the event - bidWon

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adStart', listener)

$bp().off('adStart', listener)

The adStart event is fired from the player whenever an ad begins playback.

Property

Description

Required

event (string)

Name of the event - adStart

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('vpaidStart', listener)

$bp().off('vpaidStart', listener)

The vpaidStart event is fired from the player whenever a VPAID ad begins playback. You can use this event to differentiate between a VPAID ad and a normal VAST ad.

Property

Description

Required

event (string)

Name of the event - vpaidStart

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adImpression', listener)

$bp().off('adImpression', listener)

The adImpression event is fired from the player whenever an ad is prepared to be played back and its impression pixel(s) gets fired.

Property

Description

Required

event (string)

Name of the event - vpaidStart

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adFirstQuartile', listener)

$bp().off('adFirstQuartile', listener)

The adFirstQuartile event is fired from the player whenever 25% of an ad has been viewed.

Property

Description

Required

event (string)

Name of the event - adFirstQuartile

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adMidpoint', listener)

$bp().off('adMidpoint', listener)

The adMidpoint event is fired from the player whenever 50% of an ad has been viewed.

Property

Description

Required

event (string)

Name of the event - adMidpoint

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adThirdQuartile', listener)

$bp().off('adThirdQuartile', listener)

The adThirdQuartile event is fired from the player whenever 75% of an ad has been viewed.

Property

Description

Required

event (string)

Name of the event - adThirdQuartile

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adEnd', listener)

$bp().off('adEnd', listener)

The adEnd event is fired from the player whenever an ad call process is done from start to finish. This does not necessarily mean that an ad will playback. This event fires once a complete ad cycle is completed no matter if an ad displays or not.

Property

Description

Required

event (string)

Name of the event - adThirdQuartile

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adComplete', listener)

$bp().off('adComplete', listener)

The adComplete event is fired from the player whenever an ad finishes playback.

Property

Description

Required

event (string)

Name of the event - adComplete

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adsCompleted', listener)

$bp().off('adsCompleted', listener)

The adsCompleted event is fired from the player once the whole ad break has finished. Unlike adComplete, which fires for every ad, it fires once, after the last ad of the break.

Property

Description

Required

event (string)

Name of the event - adsCompleted

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adSkip', listener)

$bp().off('adSkip', listener)

The adSkip event is fired from the player whenever a user clicks on the "SKIP AD" button inside the player for ads that are set to be skippable.

Property

Description

Required

event (string)

Name of the event - adSkip

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adError', listener)

$bp().off('adError', listener)

The adError event is fired from the player whenever an ad errors out for any reason.

Property

Description

Required

event (string)

Name of the event - adError

required

listener (function)

Function which will be called when the event fires

required

💡 Tip

See below code example on how to get additional information about the ad error like the ad error code and small description of the error.

!!! See below code example on how to get additional information about the ad error like the ad error code and small description of the error.

Example:

$bp().on('adError', function(e) {
    console.log(e.data.code, e.data.message);
});

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

$bp().once('adPause', listener)

$bp().off('adPause', listener)

The adPause event is fired from the player whenever an ad is paused.

Property

Description

Required

event (string)

Name of the event - adPause

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adResume', listener)

$bp().off('adResume', listener)

The adResume event is fired from the player whenever an ad has resumed playback after being paused.

Property

Description

Required

event (string)

Name of the event - adResume

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('adClicked', listener)

$bp().off('adClicked', listener)

The adClicked event is fired from the player whenever a user clicks on an ad.

Property

Required

event (string)

Name of the event - adClicked

required

listener (function)

Function which will be called when the event fires

required

📘 Note

The following advertising events ('adStart', 'adError' and 'adImpression') have additional data associated with them with which you can get the response of the XML template itself. In case of redirects, the last template in the array will be returned as a result. This callback is only possible if you use our in-house TargetVideo ad parser. Google IMA SDK is not supported.

Example:

$bp().on(['adStart','adError','adImpression'], function(e) {
    console.log('ad event', e.type, 'xml', $bp().values.lastVASTXML);
});

$bp().setAd(ad, prepend, level)

Set a custom ad for the player to play. It has no effect on videos with monetization turned off.

Property

Description

Required

ad (JSON object)

Define ad object to be added to the waterfall stack. Ad object is described below.

required

prepend (bool)

true adds the ad tags to the start of the existing waterfall for that ad type. false or omitted replaces that waterfall’s ad tags; if it has a separate desktop list, desktop devices keep using that list. If the player has no ad of that type yet, the ad is added either way.

optional

level (string)

player (default) or video. With player, ads set on the current video are cleared. video only works if the current video already has its own ad settings; otherwise your ad isn’t added, so use player.

optional

Ad object:

Property

Description

Required

adTagUrl (string or array)

One ad tag URL, or an array of ad tag URLs called in succession.

required

adType (string)

"0" pre-roll, "1" mid-roll, "2" post-roll, "3" overlay. Pass it as a string — a number is ignored.

required

adTimeType (string)

For mid-rolls: s seconds, % percentage of the video, i interval.

for a new mid-roll

cuepoints (string)

Comma-separated mid-roll positions, for example "20, 30". Needed when the player has no mid-roll yet; an existing mid-roll keeps its own cue points.

for a new mid-roll

pod (number)

Which ad pod of that ad type to set, starting at 0. Default: 0.

optional

The mobile and desktop arrays used in the embed code’s Ad setting are not read by setAd.

📘 Note

All ads that get set on a video level will override any setting set up on the player level.

$bp().setAd({
    "adType":"0", // pre-roll
    "adTimeType": "s",
    "adTagUrl" : ["https://adtag-url-1","https://adtag-url-2"]
});

$bp().playAd(ad)

This call will playback an ad on command.
You can pass an Ad object the same way as explained above or a direct URL to a valid VAST ad tag.

Property

Description

Required

ad (int)

JSON object as described above or direct URL to a valid VAST ad tag.

required

$bp().pushAds()

This method plays the player’s mid-roll ad immediately, wherever playback currently is in the video. It does nothing if the player has no mid-roll ad set up, or while an ad is already playing.

$bp().getAdInProgress()

This call returns true or false depending on if an ad is playing.

Return

Description

adInProgress (bool)

true if ad is in progress.

Other

Other various events and API calls that you might find useful.

$bp().toggleFullScreen(enter)

Use this method to switch the player into or out of fullscreen mode. Pass true to enter fullscreen and false to leave it; the method returns the player. Browsers only allow fullscreen after a user action, such as a click, and on iOS it only works while a video is playing.

Attribute

Description

Required

enter (bool)

true to enter fullscreen, false to leave it.

required

Example:

// Enter fullscreen from your own button
document.getElementById("BUTTON_ID").addEventListener("click", function(){
    $bp().toggleFullScreen(true);
});

$bp().isFullScreen

This call returns true or false depending on if the player is in fullscreen or not.

Return

Description

isFullScreen (bool)

true if video element is in full screen mode.

$bp().isPlayerInView()

This call returns true or false depending on if the player is 50% in view or not.

$bp().changeSkin(id)

Use this call to change the players skin using the unique ID that each TargetVideo skin has.

Property

Description

Required

id (int)

ID of the skin from TargetVideo platform. For more details about the valid values checkout the TargetVideo Platform API.

required

$bp().resize(width, height)

With this call you can dynamically resize the player.

Property

Description

Required

width (int)

Width of the player

required

height (int)

Height of the player

required

$bp().resize(16, 9);

$bp().getTitle()

Use this method to get current video title.

$bp().getTags()

Use this method to get current video tags.

$bp().getVersion()

This call returns the version of the TargetVideo Player running on the page. Include it when you report a player issue to support.

Return

Description

version (string)

Player version

Example:

$bp().getVersion();
// "2.7.18"

$bp().toggleTheaterMode(enter)

Use this method to switch theater mode on or off. It only works when theater mode is enabled for the player and the player is not inside an iframe. See the Theater mode guide for the setup and the CSS.

Attribute

Description

Required

enter (bool)

true to switch theater mode on, false to switch it off.

required

Example:

$bp().toggleTheaterMode(true);
// Switch theater mode on
$bp().toggleTheaterMode(false);
// Switch theater mode off

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

$bp().once('theaterModeChange', listener)

$bp().off('theaterModeChange', listener)

The theaterModeChange event is fired from the player whenever theater mode is switched on or off. e.data.on is true when theater mode is on.

Property

Description

Required

event (string)

Name of the event - theaterModeChange

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('theaterModeChange', function(e){
    console.log('Theater mode on:', e.data.on);
});

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

$bp().once('loadedmetadata', listener)

$bp().off('loadedmetadata', listener)

The loadedmetadata event is fired from the player whenever the entire video metadata has been loaded.

Property

Description

Required

event (string)

Name of the event - loadedmetadata

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('fullscreenchange', listener)

$bp().off('fullscreenchange', listener)

The fullscreenchange event is fired from the player whenever the fullscreen button has been called.

Property

Description

Required

event (string)

Name of the event - fullscreenchange

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('playerresize', listener)

$bp().off('playerresize', listener)

The playerresize event is fired whenever a player is resized.

Property

Description

Required

event (string)

Name of the event - playerresize

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('volumechange', listener)

$bp().off('volumechange', listener)

The volumechange event is fired whenever the player volume is changed.

Property

Description

Required

event (string)

Name of the event - volumechange

required

listener (function)

Function which will be called when the event fires

required

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

$bp().once('mutechange', listener)

$bp().off('mutechange', listener)

The mutechange event is fired whenever the players mute status is changed.

Property

Description

Required

event (string)

Name of the event - volumechange

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('mutechange', function(e){
    console.log(e.data.muted);
    // true
});

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

$bp().once('stickyChange', listener)

$bp().off('stickyChange', listener)

The stickyChange event is fired from the player whenever the a player goes to sticky or get's un-stickied.

Property

Description

Required

event (string)

Name of the event - stickyChange

required

listener (function)

Function which will be called when the event fires

required

Example:

$bp().on('stickyChange', function(e){
    console.log('stickyChange event', e.data);
});
$bp().on('stickyChange', function(e){
    console.log('stickyChange event', e.data);
    if (!e.data.sticky && e.data.interaction) {
        console.log('closed on X button click!');
    }
});

Event.data explained:

Event.data

Description

Required

sticky (bool)

Will be true or false depending on the player position

optional

interaction (bool)

Will return true if there was a user interaction

optional

JavaScript API Reference · TargetVideo Developer Docs