Redirect Notice

Redirect Notice

The page you requested has been relocated to Player Docs.

Creating Custom Plugins

The player's functionality can be extended via custom plugins. The steps for creating and attaching a plugin are as follows:

  1. Create a plugin factory function which will be called when it is time to create a new instance of the plugin. The factory function accepts two arguments: The instance of the player and the configuration object for the plugin. For example:

    function createSamplePlugin(player, config, key) {
     return new Promise(function (resolve, reject) {
         console.log("Creating Sample Plugin", player, config, key);
         if (true) {
             resolve({
                 config: config,
                 testing: function () {
                     console.log("Sample Plugin Public API Function: " + this.config.testing);
                 }
             });
         } else {
             reject("An error occured creating the sample plugin.");
         }
     });
    }
  2. Register the plugin with the AMP sdk by giving it a key and passing in the factory function:

    akamai.amp.AMP.registerPlugin("sample", createSamplePlugin);

    By default the plugin will be available in all modes of the player. If the plugin only applies to certain modes of the player, for instance flash only, pass in the modes as the third argument:

    akamai.amp.AMP.registerPlugin("sample", createSamplePlugin, ["flash"]);
  3. Configure the plugin via the player's configuration by creating a property with the plugin's key in the plugins section:

    var config = {
     plugins: {
         sample: {
             testing: 1234
         }
     }
    };
    var amp = akamai.amp.AMP.create("akamai-media-player", config);

    If the plugin does not need configuration options simply pass in a boolean:

    var config = {
     plugins: {
         sample: true
     }
    };
    var amp = akamai.amp.AMP.create("akamai-media-player", config);

    Plugins can also be enabled and disabled via the enabled flag:

    var config = {
     plugins: {
         sample: {
             enabled: true
         }
     }
    };
    var amp = akamai.amp.AMP.create("akamai-media-player", config);

    If the plugin's code lives in a different file, it can also be loaded via the config:

    var config = {
     plugins: {
         sample: {
             resources: [
                 {src: "sample.js", type: "text/javascript"}
             ],
             testing: 1234
         }
     }
    };
    var amp = akamai.amp.AMP.create("akamai-media-player", config);
  4. New API functions or properties exposes by the plugin can be accessed via the plugin's key after the ready event has fired:

    var amp = akamai.amp.AMP.create("akamai-media-player", config, function () {
     amp.sample.testing();
    });

For convenience AMP provides a Plugin base class which contain common functionality such as event dispatching. akamai.amp.Plugin