O'Reilly logo

HTML5: Your visual blueprint™ for designing rich web pages and applications by Adam McDaniel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CONTROL AUDIO AND VIDEO PLAYBACK WITH JAVASCRIPT

It may seem pointless to make the controls attribute optional in the <audio> and <video> tags. When omitted, no playback buttons will appear in the web browser. This is actually intentional, as you can still control the playback of either element using some simple JavaScript methods and event listeners.

This moves control over the playback experience from the user to the website itself. Your goal as a web developer should be to only trigger playback when it is appropriate, such as during an HTML5 Canvas game or when chaining playback of multiple video files together.

Before you begin, you must locate the audio or video element in the JavaScript DOM. The easiest way to do this is to assign the element ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required