videojs/video.js — pull request #1560 by heff (2014-10-03 01:26:02+00:00)
Title: Implementing a Source Handlers interface for supporting adaptive formats

The source handler pattern came from the need to support adaptive formats using the Media Source Extensions (or faux MSE with Flash) while keeping the code optional and external to core since it's very heavy. I'm hoping to get some feedback on the current implementation, especially from anyone working on the HLS plugin (e.g. @dmlap, @gkatsev, @seniorflexdeveloper)

The source handler interface:
```js
// Define a source handler
var mySourceHandler = {
// does the handler support source object type, return probably, maybe, or ''
canHandleSource: function(sourceObject){},

// receive the source and tech. Do whatever is needed to handle the source format.
// through the tech you have direct access to the video element (or flash object), events, and the tech API
handleSource: function(source, tech){},

// cleanup when the player disposes or switches sources
dispose: function(){}
};

// Register the source handler with the specific tech (source handlers are tech specific)
vjs.Html5.registerSourceHandler(mySourceHandler);
// or
vjs.Flash.registerSourceHandler(mySourceHandler);
```
After registering a source handler it will be included when the tech is asked if it can support a source (Html5.canPlaySource) and handed source types that it supports (Html5.prototype.setSource).

I've currently only implemented it on the HTML5 side, but Flash should look identical.

Native format support is also set up as a source handler here, which allows it to be prioritized in case we want our own HLS support to come before native, for example.