Book Image

Canvas Cookbook

Book Image

Canvas Cookbook

Overview of this book

With the growing popularity of HTML5 Canvas, this book offers tailored recipes to help you develop portable applications, presentations, and games. The recipes are simple yet creative and build on each other. At every step, the book inspires the reader to develop his/her own recipe. From basic to advanced, every aspect of Canvas API has been covered to guide readers to develop their own application, presentation, or game.
Table of Contents (16 chapters)
Canvas Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Working with videos


In this recipe, you will be introduced to another element of HTML5, <video>.

To embed video, we need the video tag, and to work on it, we need the canvas API. The output of this recipe looks like this:

How to do it

The recipe is as follows:

The HTML code:

<html>
<head>
<title>Video</title>
</head>
<body>
<center>
<video id="myVideo" autoplay="true" loop="true" width=200 height=200>
      <source src="happynewyear.mp4" type="video/mp4"/>
      The browser doesn't support video
</video>
<h1>A Video</h1>
</center>
</body>
</html>

How it works...

It's the video tag that does the trick. The video is played in a loop, and there are no controls available to pause or stop the video. If you need to see the controls, add the attribute controls to the video element (<video controls id="myVideo" …..).

One important point to remember is that your webserver MIME types should list the type of...