src/js/pop.js
branchpopcorn-port
changeset 578 8dd6ebb7a79d
parent 477 1e51d638e7ea
child 580 47fb5cd44900
equal deleted inserted replaced
577:227d21a90fc5 578:8dd6ebb7a79d
    42 
    42 
    43 IriSP.PopcornReplacement.__initApi = function() {
    43 IriSP.PopcornReplacement.__initApi = function() {
    44   IriSP.PopcornReplacement.trigger("loadedmetadata"); // we've done more than loading metadata of course,
    44   IriSP.PopcornReplacement.trigger("loadedmetadata"); // we've done more than loading metadata of course,
    45                                                       // but popcorn doesn't need to know more.
    45                                                       // but popcorn doesn't need to know more.
    46   IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute();
    46   IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute();
       
    47   
       
    48   /* some programmed segments are supposed to be run at the beginning */
       
    49   var i = 0;
       
    50   for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
       
    51     var c = IriSP.PopcornReplacement.__codes[i];
       
    52     if (0 == c.start) {
       
    53       c.onStart();
       
    54     }
       
    55     
       
    56     if (0 == c.end) {
       
    57       c.onEnd();
       
    58     }
       
    59   }
    47 };
    60 };
    48 
    61 
    49 IriSP.PopcornReplacement.jwplayer = function(container, options) {
    62 IriSP.PopcornReplacement.jwplayer = function(container, options) {
    50   IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#'
    63   IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#'
    51   options.events = {
    64   options.events = {
   114 IriSP.PopcornReplacement.code = function(options) {
   127 IriSP.PopcornReplacement.code = function(options) {
   115   IriSP.PopcornReplacement.__codes.push(options);
   128   IriSP.PopcornReplacement.__codes.push(options);
   116   return IriSP.PopcornReplacement;
   129   return IriSP.PopcornReplacement;
   117 };
   130 };
   118 
   131 
   119 IriSP.PopcornReplacement.__runCode = function() {
       
   120   var currentTime = jwplayer(IriSP.PopcornReplacement._container).getPosition();
       
   121   var i = 0;
       
   122   for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
       
   123     var c = IriSP.PopcornReplacement.__codes[i];
       
   124     if (currentTime == c.start) {
       
   125       c.onStart();
       
   126     }
       
   127     
       
   128     if (currentTime == c.end) {
       
   129       c.onEnd();
       
   130     }
       
   131 
       
   132   }
       
   133 };
       
   134 
       
   135 /* called everytime the player updates itself 
   132 /* called everytime the player updates itself 
   136    (onTime event)
   133    (onTime event)
   137  */
   134  */
   138 
   135 
   139 IriSP.PopcornReplacement.__timeHandler = function(event) {
   136 IriSP.PopcornReplacement.__timeHandler = function(event) {
   140   var pos = event.position;
   137   var pos = event.position;
   141 
   138   
   142   var i = 0;
   139   var i = 0;
   143   for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
   140   for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
   144      var c = IriSP.PopcornReplacement.__codes[i];
   141      var c = IriSP.PopcornReplacement.__codes[i];
   145      
   142       
   146      if (pos >= c.start && pos < c.end && 
   143      if (pos >= c.start && pos < c.end && 
   147          pos - 0.1 <= c.start) {       
   144          pos - 0.1 <= c.start) {       
   148         c.onStart();
   145         c.onStart();
   149      }
   146      }
   150  
   147  
   151      if (pos > c.start && pos > c.end && 
   148      if (pos > c.start && pos > c.end && 
   152          pos - 0.1 <= c.end) {
   149          pos - 0.1 <= c.end) {
   153          console.log("eonedn");
   150          c.onEnd();
   154         c.onEnd();
       
   155      }
   151      }
   156    
   152    
   157   }
   153   }
   158  
   154  
   159   IriSP.PopcornReplacement.trigger("timeupdate");
   155   IriSP.PopcornReplacement.trigger("timeupdate");