You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The JavaScript API is accessed by initializing a "VideoPlayer.Collection" object. There are two functions which can be used to do this (both take the id of the HTML element containing your Player as an argument):


  1. This function lets you add the Player dynamically:

    VideoPlayer.Collection.addPlayerById("player_container");

    The "addPlayerById" function can take an optional second argument, an object which will initialize your Player. The object can contain parameters to initialize the Player (the attributes from the embed code) and/or a success callback function, which will be called when the Player is finished loading successfully. These options are covered in detail in the Onload Callback Function tutorial.

  2. And this function lets you access an existing Player:

    var player = VideoPlayer.Collection.getPlayerById("player_container");

    Please note that you must wait for the player to load before you can connect to it. If lazy loading is enabled, the player will not load until a user clicks play. Find more information on lazy loading here.


You can also remove a Player dynamically with the VideoPlayer.Collection object by calling this function:

VideoPlayer.Collection.removePlayerById("player_container");


After connecting the VideoPlayer.Collection object to an element containing a Player, you can then access any of the API functions, register events, and change the appearance of Player elements. The following chapter contains several tutorials that will demonstrate these features in greater detail.