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 ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.