Pass Data to the Plugin

In this topic you will learn how you can pass data to the plugin for use at plugin initialization.

Define options property

When calling a plugin you can also use an additional options child property with plugins. The options property must be an object, but can contain a complex data structure such as an array of objects.

Here is a portion of a curl statement that shows the plugins property with the required name child property and the optional options child property. The data passed in the options property can then be used in the plugin.

"plugins": [{
  "name": "navigateOnVideoEnd",
  "options" : {"redirectURL": "http://docs.brightcove.com"}
}]

You can also use the options property when using the embed_in_page player implementation, where the player tag sits in the HTML page, not in an iframe. To do this simply build the data object, and pass it in as an argument. An example is shown here:

<script type="text/javascript">
  var options = {"redirectURL": "http://docs.brightcove.com"};
</script>
<script>videojs.getPlayer('myPlayerID').navigateOnVideoEnd(options);</script>

Use options data

The options property gives you the ability to pass data to a plugin via the player configuration for use at plugin initialization. For instance, to use the redirectURL object shown above, you would do the following in the plugin itself:

videojs.registerPlugin('navigateOnVideoEnd', function (options) {
  var myPlayer = this;
  myPlayer.on("ended", function () {
    window.location.href = options.redirectURL;
  });
});

Note: you use the standard plugin implementation, but use options as a parameter in the anonymous function. You can then access the value using options.propertyName notation.