Skip to content

Instantly share code, notes, and snippets.

@dmlap
Created August 14, 2014 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmlap/6154eec4d7b4e0168c23 to your computer and use it in GitHub Desktop.
Save dmlap/6154eec4d7b4e0168c23 to your computer and use it in GitHub Desktop.
Specifying and reading player configuration at runtime.
/*
* Publishers (and the Brightcove Studio) can specify options through the player config.
* Here's an example player config:
*/
var config = {
"scripts": ["http://example.com/analytics.js"],
"plugins": [{
"name": "analytics",
/* You can pass arbitrary key-value pairs to a plugin through the options object.
For this plugin, we're going to pass along an account ID that we'll use at runtime: */
"options": {
"clientId": 7
}
}]
}
/**
* In your plugin code, you'll be passed the options object at initialization.
* Here is a very simple plugin that reads the clientId we specified in the player config:
*/
var analytics = function(options) {
// The setting is available exactly as specified in the player config
reportAnalyticsEvent({
clientId: options.clientId
});
// You also have access to page-level variables.
// Note that a Brightcove player can be embedded in its own iframe or directly into a
// publisher's page. Properties like document.referrer may be different depending on how
// the player is embedded:
reportAnalyticsEvent({
clientId: options.clientId,
referrer: document.referrer
});
// Media and advertisement info may be present as well.
// See https://gist.github.com/dmlap/423d893e2b197d1edce9 for an example of how to access
// those properties.
};
/* For more info on creating plugins, check out:
* - The video.js plugin documentation: https://github.com/videojs/video.js/blob/stable/docs/guides/plugins.md
* - The list of open-source video.js plugins: https://github.com/videojs/video.js/wiki/Plugins
* - Brightcove's plugin quick-start guide: http://docs.brightcove.com/en/video-cloud/player-management/guides/plugin-dev-quick-start.html
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment