# HG changeset patch # User hamidouk # Date 1322823725 -3600 # Node ID 9b4e5f606d72fb3fa1f1eb00a77ce11ed1689ebf # Parent 2f855c3efd48d3f6018a0e0d8d1dc68087b8c49d first draft, a little rough around the edges. diff -r 2f855c3efd48 -r 9b4e5f606d72 src/js/pop.js --- a/src/js/pop.js Fri Dec 02 12:01:43 2011 +0100 +++ b/src/js/pop.js Fri Dec 02 12:02:05 2011 +0100 @@ -2,6 +2,8 @@ popcorn is a bit unstable at the time */ Popcorn = {}; +Popcorn.media = {}; + Popcorn.listen = function(msg, callback) { IriSP.jQuery(Popcorn).bind(msg, callback); }; @@ -24,13 +26,14 @@ }; Popcorn.jwplayer = function(container, options) { - Popcorn._container = container; + Popcorn._container = container.slice(1); //eschew the '#' options.events = { - onReady: Popcorn.__initApi + onReady: Popcorn.__initApi, + onTime: Popcorn.__timehandler }; jwplayer(Popcorn._container).setup(options); - + return Popcorn; }; Popcorn.currentTime = function(time) { @@ -38,23 +41,23 @@ return jwplayer(Popcorn._container).getPosition(); } else { var currentTime = +time; - media.dispatchEvent( "seeked" ); - media.dispatchEvent( "timeupdate" ); + Popcorn.trigger("seeked"); + Popcorn.trigger("timeupdate"); jwplayer( Popcorn._container ).seek( currentTime ); return jwplayer(Popcorn._container).getPosition(); } }; Popcorn.play = function() { - Popcorn.paused = false; + Popcorn.media.paused = false; Popcorn.trigger("play"); Popcorn.trigger("playing"); jwplayer( Popcorn._container ).play(); }; Popcorn.pause = function() { - if ( !media.paused ) { - media.paused = true; + if ( !Popcorn.media.paused ) { + Popcorn.media.paused = true; Popcorn.trigger( "pause" ); jwplayer( Popcorn._container ).pause(); } @@ -62,9 +65,10 @@ Popcorn.muted = function(val) { if (typeof(val) !== "undefined") { - if ( jwplayer( Popcorn._container ).getMute() !== val ) { - if ( val ) { - jwplayer( Popcorn._container ).setMute(true); + + if (jwplayer(Popcorn._container).getMute() !== val) { + if (val) { + jwplayer(Popcorn._container).setMute(true); } else { jwplayer( Popcorn._container ).setMute(false); } @@ -76,6 +80,30 @@ } else { return jwplayer( Popcorn._container ).getMute(); } -}); +}; + +Popcorn.__codes = []; +Popcorn.code = function(options) { + Popcorn.__codes.push(options); + return Popcorn; +}; + +/* called everytime the player updates itself + (onTime event) + */ +Popcorn.__timehandler = function() { + var currentTime = jwplayer(Popcorn._container).getPosition(); + var i = 0; + for(i = 0; i < Popcorn.__codes.length; i++) { + var c = Popcorn.__codes[i]; + if (currentTime <= c.start && currentTime + 0.1 >= c.start) { + c.onStart(); + } + + if (currentTime <= c.end && currentTime + 0.1 >= c.end) { + c.onEnd(); + } + } +};