src/js/pop.js
branchno-popcorn
changeset 417 bae7c50704d7
parent 394 89a79a2c6014
child 419 fe7e46eda1b4
equal deleted inserted replaced
394:89a79a2c6014 417:bae7c50704d7
    28 Popcorn.jwplayer = function(container, options) {
    28 Popcorn.jwplayer = function(container, options) {
    29   Popcorn._container = container.slice(1); //eschew the '#'
    29   Popcorn._container = container.slice(1); //eschew the '#'
    30   options.events = {
    30   options.events = {
    31       onReady: Popcorn.__initApi,
    31       onReady: Popcorn.__initApi,
    32       onTime: Popcorn.__timeHandler,
    32       onTime: Popcorn.__timeHandler,
    33       onSeek: function(event) { 
    33       onSeek: Popcorn.__seekHandler }
    34                               var i = 0;
       
    35                               console.log("old: %d, new: %d", event.position, event.offset);
       
    36                               for(i = 0; i < Popcorn.__codes.length; i++) {
       
    37                                  var c = Popcorn.__codes[i];
       
    38                                 
       
    39                                  if (event.position >= c.start && event.position < c.end) {
       
    40                                     c.onEnd();
       
    41                                  }
       
    42                                 
       
    43                                  if (typeof(event.offset) === "undefined")
       
    44                                    event.offset = 0;
       
    45                                  if (event.offset >= c.start && event.offset < c.end) {
       
    46                                    c.onStart();
       
    47                                  }
       
    48                                  
       
    49                                }
       
    50                          
       
    51                            Popcorn.trigger("timeupdate");
       
    52               }
       
    53   }
       
    54     
    34     
    55   jwplayer(Popcorn._container).setup(options);
    35   jwplayer(Popcorn._container).setup(options);
    56   Popcorn.media.duration = options.duration;
    36   Popcorn.media.duration = options.duration;
    57   return Popcorn;
    37   return Popcorn;
    58 };
    38 };
   127 
   107 
   128 /* called everytime the player updates itself 
   108 /* called everytime the player updates itself 
   129    (onTime event)
   109    (onTime event)
   130  */
   110  */
   131 
   111 
   132 Popcorn.__timeHandler = function() {
   112 Popcorn.__timeHandler = function(event) {
       
   113   var pos = event.position;
       
   114 
       
   115   var i = 0;
       
   116   for(i = 0; i < Popcorn.__codes.length; i++) {
       
   117      var c = Popcorn.__codes[i];
       
   118      
       
   119      if (pos >= c.start && pos < c.end && 
       
   120          pos - 0.1 <= c.start) {
       
   121         c.onStart();
       
   122      }
       
   123  
       
   124      if (pos >= c.start && pos >= c.end && 
       
   125          pos - 0.1 <= c.end) {
       
   126         c.onEnd();
       
   127      }
       
   128    
       
   129   }
       
   130  
   133   Popcorn.trigger("timeupdate");
   131   Popcorn.trigger("timeupdate");
   134 };
   132 };
       
   133 
       
   134 Popcorn.__seekHandler = function(event) { 
       
   135   var i = 0;
       
   136   for(i = 0; i < Popcorn.__codes.length; i++) {
       
   137      var c = Popcorn.__codes[i];
       
   138     
       
   139      if (event.position >= c.start && event.position < c.end) {
       
   140         c.onEnd();
       
   141      }
       
   142     
       
   143      if (typeof(event.offset) === "undefined")
       
   144        event.offset = 0;
       
   145      if (event.offset >= c.start && event.offset < c.end) {
       
   146        c.onStart();
       
   147      }
       
   148      
       
   149    }
       
   150 
       
   151   Popcorn.trigger("timeupdate");
       
   152 }
       
   153 
   135 
   154 
   136 Popcorn.roundTime = function() {
   155 Popcorn.roundTime = function() {
   137   var currentTime = Popcorn.currentTime();
   156   var currentTime = Popcorn.currentTime();
   138   return Math.round(currentTime);
   157   return Math.round(currentTime);
   139 };
   158 };