Player JavaScript API

You can control the Animoto Flash video player using JavaScript.

Retrieving the player element
First you need to target the HTML element. This can be done in a number of ways, for example:
function getPlayer(id) {
     return (navigator.appName.indexOf("Microsoft") != -1) ? window[id] : document[id];
}
You would pass this method the object/embed id, normally something like "vp1fKSkZ". Important: Do not change the object/embed code's id or JavaScript communication will fail in some browsers.
Preventing errors during calls
You cannot make calls to a player until after it has finished booting up and has connected to Javascript. This can be done in one of the following ways:
1. Wrap your call in a conditional statement that verifies the function exists. For example,
       if (getPlayer("vp1fKSkZ").playMedia) {
            getPlayer("vp1fKSkZ").playMedia();
       }
2. Add a callback to the page called playerReady, and use this to set a variable indicating that it's safe to make calls to the player.
3. If you have more than one player on a page, either inspect the info object passed to the playerReady callback to get the specific player's id, or alternatively set a unique function name in the embed using the custom flashvar ready_callback.
API
The following methods return a blank string if the call succeeds or an error string if the call fails.
playMedia()
pauseMedia()
toggleMediaPlay()
seekMedia(seconds)
setVolume(0..100)
The getState method lets you check the current play state the player is in. Note that the state 'BUFFERING' is equivalent to 'PLAYING', and the state 'COMPLETED' is equivalent to 'IDLE' but means the video has recently finished playing.
getState()
returns 'IDLE' | 'BUFFERING' | 'PLAYING' | 'PAUSED' | 'COMPLETED'
The loadMedia method allows you to trigger the player to load a new video using an Animoto oKey. It returns blank string for success or an error string for failure.You can control the animoto Flash video player using JavaScript.
Retrieving the player element
First you need to target the HTML element. This can be done in a number of ways, for example:
function getPlayer(id) {
     return (navigator.appName.indexOf("Microsoft") != -1) ? window[id] : document[id];
}
You would pass this method the object/embed id, normally something like "vp1fKSkZ". Important: Do not change the object/embed code's id or JavaScript communication will fail in some browsers.
Preventing errors during calls
You cannot make calls to a player until after it has finished booting up and has connected to Javascript. This can be done in one of the following ways:
1. Wrap your call in a conditional statement that verifies the function exists. For example,
       if (getPlayer("vp1fKSkZ").playMedia) {
            getPlayer("vp1fKSkZ").playMedia();
       }
2. Add a callback to the page called playerReady, and use this to set a variable indicating that it's safe to make calls to the player.
3. If you have more than one player on a page, either inspect the info object passed to the playerReady callback to get the specific player's id, or alternatively set a unique function name in the embed using the custom flashvar ready_callback.
API
The following methods return a blank string if the call succeeds or an error string if the call fails.
playMedia()
pauseMedia()
toggleMediaPlay()
seekMedia(seconds)
setVolume(0..100)
The getState method lets you check the current play state the player is in. Note that the state 'BUFFERING' is equivalent to 'PLAYING', and the state 'COMPLETED' is equivalent to 'IDLE' but means the video has recently finished playing.
getState()
returns 'IDLE' | 'BUFFERING' | 'PLAYING' | 'PAUSED' | 'COMPLETED'
The loadMedia method allows you to trigger the player to load a new video using an Animoto oKey. It returns blank string for success or an error string for failure.
loadMedia("fKSkZQJprUSxEQyrS5eYUw");
loadMedia("fKSkZQJprUSxEQyrS5eYUw");

Note: Use this API at your own risk, there is a chance that it may be changed or unsupported in the future.


Retrieving the player element

First you need to target the player's HTML element using the object/embed id, which is normally something like "vp1fKSkZ".

 

var player = document.getElementById("vp1fKSkZ");

 If you want to change the id object/embed id you must add a custom flashvar called 'id' with the new value in both the object and embed tags.


Use SWFObject


We've found that using SWFObject is the best way to ensure that your embed will work correctly in all browsers and operating systems.

You should use the object/embed id as your div id, or if you use a custom id you should include a new flashvar 'id' referring to the new name.

Here's an example SWFObject embed. (Note that it's easiest to just paste the full swf url with flashvars. In the following example some of the url characters are replaced with spaces to prevent this wiki from generating a link, your url should not be reformatted in this way.)

swfobject.embedSWF( "http //p-static animoto com/swf/w.swf?w=swf/vp1&e=1239733952&f=gEAqirVa6E30h4RlCAuv0g&d=31&m=b&r=w&i=m&options=arthropod",
                    "vp1gEAqi", "432", "240" "9.0.115", false,
                    null, { allowFullScreen:true, allowScriptAccess:"always" }, null);
<div id="vp1gEAqi">Update your flash player.</div>

 

Preventing errors during calls

You cannot make calls to a player until after it has finished booting up and has connected to Javascript. This can be done in one of the following ways:

 

1. Wrap your call in a conditional statement that verifies the function exists. For example, 

      if (document.getElementById("vp1fKSkZ").playMedia) {
            document.getElementById("vp1fKSkZ").playMedia(); 
      }

2. Add a callback to the page called playerReady, and use this to set a variable indicating that it's safe to make calls to the player.

    function playerReady(info) {
alert("Player " + info.id + " is ready!");
}

3. If you have more than one player on a page, either inspect the info object passed to the playerReady callback to get the specific player's id. Alternatively you can set a unique callback name in each embed using the custom flashvar ready_callback (be sure to add this to both the object and embed tags in each embed instance).

    function playerReady(info) {
if (info.id == "vp1fKSkZ") { alert("Primary player is ready");
}
else if (info.id == "vp1fKSkZ") { alert("Secondary player is ready"); } }

 

API

The following methods return a blank string if the call succeeds or an error string if the call fails.

 

playMedia(); // makes video start playing
pauseMedia(); // pauses video
toggleMediaPlay(); // plays or pauses depending on current play state
seekMedia(seconds); // seeks video to position (if it has loaded to that point)
setVolume(0..100); // sets player volume, for example pass 0 to mute player.

 

The getState method lets you check the current play state the player is in. Note that the state 'BUFFERING' is equivalent to 'PLAYING', and the state 'COMPLETED' is equivalent to 'IDLE' but means the video has recently finished playing.

getState();

returns: 'IDLE' | 'BUFFERING' | 'PLAYING' | 'PAUSED' | 'COMPLETED'

 

 

We've made an effort to keep things simple here, but if this document did not address your specific needs please feel free to drop us a support request.

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk