Web Player

Working with playlists

Play the n-th item in a playlist via API

Use the following code snippet to start playback of the 3rd video in a playlist. Positions start at 0, so playByIndex(2) plays the 3rd video. The call does nothing while an ad is playing or loading, or if the position is past the end of the playlist.

Example:

$bp().playByIndex(2);

Start playing from specific index in a playlist

To easily start playback of specific video in a playlist, you can do this by passing the video’s position to the player in the embed code. Positions start at 0, so "4" below starts with the 5th video:

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"playlist":"PLAYLIST_ID",
	"startPlaylistIndex":"4"
});

Limit the number of videos in a playlist

Use the maxItems param in the player’s embed code to limit the number of videos in a playlist.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"playlist":"PLAYLIST_ID",
	"maxItems":5
});

Set a playlist of items via an external config

You can use the following example to set up your player to play a playlist of your own video items from a JSON file. The playlist must be an absolute URL (starting with https:// or //); anything else is read as a playlist ID from your account.

Example:

$bp("myDiv", {
    "id":"PLAYER_ID",
    "width":"800",
    "height":"600",
    "playlist":"https://your-domain.com/custom_playlist.json"
});

Or pass the playlist items directly in the embed code:

var playerConfig = {
	"id": "PLAYER_ID",
	"playlist": {
		"Video": [
			{
				"title": "TITLE I",
				"image": "STARTING SNAPSHOT URL",
				"thumbnail": "URL TO THUMBNAIL",
				"videoId": "ARBITRARY VIDEO ID (OPTIONAL)",
				"duration": "DURATION OF VIDEO IN SECONDS",
				"source": {
					"sd": "DIRECT URL TO SD RENDITION",
					"hd": "DIRECT URL TO HD RENDITION"
				}
			},
			{
				"title": "TITLE 2",
				"image": "STARTING SNAPSHOT URL",
				"thumbnail": "URL TO THUMBNAIL",
				"videoId": "ARBITRARY VIDEO ID (OPTIONAL)",
				"duration": "DURATION OF VIDEO IN SECONDS",
				"source": {
					"sd": "DIRECT URL TO SD RENDITION",
					"hd": "DIRECT URL TO HD RENDITION"
				}
			},
			{
				"title": "TITLE 3",
				"image": "STARTING SNAPSHOT URL",
				"thumbnail": "URL TO THUMBNAIL",
				"videoId": "ARBITRARY VIDEO ID (OPTIONAL)",
				"duration": "DURATION OF VIDEO IN SECONDS",
				"source": {
					"sd": "DIRECT URL TO SD RENDITION",
					"hd": "DIRECT URL TO HD RENDITION"
				}
			}
		]
	}
}

var targetVideoPlayer = $bp('myDiv', playerConfig);

Example of how JSON playlist should look like:

{
	"Video": [
		{
			"title": "TITLE I",
			"image": "STARTING SNAPSHOT URL",
			"thumbnail": "URL TO THUMBNAIL",
			"videoId": "ARBITRARY VIDEO ID (OPTIONAL)",
			"source": {
				"sd": "VIDEO_URL"
			}
		},
		{
			"title": "TITLE 2",
			"image": "STARTING SNAPSHOT URL",
			"thumbnail": "URL TO THUMBNAIL",
			"videoId": "ARBITRARY VIDEO ID (OPTIONAL)",
			"source": {
				"sd": "VIDEO_URL",
				"hd": "VIDEO_URL"
			}
		},
		{
			"title": "TITLE 3",
			"image": "STARTING SNAPSHOT URL",
			"thumbnail": "URL TO THUMBNAIL",
			"videoId": "ARBITRARY VIDEO ID (OPTIONAL)",
			"source": {
				"sd": "VIDEO_URL",
				"hd": "VIDEO_URL"
			}
		}
	]
}

Shuffle playlist items

Use the following code snippet to shuffle an embedded playlist in a TargetVideo player. This option will load a random video from your playlist on each player load.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"480",
	"playlist":"PLAYLIST_ID",
	"shuffle": true
});

Increase the initial number of items in a playlist

Use the items param in the player’s embed code to increase the initial number of videos loaded in a playlist. The default value is 20, however, you can expand the initial number of videos to up to 100.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"playlist":{
		mode:"playlist",
		id :"PLAYLIST_ID", 
		items:50 
	}
});
Working with playlists · TargetVideo Developer Docs