src/js/pop.js
author hamidouk
Tue, 24 Jan 2012 12:29:14 +0100
branchembed-playerapi-rewrite
changeset 699 0d6200d801ad
parent 652 d6e18921fab8
child 702 f1225d38c150
permissions -rw-r--r--
refactoring the pop.js code.
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
445
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
     4
IriSP.PopcornReplacement = {
442
ee6594f6d00d play pause that just works (tm)
hamidouk
parents: 441
diff changeset
     5
};
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
     6
445
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
     7
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
     8
/** instantiate a new popcorn-compatible player
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
     9
    @param playerFns an object which contains a number of
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    10
    methods: init, play, pause, getMute, setMute used by
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    11
    our wrapper.
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    12
 */
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    13
IriSP.PopcornReplacement.player = function(playerFns) {
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    14
  this.playerFns = playerFns;
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    15
  this.media = { 
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    16
    "paused": true,
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    17
    "muted": false
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    18
  };
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    19
  
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    20
  this.msgPump = {}; /* dictionnary used to receive and send messages */
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    21
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    22
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    23
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    24
//  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).bind(msg, function(event, rest) { callback(rest); });
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    25
  if (!this.msgPump.hasOwnProperty(msg))
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    26
    this.msgPump[msg] = [];
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    27
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    28
  this.msgPump[msg].push(callback);
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    29
};
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    30
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    31
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
445
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
    32
//  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).trigger(msg, params);
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
    33
  
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    34
  if (!this.msgPump.hasOwnProperty(msg))
445
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
    35
    return;
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
    36
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    37
  var d = this.msgPump[msg];
596
a0d2c5b96bee style fix.
hamidouk
parents: 586
diff changeset
    38
586
a3705fc7e054 stylistic rewrite.
hamidouk
parents: 580
diff changeset
    39
  for(var i = 0; i < d.length; i++) {
a3705fc7e054 stylistic rewrite.
hamidouk
parents: 580
diff changeset
    40
    d[i].call(window, params);
445
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
    41
  }
c2eac11a9053 wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents: 442
diff changeset
    42
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    43
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    44
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    45
IriSP.PopcornReplacement.guid = function(prefix) {
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    46
  var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    47
      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
    48
      return v.toString(16);
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    49
   });
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    50
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    51
  return prefix + str;
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    52
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    53
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    54
IriSP.PopcornReplacement.__initApi = function() {
463
7ef123b2410f trigger a bunch of signals for popcorn compatibility.
hamidouk
parents: 458
diff changeset
    55
  IriSP.PopcornReplacement.trigger("loadedmetadata"); // we've done more than loading metadata of course,
7ef123b2410f trigger a bunch of signals for popcorn compatibility.
hamidouk
parents: 458
diff changeset
    56
                                                      // but popcorn doesn't need to know more.
458
5bafddd9e3ba fixed button display bug.
hamidouk
parents: 448
diff changeset
    57
  IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute();
578
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    58
  
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    59
  /* some programmed segments are supposed to be run at the beginning */
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    60
  var i = 0;
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    61
  for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    62
    var c = IriSP.PopcornReplacement.__codes[i];
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    63
    if (0 == c.start) {
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    64
      c.onStart();
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    65
    }
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    66
    
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    67
    if (0 == c.end) {
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    68
      c.onEnd();
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    69
    }
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    70
  }
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    71
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    72
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    73
IriSP.PopcornReplacement.jwplayer = function(container, options) {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    74
  IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#'
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    75
  options.events = {
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    76
      onReady: IriSP.PopcornReplacement.__initApi,
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    77
      onTime: IriSP.PopcornReplacement.__timeHandler,
442
ee6594f6d00d play pause that just works (tm)
hamidouk
parents: 441
diff changeset
    78
      onPlay: IriSP.PopcornReplacement.__playHandler,
ee6594f6d00d play pause that just works (tm)
hamidouk
parents: 441
diff changeset
    79
      onPause: IriSP.PopcornReplacement.__pauseHandler,
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
    80
      onSeek: IriSP.PopcornReplacement.__seekHandler 
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
    81
      }
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    82
    
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    83
  jwplayer(IriSP.PopcornReplacement._container).setup(options);
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    84
  IriSP.PopcornReplacement.media.duration = options.duration;
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    85
  return IriSP.PopcornReplacement;
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    86
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    87
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    88
IriSP.PopcornReplacement.currentTime = function(time) {
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 604
diff changeset
    89
  if (typeof(time) === "undefined") {        
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    90
      return jwplayer(IriSP.PopcornReplacement._container).getPosition();            
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    91
  } else {
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    92
     var currentTime = +time;
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
    93
     jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime );
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 604
diff changeset
    94
     IriSP.PopcornReplacement.__delay_seek_signal = true;     
652
d6e18921fab8 fixes bug in the way a seeked signal is sent.
hamidouk
parents: 612
diff changeset
    95
     IriSP.PopcornReplacement.trigger("seeked");           
604
cc2208986a4d WIP - trying to fix a seeking bug.
hamidouk
parents: 596
diff changeset
    96
     return currentTime;
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    97
  }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    98
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    99
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   100
IriSP.PopcornReplacement.play = function() {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   101
      IriSP.PopcornReplacement.media.paused = false;
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   102
      IriSP.PopcornReplacement.trigger("play");
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   103
//      IriSP.PopcornReplacement.trigger("playing");
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   104
      jwplayer( IriSP.PopcornReplacement._container ).play();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   105
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   106
    
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   107
IriSP.PopcornReplacement.pause = function() {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   108
      if ( !IriSP.PopcornReplacement.media.paused ) {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   109
        IriSP.PopcornReplacement.media.paused = true;
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   110
        IriSP.PopcornReplacement.trigger( "pause" );
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   111
        jwplayer( IriSP.PopcornReplacement._container ).pause();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   112
      }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   113
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   114
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   115
IriSP.PopcornReplacement.muted = function(val) {
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   116
  if (typeof(val) !== "undefined") {
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   117
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   118
    if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) {
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   119
      if (val) {
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   120
        jwplayer(IriSP.PopcornReplacement._container).setMute(true);
448
fa9400275846 added a volume boolen in media.
hamidouk
parents: 445
diff changeset
   121
        IriSP.PopcornReplacement.media.muted = true;
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   122
      } else {
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   123
        jwplayer( IriSP.PopcornReplacement._container ).setMute(false);
448
fa9400275846 added a volume boolen in media.
hamidouk
parents: 445
diff changeset
   124
        IriSP.PopcornReplacement.media.muted = false;
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   125
      }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   126
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   127
      IriSP.PopcornReplacement.trigger( "volumechange" );
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   128
    }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   129
    
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   130
    return jwplayer( IriSP.PopcornReplacement._container ).getMute();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   131
  } else {
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   132
    return jwplayer( IriSP.PopcornReplacement._container ).getMute();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
   133
  }
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   134
};
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   135
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   136
IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted;
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   137
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   138
IriSP.PopcornReplacement.__codes = [];
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   139
IriSP.PopcornReplacement.code = function(options) {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   140
  IriSP.PopcornReplacement.__codes.push(options);
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   141
  return IriSP.PopcornReplacement;
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   142
};
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   143
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   144
/* called everytime the player updates itself 
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   145
   (onTime event)
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   146
 */
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   147
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   148
IriSP.PopcornReplacement.__timeHandler = function(event) {
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   149
  var pos = event.position;
578
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
   150
  
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   151
  var i = 0;
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   152
  for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   153
     var c = IriSP.PopcornReplacement.__codes[i];
580
47fb5cd44900 fixed a couple .code() bugs.
hamidouk
parents: 578
diff changeset
   154
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   155
     if (pos >= c.start && pos < c.end && 
580
47fb5cd44900 fixed a couple .code() bugs.
hamidouk
parents: 578
diff changeset
   156
         pos - 1 <= c.start) {       
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   157
        c.onStart();
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   158
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   159
 
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   160
     if (pos > c.start && pos > c.end && 
580
47fb5cd44900 fixed a couple .code() bugs.
hamidouk
parents: 578
diff changeset
   161
         pos - 1 <= c.end) {
578
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
   162
         c.onEnd();
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   163
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   164
   
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   165
  }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   166
 
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   167
  IriSP.PopcornReplacement.trigger("timeupdate");
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
   168
};
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   169
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   170
IriSP.PopcornReplacement.__seekHandler = function(event) {
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   171
  var i = 0;
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   172
  
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   173
  for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   174
     var c = IriSP.PopcornReplacement.__codes[i];
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   175
    
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   176
     if (event.position >= c.start && event.position < c.end) {        
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   177
        c.onEnd();
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   178
     }         
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   179
   }
580
47fb5cd44900 fixed a couple .code() bugs.
hamidouk
parents: 578
diff changeset
   180
  
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   181
   for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   182
     var c = IriSP.PopcornReplacement.__codes[i];
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   183
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   184
     if (typeof(event.offset) === "undefined")
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   185
       event.offset = 0;
475
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   186
           
5c254621cd9c fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents: 463
diff changeset
   187
     if (event.offset >= c.start && event.offset < c.end) { 
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   188
       c.onStart();
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   189
     }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   190
     
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   191
   }
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   192
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   193
  IriSP.PopcornReplacement.trigger("timeupdate");
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   194
};
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   195
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   196
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   197
IriSP.PopcornReplacement.__playHandler = function(event) {
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   198
  IriSP.PopcornReplacement.media.paused = false;
442
ee6594f6d00d play pause that just works (tm)
hamidouk
parents: 441
diff changeset
   199
  IriSP.PopcornReplacement.trigger("play");
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   200
};
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   201
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   202
IriSP.PopcornReplacement.__pauseHandler = function(event) {
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   203
  IriSP.PopcornReplacement.media.paused = true;
442
ee6594f6d00d play pause that just works (tm)
hamidouk
parents: 441
diff changeset
   204
  IriSP.PopcornReplacement.trigger("pause");
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   205
};
417
bae7c50704d7 fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents: 394
diff changeset
   206
431
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   207
IriSP.PopcornReplacement.roundTime = function() {
f9460dc1957f made our jwplayer wrapper a subobject of IriSP.
hamidouk
parents: 419
diff changeset
   208
  var currentTime = IriSP.PopcornReplacement.currentTime();
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   209
  return Math.round(currentTime);
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   210
};
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
   211