O'Reilly logo

HTML5 iPhone Web Application Development by Alvin Crespo

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

Creating a JavaScript video library

At the moment, we have a very simple Video class that caches an element and then attaches multiple events that are defined by the media element specification for HTML5. We have defined the essentials of a video player and now need to abstract it a bit further so it can be reused and managed much better. Following some conventions and creating a flexible framework will help us move faster and more effectively.

First, let's think about some things we may want from this class:

  • An events method that attaches the proper events
  • Callback methods that can be defined, for example, onPlay, onPause, and onEnded
  • Public methods that can be called from outside the instance
  • Chainable methods similar to jQuery where you can call ...

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