Page History
Panel | ||
---|---|---|
|
Code Block | ||||
---|---|---|---|---|
| ||||
<!DOCTYPE html> <html> <head> <script src="//e.video-cdn.net/v2/embed.js"></script> </head> <body> <div id="player_container1234"></div> <script type="text/javascript"> //create a new player instance (vmpro) function createPlayer() { var optionsplayerProps = { success: function (playerApi) { playerApi.play(); playerApi.forward(20000); playerApi.toggleMute(); }, parameters: { configType: 'vmpro', playerId: '<PlayerID>', videoId: '<VideoID>', apiUrl: '//d.video-cdn.net/play', flashPath: '//e.video-cdn.net/v2/' } }; VideoPlayer.Collection.addPlayerById('player_container', options); } //add the player var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src =}; loadPlayer = function () { var element = document.getElementById('1234'); var player = document.createElement('div'); player.setAttribute('mi24-video-player', ''); player.setAttribute('config-type', 'vmpro'); player.setAttribute('player-id', '<PlayerID>'); player.setAttribute('video-id', '<VideoId>'); player.setAttribute('api-url', '//d.video-cdn.net/play'); player.setAttribute('flash-path', '//e.video-cdn.net/v2/embed.js'); head element.appendChild(scriptplayer); script.onload = (function () { createPlayer(); }); </script> VideoPlayer.Collection.addPlayerById('1234', playerProps); }; </script> <button onclick="loadPlayer()">load</button </body> </html> |
Note |
---|
Please note that you need to specify necessary IDs and URLs. |
Adding the Player Script
First you will want to take note of the way that the Player script has been added. Note the "script" tag at the end of your embed code:
Code Block | ||
---|---|---|
| ||
<script src="//e.video-cdn.net/v2/embed.js"></script> |
This tag specifies the source of the API script, the "embed.js" file. This must be included to make calls to the API work. However, it only needs to be added to the page once, regardless of how many players will be added to the page.
The code above adds the "embed.js" file by appending it to the "head" tag dynamically with JavaScript (lines 32-36). We have found this to be the best way to add the "embed.js" file because it facilitates correct timing and order of operations by allowing you to use the script's "onload" property to initiate the creation of your Player (line 39).
Creating the Player
Note the "createPlayer" function (line 12), which is called when the script loads. This function creates an "options" object to pass into the API's "addPlayerById" function (see the Adding or Removing a Player chapter for more details). The property "success" must be set within this object. This is where you can create your callback function, which you can use to call other API functions, which will execute as soon as the Player is successfully created. The above code will play, fast forward 20 seconds, and mute the audio (see the Basic Functions chapter for a list of other functions you can call here).
The "parameters" property (line 19) is created using the properties from your embed code. This allows you to set up an empty div, "player_container" as a placeholder and add these properties dynamically when the player is created.