Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Controlling the Player Using JavaScript

Playing, pausing and stopping the player are trivial operations with the JavaScript API. In fact, the only playback function that cannot be called from JavaScript is the fullscreen toggle. This is due to security limitations.

This example demonstrates calling player functions through JavaScript

Demo

Control the video from JavaScript:

Code

Here's the code for this demo. The jwplayer().play(), jwplayer().setMute() and jwplayer().stop() functions take care of the controls.

<div id="container"></div>

<script type="text/javascript">
  jwplayer("container").setup({
    file: "/videos/bunny.mp4",
    flashplayer: "jwplayer/jwplayer.swf",
    image: "/thumbs/bunny.jpg",
    height: 270,
    width: 480
  });
</script>

<ul>
  <li><a href="#" onclick="jwplayer().play();">Toggle the playback</a></li>
  <li><a href="#" onclick="jwplayer().setMute();">Toggle the audio</a></li>
  <li><a href="#" onclick="jwplayer().stop();">Stop playback</a></li>
</ul>

Enhancements

Some ideas for enhancing this functionality: