Loading...

This presentation is an HTML5 website

Press key to advance.

Having issues seeing the presentation? Read the disclaimer

Slides controls, press:

  • and to move around.
  • Ctrl/Command and + or - to zoom in and out if slides don’t fit.
  • T to change the theme.
  • H to toggle syntax highlight.

Interactive & Immersive HTML5 Video

The JavaScript Company

Rick Waldron

Bocoup JavaScript Evangelist

jQuery Bugs Team & Contributor

@rwaldron on twitter/irc

http://spkr8.com/t/7215

Video on the Web 101
  • 1991 QuickTime 1.0 (Macintosh II, System 6)
  • 1995 RealPlayer (Streaming Video To The Web)
  • 1995 JavaScript (http://gul.ly/hr)
  • 1996 Flash
  • 2000 Real, QuickTime, Windows Media Player
  • 2002 Flash MX(6) Video, Sorenson Spark
  • 2003 Flash External FLV, VP6 codec
  • 2005 YouTube ("Me At The Zoo", April 23rd 2005)
  • 2008 HTML5 Video (http://gul.ly/101)
Proprietary Open

HTML5 Video !== Flash Video

Not Interactive

"Read Only"

Popcorn.js makes HTML5 Video...

Programmable

Interactive

Event Driven

Immersive

So...What IS Popcorn.js?








Popcorn.js

Start the video to watch popcorn.js change your webpage!









Original "WTF is Popcorn.js?" by Brett Gaylor
A Brief History of Popcorn.js
  • Envisioned By Brett Gaylor, Web Made Movies
  • Given life by CDOT* at Seneca College, Toronto
  • 2010 0.1, Web Made Movies Proof of Concept
  • 2011 0.2, 100% Re-written as framework
  • 2011 0.3, Major Plugin Release
  • 2011 0.4, Supports Youtube & Vimeo Api
  • 2011 0.5, Subtitle Overhaul & Composable Plugins
* Center for the Development of Open Technology
Popcorn.js 0.1
  • All commands included in core
  • Single execution, ran on DOM ready
  • A proof of concept
Popcorn.js 0.2 And Beyond
  • Reduce core to a framework
  • Plugin API
    • Commands
    • Data Loading Parsers
    • Player Engines
  • Extensive Test Suite
+ Current stable is 0.4.1 (0.5 Releasing Next Week!);
Framework Goals

 

  • Playback Event Handling
  • Instance Management
  • Easily Extended with Plugins
  • Most importantly: Easy to use
Easy code can tell a story

Think about jQuery's stories...

  • Write less, do more.*
  • Find things, do stuff.








* Dave Methvin; Thanks to Karl Swedberg for that tidbit of historical goodness
Easy code can tell a story

This is Popcorn.js's story...

  • A video
  • Does something
  • At a time
  • With some information
Note: The Popcorn.js 0.2+ API was envisioned by Boaz Sender and Ben Alman @ Bocoup
Designing The Syntax

A video...Does Something...At a time...With some information


// Think something like...
aVideo.doesSomething({  at this time, with this information });

Evolved into...


// A Popcorn Video Object...
Popcorn("#video-id");


// ... does something, at this time, with this information
Popcorn("#video-id").doSomething({
  start: 0,
  end: 4,
  info: "..."
});

This design makes Popcorn REALLY easy to extend...

What about the native video API?
Popcorn.js doesn't reinvent the HTML5 Video API, it embraces the syntax and idioms
  • play(), pause()
  • ...Are still play(), pause()
  • currentTime, volume, playbackRate
  • ...Becomes currentTime(), volume(), playbackRate()
  • Never extend the native.
  • Always return a Popcorn video object.
The Popcorn Object
var $pop = Popcorn("#an-id-selector");

So what does $pop look like?
{
  data: {
    events: {},     // Event handler data
    trackEvents: {
      //  Array index corresponds to an integer
      //  ...which corresponds to a whole second
      byEnd: [],    // Queue of end functions (runs first)
      byStart: []   // Queue of start functions
    }
  },

  video: [object HTMLVideoElement],

  __proto__: {

    /*
      Methods...
      load, play, pause, currentTime, playbackRate, mute, volume,
      roundTime, exec, trigger, listen, unlisten, getTrackEvents,
      removeTrackEvent, removePlugin
    */
  }
}
A little of this and a little of that
var $pop = Popcorn("#tron");

$pop.listen( "ended", function() {

  //  Show YouTube-like "Related Videos" screen
  this.related({
    list: [
      "Tron",
      "Matrix",
      "Hackers"
    ]
  });
}).exec( 4, function() {

  this.pause();

  if ( confirm("Wanna see more?") ) {

    this.play();

  } else {

    this.currentTime(

      this.duration() - 2

    ).play();
  }
});

Is a little like this
* One sec, this needs the entire slide. Also, click "cancel" for fun stuff

But wait... that's not all!

Popcorn.js does plugins

...Easily

The Plugin API
  • Simple event commands
  • Really easy to write
(function( Popcorn ) {

  Popcorn.plugin( "comments", {

    _setup: function( options ) {
      //  Do something immediately when the plugin is called
    },
    start: function( event, options ) {
      //  Fires at the specified start time
    },
    end: function( event, options ) {
      //  Fires at the specified end time
    }
  });

})( Popcorn );

Plugin Templates @ http://gul.ly/109

Plugin In Action
Click inside the code below and press shift-enter to add a wikipedia event
var $pop = Popcorn("#video");

$pop.wikipedia({
  start: 6,
  end: 15,
  target: "output",
  numberofwords: 150,
  src: "http://en.wikipedia.org/wiki/Brendan_Eich"
});

Official Plugins
* Special Thanks to Anna Sobiepanek & Scott Downe
  • Creative Commons Attribution
  • Flickr Photo Stream
  • Footnotes
  • Google Maps
  • Google News
  • Image
  • Last.fm Playlist
  • Lowerthird
  • Mustache Templates
  • Subtitles
  • Twitter Feed
  • Webpage Frame
  • Wikipedia

Popcorn.js is declarative, too.

playback.json
[{
    "image":  {
      "start": 0,
      "end": 2,
      "src":"src/json160.gif"
    }
  },
  {
    "footnote": {
      "start": 0,
      "end": 2,
      "text":"I invented JSON"
    }
  },
  {
    "image":  {
      "start": 2,
      "end": 10,
      "src":"src/jslint.gif"
    }
  },
  {
    "footnote": {
      "start": 2,
      "end": 10,
      "text":"I wrote JSLint"
    }
  }
]
Declarative In Action
  <video id="crock-video" data-timeline-sources="playback.json">
    <source src="src/crockford.ogv" type="video/ogg;" />
  </video>


So... What about Youtube & Vimeo?

Popcorn can do that, too.

This is a monkey, riding a dog.
Popcorn(
  Popcorn.youtube( "whiplash", "http://www.youtube.com/watch?v=BYNoQZ5djUA" )
);

//   Add a few commands with the footnote plugin...