Web Player

Video playback

Video playback code examples

Managing video quality

Change the video quality

To change the quality of the video that is playing, call setVideoSource. For MP4 sources, pass a rendition name: ld (240p), sd (360p), hsd (480p), mhd (540p), hd (720p), fhd (1080p), qhd (1440p), uhd (2160p) or fuhd (4320p). For HLS and DASH streams, pass a height such as "720p", or "Auto" to return to automatic quality. The call does nothing before playback has started, during an ad, or after the video has ended. More details are in the JavaScript API reference, under $bp().setVideoSource(rendition).

Example:

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

Detect a video quality change

The qualityChange event fires when the video quality changes. More details are in the JavaScript API reference, under $bp().on('qualityChange', listener).

$bp().on('qualityChange', function() {
    // custom code to execute on qualityChange event
});

Load the player with a specific video rendition quality

You can force a specific video rendition quality that the player will load by adding the video_source parameter to your embed code. Use one of the rendition names listed above; if the video has no rendition at that quality, the player uses the closest one. A quality the viewer picked in the player’s menu is remembered for 24 hours and takes priority over video_source.

Example:

$bp("myDiv", {
	"id": "PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"video_source":"hd"
});

HLS Secure URLs

If your HLS streams are protected by cookies (for example, a token stored in a cookie), set hls_with_credentials to true. The player then sends the browser’s cookies with every HLS request, for both the .m3u8 playlists and the segments. Your streaming server must allow credentialed cross-origin requests: Access-Control-Allow-Credentials: true, and Access-Control-Allow-Origin set to your site’s origin rather than *.

Example:

$bp("myDiv", {
    "id":"PLAYER_ID",
    "width":"640",
    "height":"360",
    "video":"VIDEO_ID",
    "hls_with_credentials": true
});

Set a maximum bitrate for HLS video streams

You can cap the bitrate the TargetVideo player uses for HLS streams with hls_max_bitrate, in bits per second ("500000" is 500 kbps). Renditions above the cap are removed; if every rendition is above it, the player uses the lowest one.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"hls_max_bitrate":"500000"
});	

Working with playback

Seek anywhere on the player’s timeline

The code snippet below shows how to use the API to seek anywhere on the player’s timeline. The code below will seek to the 90 second mark of a video.

Example:

$bp().currentTime(90);

Force player to load audio files without a valid audio extension

You can make the TargetVideo player play audio files whose URL has no valid audio extension by adding force_play_unknown_extensions to your embed code. The player then hands such files to the browser instead of rejecting them.

Example:

$bp("myDiv", {
    "id":"PLAYER_ID",
    "width":"640",
    "height":"360",
    "video":"VIDEO_ID", 
    "force_play_unknown_extensions" : true
});

Video click-through

Add a video click-through URL programmatically

Use the following code snippet to add or remove a video click-through URL via the player’s JavaScript API. Clicking the video then opens the URL in a new tab. Run the code in the function you pass to $bp() as its third argument: there, this is the player. The URL applies to the current video.

Example:

$bp("myDiv", config, function() {
    // Set a custom click-through URL
    this.currentSource.clickthroughUrl = "http://www.google.com";
    
    // Remove a click-through URL
    this.currentSource.clickthroughUrl = "";
});

Custom video click-through

The example below opens a custom click-through URL whenever the video is clicked.

Example:

function onReady() {
    this.touch.add('click', function () {
        window.open('http://google.com', '_blank');
    });
}

$bp("myDiv", config, onReady);

Volume

Set custom volume

Use the example below to set the player’s volume programmatically. Volume is a number from 0 (muted) to 1 (full).

Example:

$bp("myDiv", config, function() {
    this.volume(0.2);
});
Video playback · TargetVideo Developer Docs