// A Few reusable utils, memoized onto Popcorn
Popcorn.extend( Popcorn, {
guid: function() {
- return +new Date();
+ return +new Date() + Math.floor(Math.random()*11);
},
sizeOf: function ( obj ) {
var size = 0;
}
// setup for custom event system
- this.data.events[type][ fn.toString() ] = fn;
+ this.data.events[type][ fn.toString() + Popcorn.guid() ] = fn;
if ( Popcorn.events.all.indexOf( type ) > -1 ) {
-
this.video.addEventListener( type, function( event ) {
-
+
Popcorn.forEach( self.data.events[type], function ( obj, key ) {
-
obj.call(self, event);
-
});
}, false);
Popcorn.extend( Popcorn.p, plugin );
+
+
+
+
// within the context of a plugin, the `timeupdate` or any of the events can be listened to
};
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn API DEMO</title>
+
+ <script src="jquery.js"></script>
+ <script src="../popcorn-api-draft.js"></script>
+ <script src="demo.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn API</h1>
+
+ <style>
+ /* test positioning */
+
+ video {
+ position: fixed;
+ left: 100px;
+ top: 100px;
+ }
+
+ </style>
+
+ <div>
+ <video id='video'
+ controls preload='none'
+ poster="http://media.w3.org/2010/05/sintel/poster.png">
+
+ <source id='mp4'
+ src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="http://media.w3.org/2010/05/sintel/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ </div>
+
+
+
+
+
+
+</body>
+</html>
--- /dev/null
+
+// EXAMPLE PLUGIN: SUBTITLER
+
+(function (Popcorn) {
+
+
+
+
+ Popcorn.plugin( "subtitler" , function ( options ) {
+
+ var subtitles = [],
+ context = this.video,
+ div = document.getElementById("subtitle-container");
+
+
+ // Check for existing frame
+ if ( !div ) {
+ // if no existing frame, create it.
+ div = document.createElement("div");
+ div.id = "subtitle-container";
+
+ Popcorn.extend(div.style, {
+ //border: "1px solid red",
+ width: context.clientWidth + "px",
+ height: context.clientHeight + "px",
+ top: context.offsetTop + "px",
+ left: context.offsetLeft + "px",
+ position: "absolute",
+ color: "white",
+ textShadow: "black 2px 2px 6px",
+ fontSize: "18px",
+ fontWeight: "bold",
+ textAlign: "center"
+ });
+
+ context.parentNode.appendChild(div);
+ }
+
+ if ( typeof options === "object" && "join" in options ) {
+ subtitles = options;
+ } else {
+ subtitles.push(options);
+ }
+
+ this.listen("timeupdate", function (event) {
+
+
+ Popcorn.forEach(subtitles, function ( subtitle ) {
+
+ var temp = div.querySelectorAll( subtitle.id );
+
+ if ( this.currentTime() >= subtitle.start && !temp.length ) {
+ div.innerHTML = div.innerHTML + subtitle.html;
+ }
+
+ if ( this.currentTime() >= subtitle.end ) {
+
+ if ( temp.length ) {
+ Popcorn.forEach(temp, function ( title ) {
+ title.style.display = "none";
+ });
+ }
+ }
+
+ }, this);
+ });
+ });
+
+})(Popcorn);
+
+
+// END EXAMPLE
+
+
+$(function () {
+
+
+
+ var p = Popcorn('#video');
+
+
+ p.play();
+
+
+ p.subtitler({
+ id: "#subtitle-a",
+ start: 2, // seconds
+ end: 5, // seconds
+ html: '<p id="subtitle-a">Appear at 2 second mark, dissappear at 5 second mark</p>'
+ });
+
+
+
+ // Butter would generate the data to populate this api function call's argument
+
+ p.subtitler([
+ {
+ id: "#stays-forever",
+ start: 5,
+ html: '<p id="stays-forever">Stays forever!</p>'
+ },
+ {
+ id: "#comes-and-goes-1",
+ start: 10,
+ end: 12,
+ html: '<p id="comes-and-goes-1">Comes and goes</p>'
+ },
+ {
+ id: "#comes-and-goes-2",
+ start: 12,
+ end: 14,
+ html: '<p id="comes-and-goes-2">BACK! For the second time...</p>'
+ },
+ {
+ id: "#comes-and-goes-3",
+ start: 14,
+ end: 16,
+ html: '<p id="comes-and-goes-3">This is the last time. I promise.</p>'
+ }
+
+ ]);
+
+
+
+
+});
\ No newline at end of file