Skip to content

Instantly share code, notes, and snippets.

@dmlap
Created February 17, 2015 16:00
Show Gist options
  • Save dmlap/41448ee777633c13ec20 to your computer and use it in GitHub Desktop.
Save dmlap/41448ee777633c13ec20 to your computer and use it in GitHub Desktop.
Dynamically configuring the ad server URL for the Brightcove Player.
/**
* PLUGIN CODE
*/
// create a simple javascript plugin that gets the current video ID and sets up ads:
videojs.plugin('setupAds', function() {
'use strict';
var player = this,
currentVideoId = player.el().getAttribute('data-video-id');
player.ima3({
serverUrl: '//ads.example.com/ad?q=100&anotherparam=17&video=' + currentVideoId
});
});
/**
* PLAYER CONFIGURATION
*/
// Below is the raw player configuration JSON, what you'd see if you were working
// with the Player Management APIs directly. You could configure all of this through
// the studio, too. Each of the top-level properties corresponds to the fields in
// the "Plugins" pane of the Player Details page.
// include that plugin in your player config *instead of* a plugin entry for videojs-ima3:
{
"scripts": [
"//players.brightcove.net/videojs-ima3/videojs.ima3.min.js",
"//example.com/setupads.js" // the URL to the plugin javascript above
],
"stylesheets": [
"//players.brightcove.net/videojs-ima3/videojs.ima3.min.css"
],
// only include plugin initialization options for the setupAds plugin
// setupAds will initialize videojs-ima3 instead of configuring it statically here
"plugins": [{
"name": "setupAds"
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment