src/js/pop.js
author hamidouk
Wed, 07 Dec 2011 12:34:29 +0100
branchpopcorn-port
changeset 419 fe7e46eda1b4
parent 417 bae7c50704d7
child 431 f9460dc1957f
permissions -rw-r--r--
renamed all popcorn references in pop.js to not reference popcorn.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
387
d1fe53ad8d72 initial commit
hamidouk
parents:
diff changeset
     1
/* wrapper that simulates popcorn.js because
d1fe53ad8d72 initial commit
hamidouk
parents:
diff changeset
     2
   popcorn is a bit unstable at the time */
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
     3
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
     4
PopcornReplacement = {};
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
     5
PopcornReplacement.media = { "paused": true};
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
     6
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
     7
PopcornReplacement.listen = function(msg, callback) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
     8
  IriSP.jQuery(PopcornReplacement).bind(msg, function(event, rest) { callback(rest); });
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
     9
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    10
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    11
PopcornReplacement.trigger = function(msg, params) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    12
  IriSP.jQuery(PopcornReplacement).trigger(msg, params);
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    13
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    14
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    15
PopcornReplacement.guid = function(prefix) {
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    16
  var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    17
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    18
      return v.toString(16);
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    19
   });
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    20
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    21
  return prefix + str;
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    22
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    23
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    24
PopcornReplacement.__initApi = function() {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    25
  PopcornReplacement.trigger("timeupdate");
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    26
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    27
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    28
PopcornReplacement.jwplayer = function(container, options) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    29
  PopcornReplacement._container = container.slice(1); //eschew the '#'
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    30
  options.events = {
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    31
      onReady: PopcornReplacement.__initApi,
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    32
      onTime: PopcornReplacement.__timeHandler,
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    33
      onSeek: PopcornReplacement.__seekHandler }
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    34
    
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    35
  jwplayer(PopcornReplacement._container).setup(options);
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    36
  PopcornReplacement.media.duration = options.duration;
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    37
  return PopcornReplacement;
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    38
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    39
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    40
PopcornReplacement.currentTime = function(time) {
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    41
  if (typeof(time) === "undefined") {
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    42
      return jwplayer(PopcornReplacement._container).getPosition();            
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    43
  } else {
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    44
     var currentTime = +time;
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    45
     jwplayer( PopcornReplacement._container ).seek( currentTime );
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    46
     return jwplayer(PopcornReplacement._container).getPosition();            
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    47
  }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    48
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    49
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    50
PopcornReplacement.play = function() {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    51
      PopcornReplacement.media.paused = false;
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    52
//      PopcornReplacement.trigger("play");
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    53
//      PopcornReplacement.trigger("playing");
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    54
      jwplayer( PopcornReplacement._container ).play();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    55
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    56
    
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    57
PopcornReplacement.pause = function() {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    58
      if ( !PopcornReplacement.media.paused ) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    59
        PopcornReplacement.media.paused = true;
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    60
        PopcornReplacement.trigger( "pause" );
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    61
        jwplayer( PopcornReplacement._container ).pause();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    62
      }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    63
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    64
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    65
PopcornReplacement.muted = function(val) {
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    66
  if (typeof(val) !== "undefined") {
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    67
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    68
    if (jwplayer(PopcornReplacement._container).getMute() !== val) {
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    69
      if (val) {
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    70
        jwplayer(PopcornReplacement._container).setMute(true);
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    71
      } else {
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    72
        jwplayer( PopcornReplacement._container ).setMute(false);
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    73
      }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    74
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    75
      PopcornReplacement.trigger( "volumechange" );
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    76
    }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    77
    
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    78
    return jwplayer( PopcornReplacement._container ).getMute();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    79
  } else {
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    80
    return jwplayer( PopcornReplacement._container ).getMute();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    81
  }
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    82
};
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    83
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    84
PopcornReplacement.mute = PopcornReplacement.muted;
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
    85
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    86
PopcornReplacement.__codes = [];
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    87
PopcornReplacement.code = function(options) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    88
  PopcornReplacement.__codes.push(options);
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    89
  return PopcornReplacement;
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    90
};
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    91
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    92
PopcornReplacement.__runCode = function() {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    93
  var currentTime = jwplayer(PopcornReplacement._container).getPosition();
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    94
  var i = 0;
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    95
  for(i = 0; i < PopcornReplacement.__codes.length; i++) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
    96
    var c = PopcornReplacement.__codes[i];
391
0a68395f7e12 added duration. automatically trigger timeupdate.
hamidouk
parents: 390
diff changeset
    97
    if (currentTime == c.start) {
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    98
      c.onStart();
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    99
    }
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   100
    
391
0a68395f7e12 added duration. automatically trigger timeupdate.
hamidouk
parents: 390
diff changeset
   101
    if (currentTime == c.end) {
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   102
      c.onEnd();
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   103
    }
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   104
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   105
  }
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   106
};
391
0a68395f7e12 added duration. automatically trigger timeupdate.
hamidouk
parents: 390
diff changeset
   107
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   108
/* called everytime the player updates itself 
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   109
   (onTime event)
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   110
 */
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   111
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   112
PopcornReplacement.__timeHandler = function(event) {
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   113
  var pos = event.position;
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   114
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   115
  var i = 0;
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   116
  for(i = 0; i < PopcornReplacement.__codes.length; i++) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   117
     var c = PopcornReplacement.__codes[i];
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   118
     
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   119
     if (pos >= c.start && pos < c.end && 
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   120
         pos - 0.1 <= c.start) {
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   121
        c.onStart();
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   122
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   123
 
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   124
     if (pos >= c.start && pos >= c.end && 
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   125
         pos - 0.1 <= c.end) {
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   126
        c.onEnd();
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   127
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   128
   
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   129
  }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   130
 
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   131
  PopcornReplacement.trigger("timeupdate");
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   132
};
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   133
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   134
PopcornReplacement.__seekHandler = function(event) { 
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   135
  var i = 0;
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   136
  for(i = 0; i < PopcornReplacement.__codes.length; i++) {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   137
     var c = PopcornReplacement.__codes[i];
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   138
    
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   139
     if (event.position >= c.start && event.position < c.end) {
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   140
        c.onEnd();
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   141
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   142
    
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   143
     if (typeof(event.offset) === "undefined")
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   144
       event.offset = 0;
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   145
     if (event.offset >= c.start && event.offset < c.end) {
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   146
       c.onStart();
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   147
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   148
     
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   149
   }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   150
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   151
  PopcornReplacement.trigger("timeupdate");
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   152
}
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   153
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   154
419
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   155
PopcornReplacement.roundTime = function() {
fe7e46eda1b4 renamed all popcorn references in pop.js to not reference popcorn.
hamidouk
parents: 417
diff changeset
   156
  var currentTime = PopcornReplacement.currentTime();
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   157
  return Math.round(currentTime);
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   158
};