Book Image

HTML5 Multimedia Development Cookbook

Book Image

HTML5 Multimedia Development Cookbook

Overview of this book

HTML5 is the most significant new advancement the web has seen in many years. HTML5 adds many new features including the video, audio, and canvas elements, as well as the integration of SVG. This cookbook is packed full of recipes that will help you harness HTML5’s next generation multimedia features. HTML5 is the future.Whether you’re a seasoned pro or a total newbie, this book gives you the recipes that will serve as your practical guide to creating semantically rich websites and apps using HTML5. Get ready to perform a quantum leap harnessing HTML5 to create powerful, real world applications. Many of the new key features of HTML5 are covered, with self-contained practical recipes for each topic. Forget hello world. These are practical recipes you can utilize straight away to create immersive, interactive multimedia applications. Create a stylish promo page in HTML5. Use SVG to replace text dynamically. Use CSS3 to control background size and appearance. Use the Canvas to process images dynamically. Apply custom playback controls to your video.
Table of Contents (16 chapters)
HTML5 Multimedia Development Cookbook
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface

Random animation with audio using the canvas tag and JavaScript


In this recipe we will use the canvas tag to draw and animate a series of shapes. We will also loop an audio file using the audio tag to play while the animation displays. We are adapting an original animation created by Michael Nutt. We will be creating a slower, more relaxing animation that looks like waving grass.

Getting ready

You will need a recently updated browser, such as Firefox 3.6 or Google Chrome, and an audio file in multiple formats. It does display at a different (smaller) size in Opera browsers 9 and 10. The audio will also not play in those versions of Opera.

How to do it...

First, open a new HTML5 page and name it random-animation-with-audio.html. Enter the beginnings of an HTML5 page including the page title:

<!DOCTYPE html> <html lang="en"> <head><meta charset="utf-8" /> <title>Canvas Reggae</title>.

Then, add links to the JavaScript and CSS files that will be imported...