<pclass="legacydocsnote">This documentation is for an outdated version of Video.js. See <ahref="https://docs.videojs.com">documentation for the current release</a>.
<p>The Video.js API allows you to interact with the video through JavaScript, whether the browser is playing the video through HTML5 video, Flash, or any other supported playback technologies.</p>
<h2id="referencing-the-player">Referencing the Player</h2>
<p>To use the API functions, you need access to the player object. Luckily this is easy to get. You just need to make sure your video tag has an ID. The example embed code has an ID of "example_video_1". If you have multiple videos on one page, make sure every video tag has a unique ID.</p>
<p>(If the player hasn't been initialized yet via the data-setup attribute or another method, this will also initialize the player.)</p>
<h2id="wait-until-the-player-is-ready">Wait Until the Player is Ready</h2>
<p>The time it takes Video.js to set up the video and API will vary depending on the playback technology being used (HTML5 will often be much faster to load than Flash). For that reason we want to use the player's 'ready' function to trigger any code that requires the player's API.</p>
<p>Now that you have access to a ready player, you can control the video, get values, or respond to video events. The Video.js API function names follow the <ahref="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html">HTML5 media API</a>. The main difference is that getter/setter functions are used for video properties.</p>
<pre><codeclass="lang-js">
// setting a property on a bare HTML5 video element
myVideoElement.currentTime = "120";
// setting a property on a Video.js player
myPlayer.currentTime(120);
</code></pre>
<p>The full list of player API methods and events can be found in the <ahref="http://docs.videojs.com/docs/api/index.html">player API docs</a>.</p>