src/js/pop.js
author veltr
Tue, 26 Jun 2012 14:22:29 +0200
branchnew-model
changeset 919 972099304059
parent 917 eb8677d3a663
child 957 4da0a5740b6c
permissions -rw-r--r--
Improved HTML Mashup
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
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
     4
/* Popcorn.code replacement has been disabled. It didn't work properly and was not even used  */
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
     5
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
     6
IriSP.PopcornReplacement = {  
442
ee6594f6d00d play pause that just works (tm)
hamidouk
parents: 441
diff changeset
     7
};
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
     8
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
     9
/** base class for our popcorn-compatible players.
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    10
 */
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    11
IriSP.PopcornReplacement.player = function(container, options) {
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    12
  
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    13
    this.media = { 
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    14
        "paused": true,
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    15
        "muted": false
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    16
    };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 841
diff changeset
    17
    
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    18
    this.container = container.replace(/^#/,''); //remove '#' at beginning
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    19
    this.msgPump = {}; /* dictionnary used to receive and send messages */
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    20
    this._options = options;
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
    21
388
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
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    24
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    25
    if (!this.msgPump.hasOwnProperty(msg)) {
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    26
        this.msgPump[msg] = [];
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    27
    }
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    28
    this.msgPump[msg].push(callback);
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    29
};
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    30
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
    31
IriSP.PopcornReplacement.player.prototype.on = IriSP.PopcornReplacement.player.prototype.listen;
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
    32
699
0d6200d801ad refactoring the pop.js code.
hamidouk
parents: 652
diff changeset
    33
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    34
    if (!this.msgPump.hasOwnProperty(msg)) {
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    35
        return;
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    36
    }
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    37
    var d = this.msgPump[msg];
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    38
    for(var i = 0; i < d.length; i++) {
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    39
        d[i].call(window, params);
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    40
    }
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    41
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    42
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
    43
IriSP.PopcornReplacement.player.prototype.emit = IriSP.PopcornReplacement.player.prototype.trigger;
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    44
/*
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    45
IriSP.PopcornReplacement.player.prototype.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
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    54
/** init the api after that flash player has been setup - called by the callback
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    55
    defined by the embedded flash player 
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    56
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    57
IriSP.PopcornReplacement.player.prototype.__initApi = function() {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    58
  this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
463
7ef123b2410f trigger a bunch of signals for popcorn compatibility.
hamidouk
parents: 458
diff changeset
    59
                                                      // but popcorn doesn't need to know more.
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    60
  this.media.muted = this.playerFns.getMute();
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    61
  /* some programmed segments are supposed to be run at the beginning 
578
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    62
  var i = 0;
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    63
  for(i = 0; i < this.__codes.length; i++) {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    64
    var c = this.__codes[i];
578
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    65
    if (0 == c.start) {
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    66
      c.onStart();
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    67
    }
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    68
    
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    69
    if (0 == c.end) {
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    70
      c.onEnd();
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    71
    }
8dd6ebb7a79d fixed .code() bug.
hamidouk
parents: 477
diff changeset
    72
  }
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    73
  
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    74
};
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    75
*/
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    76
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    77
IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 604
diff changeset
    78
  if (typeof(time) === "undefined") {        
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    79
      return this.playerFns.getPosition();            
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    80
  } else {
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    81
     var currentTime = +time;
723
bbf9914a5f99 fixed bug
hamidouk
parents: 711
diff changeset
    82
     this.playerFns.seek(currentTime);              
604
cc2208986a4d WIP - trying to fix a seeking bug.
hamidouk
parents: 596
diff changeset
    83
     return currentTime;
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    84
  }
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    85
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    86
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    87
IriSP.PopcornReplacement.player.prototype.play = function() {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    88
  this.media.paused = false;
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    89
  this.trigger("play");
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    90
  this.playerFns.play();
388
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    91
};
30277c1e3d46 replaced most of popcorn's functions.
hamidouk
parents: 387
diff changeset
    92
    
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    93
IriSP.PopcornReplacement.player.prototype.pause = function() {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    94
    this.media.paused = true;
919
972099304059 Improved HTML Mashup
veltr
parents: 917
diff changeset
    95
    this.trigger("pause");
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    96
    this.playerFns.pause();
390
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    97
};
9b4e5f606d72 first draft, a little rough around the edges.
hamidouk
parents: 388
diff changeset
    98
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
    99
IriSP.PopcornReplacement.player.prototype.muted = function(val) {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   100
  if (typeof(val) !== "undefined") {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   101
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   102
    if (this.playerFns.getMute() !== val) {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   103
      if (val) {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   104
        this.playerFns.setMute(true);
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   105
        this.media.muted = true;
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   106
      } else {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   107
        this.playerFns.setMute(false);
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   108
        this.media.muted = false;
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   109
      }
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   110
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   111
      this.trigger( "volumechange" );
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   112
    }
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   113
    
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   114
    return this.playerFns.getMute();
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   115
  } else {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   116
    return this.playerFns.getMute();
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   117
  }
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   118
};
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   119
839
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   120
IriSP.PopcornReplacement.player.prototype.volume = function(val) {
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   121
    if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") {
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   122
        return false;
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   123
    }
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   124
    var _vol = this.playerFns.getVolume();
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   125
    if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) {
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   126
        val = Math.max(0, Math.min(1, val));
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   127
        if (parseFloat(val) != parseFloat(_vol)) {
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   128
            this.playerFns.setVolume(val);
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   129
            this.trigger("volumechange");
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   130
            _vol = this.playerFns.getVolume();
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   131
        }
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   132
    }
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   133
    return _vol;
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   134
};
4357aac4eb19 Added volume support
veltr
parents: 785
diff changeset
   135
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   136
IriSP.PopcornReplacement.player.prototype.mute = function() {
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   137
    this.muted(true);
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   138
}
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   139
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   140
IriSP.PopcornReplacement.player.prototype.unmute = function() {
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   141
    this.muted(false);
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 904
diff changeset
   142
}
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   143
441
99b7c5192330 fixed horrible bug involving jQuery message passing.
hamidouk
parents: 431
diff changeset
   144
702
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   145
IriSP.PopcornReplacement.player.prototype.roundTime = function() {
f1225d38c150 new, extendable api.
hamidouk
parents: 699
diff changeset
   146
  var currentTime = this.currentTime();
394
89a79a2c6014 WIP - working on the code function.
hamidouk
parents: 391
diff changeset
   147
  return Math.round(currentTime);
711
323205a7bd39 separated jwplayer code from pop.js and put it into its own folder, players/.
hamidouk
parents: 706
diff changeset
   148
};