web/res/metadataplayer/LdtPlayer-core.js
changeset 648 b28afee5470b
parent 638 e0d4e8431de3
child 652 b3ccfdbd581b
equal deleted inserted replaced
647:b43f711b5c3e 648:b28afee5470b
   150     }
   150     }
   151 }
   151 }
   152 
   152 
   153 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   153 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   154     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   154     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   155         var _media = this.videoData.currentMedia;
   155         
   156         if (typeof _media !== "undefined") {
   156         var _media;
       
   157         
       
   158         if (typeof this.videoData.mainMedia !== "undefined") {
       
   159             _media = this.videoData.getElement(this.videoData.mainMedia);
       
   160         }
       
   161         
       
   162         if (this.config.player.type === "mashup" || this.config.player.type === "mashup-html") {
       
   163             if (typeof _media === "undefined" || _media.elementType !== "mashup") {
       
   164                 var _mashups = this.videoData.getMashups();
       
   165                 if (_mashups.length) {
       
   166                     _media = _mashups[0];
       
   167                 }
       
   168             }
       
   169         } else {
       
   170             if (typeof _media === "undefined" || _media.elementType !== "media") {
       
   171                 var _medias = this.videoData.getMedias();
       
   172                 if (_medias.length) {
       
   173                     _media = _medias[0];
       
   174                 }
       
   175             }
       
   176         }
       
   177         
       
   178         this.videoData.currentMedia = _media;
       
   179         
       
   180         if (typeof _media !== "undefined" && typeof _media.video !== "undefined") {
   157             this.config.player.video = _media.video;
   181             this.config.player.video = _media.video;
   158             if (typeof _media.streamer !== "undefined") {
   182             if (typeof _media.streamer !== "undefined") {
   159                 this.config.player.streamer = _media.streamer;
   183                 this.config.player.streamer = _media.streamer;
   160                 this.config.player.video = _media.video.replace(_media.streamer,'');
   184                 this.config.player.video = _media.video.replace(_media.streamer,'');
   161             }
   185             }
   394     }
   418     }
   395 }
   419 }
   396 /* wrapper that simulates popcorn.js because
   420 /* wrapper that simulates popcorn.js because
   397    popcorn is a bit unstable at the time */
   421    popcorn is a bit unstable at the time */
   398 
   422 
       
   423 /* Popcorn.code replacement has been disabled. It didn't work properly and was not even used  */
       
   424 
   399 IriSP.PopcornReplacement = {  
   425 IriSP.PopcornReplacement = {  
   400 };
   426 };
   401 
   427 
   402 /** base class for our popcorn-compatible players.
   428 /** base class for our popcorn-compatible players.
   403  */
   429  */
   404 IriSP.PopcornReplacement.player = function(container, options) {
   430 IriSP.PopcornReplacement.player = function(container, options) {
   405   /* the jwplayer calls the callbacks in the global space so we need to 
       
   406      preserve them this way */
       
   407   if (typeof IriSP._ === "undefined") {
       
   408       return;
       
   409   }
       
   410     
       
   411   this.callbacks = {
       
   412       onReady:  IriSP._.bind(this.__initApi, this),
       
   413       onTime:   IriSP._.bind(this.__timeHandler, this),
       
   414       onPlay:   IriSP._.bind(this.__playHandler, this),
       
   415       onPause:  IriSP._.bind(this.__pauseHandler, this),
       
   416       onSeek:   IriSP._.bind(this.__seekHandler, this) 
       
   417   };
       
   418   
   431   
   419   this.media = { 
   432     this.media = { 
   420     "paused": true,
   433         "paused": true,
   421     "muted": false
   434         "muted": false
   422   };
   435     };
   423     
   436     
   424   this.container = container.replace(/^#/,''); //eschew the '#'
   437     this.container = container.replace(/^#/,''); //remove '#' at beginning
   425   
   438     this.msgPump = {}; /* dictionnary used to receive and send messages */
   426   this.msgPump = {}; /* dictionnary used to receive and send messages */
   439     this._options = options;
   427   this.__codes = []; /* used to schedule the execution of a piece of code in 
       
   428                         a segment (similar to the popcorn.code plugin). */
       
   429   
       
   430   this._options = options;
       
   431 
   440 
   432 };
   441 };
   433 
   442 
   434 IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
   443 IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
   435   if (!this.msgPump.hasOwnProperty(msg))
   444     if (!this.msgPump.hasOwnProperty(msg)) {
   436     this.msgPump[msg] = [];
   445         this.msgPump[msg] = [];
   437 
   446     }
   438   this.msgPump[msg].push(callback);
   447     this.msgPump[msg].push(callback);
   439 };
   448 };
   440 
   449 
   441 IriSP.PopcornReplacement.player.prototype.on = IriSP.PopcornReplacement.player.prototype.listen;
   450 IriSP.PopcornReplacement.player.prototype.on = IriSP.PopcornReplacement.player.prototype.listen;
   442 
   451 
   443 IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
   452 IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
   444   if (!this.msgPump.hasOwnProperty(msg))
   453     if (!this.msgPump.hasOwnProperty(msg)) {
   445     return;
   454         return;
   446 
   455     }
   447   var d = this.msgPump[msg];
   456     var d = this.msgPump[msg];
   448 
   457     for(var i = 0; i < d.length; i++) {
   449   for(var i = 0; i < d.length; i++) {
   458         d[i].call(window, params);
   450     d[i].call(window, params);
   459     }
   451   }
       
   452 
       
   453 };
   460 };
   454 
   461 
   455 IriSP.PopcornReplacement.player.prototype.emit = IriSP.PopcornReplacement.player.prototype.trigger;
   462 IriSP.PopcornReplacement.player.prototype.emit = IriSP.PopcornReplacement.player.prototype.trigger;
   456 
   463 /*
   457 IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
   464 IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
   458   var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
   465   var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
   459       var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
   466       var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
   460       return v.toString(16);
   467       return v.toString(16);
   461    });
   468    });
   463   return prefix + str;
   470   return prefix + str;
   464 };
   471 };
   465 
   472 
   466 /** init the api after that flash player has been setup - called by the callback
   473 /** init the api after that flash player has been setup - called by the callback
   467     defined by the embedded flash player 
   474     defined by the embedded flash player 
   468 */
   475 
   469 IriSP.PopcornReplacement.player.prototype.__initApi = function() {
   476 IriSP.PopcornReplacement.player.prototype.__initApi = function() {
   470   this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
   477   this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
   471                                                       // but popcorn doesn't need to know more.
   478                                                       // but popcorn doesn't need to know more.
   472   this.media.muted = this.playerFns.getMute();
   479   this.media.muted = this.playerFns.getMute();
   473   /* some programmed segments are supposed to be run at the beginning */
   480   /* some programmed segments are supposed to be run at the beginning 
   474   var i = 0;
   481   var i = 0;
   475   for(i = 0; i < this.__codes.length; i++) {
   482   for(i = 0; i < this.__codes.length; i++) {
   476     var c = this.__codes[i];
   483     var c = this.__codes[i];
   477     if (0 == c.start) {
   484     if (0 == c.start) {
   478       c.onStart();
   485       c.onStart();
   480     
   487     
   481     if (0 == c.end) {
   488     if (0 == c.end) {
   482       c.onEnd();
   489       c.onEnd();
   483     }
   490     }
   484   }
   491   }
       
   492   
   485 };
   493 };
       
   494 */
   486 
   495 
   487 IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
   496 IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
   488   if (typeof(time) === "undefined") {        
   497   if (typeof(time) === "undefined") {        
   489       return this.playerFns.getPosition();            
   498       return this.playerFns.getPosition();            
   490   } else {
   499   } else {
   500   this.playerFns.play();
   509   this.playerFns.play();
   501 };
   510 };
   502     
   511     
   503 IriSP.PopcornReplacement.player.prototype.pause = function() {
   512 IriSP.PopcornReplacement.player.prototype.pause = function() {
   504     this.media.paused = true;
   513     this.media.paused = true;
   505     this.trigger( "pause" );
   514     this.trigger("pause");
   506     this.playerFns.pause();
   515     this.playerFns.pause();
   507 };
   516 };
   508 
   517 
   509 IriSP.PopcornReplacement.player.prototype.muted = function(val) {
   518 IriSP.PopcornReplacement.player.prototype.muted = function(val) {
   510   if (typeof(val) !== "undefined") {
   519   if (typeof(val) !== "undefined") {
   549 
   558 
   550 IriSP.PopcornReplacement.player.prototype.unmute = function() {
   559 IriSP.PopcornReplacement.player.prototype.unmute = function() {
   551     this.muted(false);
   560     this.muted(false);
   552 }
   561 }
   553 
   562 
   554 IriSP.PopcornReplacement.player.prototype.code = function(options) {
       
   555   this.__codes.push(options);
       
   556   return this;
       
   557 };
       
   558 
       
   559 /* called everytime the player updates itself 
       
   560    (onTime event)
       
   561  */
       
   562 
       
   563 IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) {
       
   564   var pos = event.position;
       
   565 
       
   566   var i = 0;
       
   567   for(i = 0; i < this.__codes.length; i++) {
       
   568      var c = this.__codes[i];
       
   569 
       
   570      if (pos >= c.start && pos < c.end && 
       
   571          pos - 1 <= c.start) {       
       
   572         c.onStart();
       
   573      }
       
   574  
       
   575      if (pos > c.start && pos > c.end && 
       
   576          pos - 1 <= c.end) {
       
   577          c.onEnd();
       
   578      }
       
   579    
       
   580   }
       
   581  
       
   582   this.trigger("timeupdate");
       
   583 };
       
   584 
       
   585 IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) {
       
   586   var i = 0;
       
   587   
       
   588   for(i = 0; i < this.__codes.length; i++) {
       
   589      var c = this.__codes[i];
       
   590     
       
   591      if (event.position >= c.start && event.position < c.end) {        
       
   592         c.onEnd();
       
   593      }         
       
   594    }
       
   595   
       
   596    for(i = 0; i < this.__codes.length; i++) {
       
   597      var c = this.__codes[i];
       
   598 
       
   599      if (typeof(event.offset) === "undefined")
       
   600        event.offset = 0;
       
   601            
       
   602      if (event.offset >= c.start && event.offset < c.end) { 
       
   603        c.onStart();
       
   604      }
       
   605      
       
   606    }
       
   607   
       
   608   /* this signal sends as an extra argument the position in the video.
       
   609      As far as I know, this argument is not provided by popcorn */
       
   610   this.trigger("seeked", event.offset);  
       
   611 };
       
   612 
       
   613 IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) {
       
   614   this.media.paused = false;
       
   615   this.trigger("play");
       
   616 };
       
   617 
       
   618 IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) {
       
   619   this.media.paused = true;
       
   620   this.trigger("pause");
       
   621 };
       
   622 
   563 
   623 IriSP.PopcornReplacement.player.prototype.roundTime = function() {
   564 IriSP.PopcornReplacement.player.prototype.roundTime = function() {
   624   var currentTime = this.currentTime();
   565   var currentTime = this.currentTime();
   625   return Math.round(currentTime);
   566   return Math.round(currentTime);
   626 };/* TODO: Separate Project-specific data from Source */
   567 };/* TODO: Separate Project-specific data from Source */
  1281     })
  1222     })
  1282 }
  1223 }
  1283 
  1224 
  1284 IriSP.Model.Source.prototype.getElement = function(_elId) {
  1225 IriSP.Model.Source.prototype.getElement = function(_elId) {
  1285     return this.directory.getElement(_elId);
  1226     return this.directory.getElement(_elId);
  1286 }
       
  1287 
       
  1288 IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) {
       
  1289     if (typeof _idRef !== "undefined") {
       
  1290         this.currentMedia = this.getElement(_idRef);
       
  1291     }
       
  1292 }
       
  1293 
       
  1294 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() {
       
  1295     if (typeof this.currentMedia === "undefined" && this.getMedias().length) {
       
  1296         this.currentMedia = this.getMedias()[0];
       
  1297     }
       
  1298 }
  1227 }
  1299 
  1228 
  1300 IriSP.Model.Source.prototype.get = function() {
  1229 IriSP.Model.Source.prototype.get = function() {
  1301     this.status = IriSP.Model._SOURCE_STATUS_WAITING;
  1230     this.status = IriSP.Model._SOURCE_STATUS_WAITING;
  1302     this.handleCallbacks();
  1231     this.handleCallbacks();
  1688 
  1617 
  1689 IriSP.PopcornReplacement.allocine.prototype.ready = function() {
  1618 IriSP.PopcornReplacement.allocine.prototype.ready = function() {
  1690     this.player = document.getElementById(this.container);
  1619     this.player = document.getElementById(this.container);
  1691     this.player.addEventListener("onStateChange", "onAllocineStateChange");
  1620     this.player.addEventListener("onStateChange", "onAllocineStateChange");
  1692     this.player.cueVideoByUrl(this._options.video);
  1621     this.player.cueVideoByUrl(this._options.video);
  1693     this.callbacks.onReady();
  1622     this.trigger("loadedmetadata");
  1694 };
  1623 };
  1695 
  1624 
  1696 IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) {
  1625 IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) {
  1697     this.callbacks.onTime({
  1626     this.trigger("timeupdate");
  1698         position: progressInfo.mediaTime
       
  1699     });
       
  1700 }
  1627 }
  1701 
  1628 
  1702 
  1629 
  1703 IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) {
  1630 IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) {
  1704     if (this.player) {
  1631     if (this.player) {
  1716         return false;
  1643         return false;
  1717     }
  1644     }
  1718 }
  1645 }
  1719 
  1646 
  1720 IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
  1647 IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
  1721     console.log("stateHandler");
       
  1722     switch(state) {
  1648     switch(state) {
  1723         case 1:
  1649         case 1:
  1724             this.callbacks.onPlay();
  1650             this.trigger("play");
  1725             break;
  1651             break;
  1726 
  1652 
  1727         case 2:
  1653         case 2:
  1728             this.callbacks.onPause();
  1654             this.trigger("pause");
  1729             break;
  1655             break;
  1730 
  1656 
  1731         case 3:
  1657         case 3:
  1732             this.callbacks.onSeek({
  1658             this.trigger("seeked");
  1733                 position: this.player.getCurrentTime()
       
  1734             });
       
  1735             break;
  1659             break;
  1736 
       
  1737         /*
       
  1738         case 5:
       
  1739             this.callbacks.onReady();
       
  1740             break;
       
  1741         */
       
  1742     }
  1660     }
  1743     
  1661     
  1744 };/* To wrap a player the develop should create a new class derived from
  1662 };/* To wrap a player the develop should create a new class derived from
  1745 the IriSP.PopcornReplacement.player and defining the correct functions */
  1663 the IriSP.PopcornReplacement.player and defining the correct functions */
  1746 
  1664 
  1850     
  1768     
  1851     this.player.addEventListener("onStateChange", "onDailymotionStateChange");
  1769     this.player.addEventListener("onStateChange", "onDailymotionStateChange");
  1852     this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
  1770     this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
  1853     this.player.cueVideoByUrl(this._options.video);
  1771     this.player.cueVideoByUrl(this._options.video);
  1854     
  1772     
  1855     this.callbacks.onReady();
  1773     this.trigger("loadedmetadata");
  1856 };
  1774 };
  1857 
  1775 
  1858 IriSP.PopcornReplacement.dailymotion.prototype.onProgress = function(progressInfo) {
  1776 IriSP.PopcornReplacement.dailymotion.prototype.onProgress = function(progressInfo) {
  1859     
  1777     this.trigger("timeupdate");
  1860     this.callbacks.onTime({
       
  1861         position: progressInfo.mediaTime
       
  1862     });
       
  1863 }
  1778 }
  1864 
  1779 
  1865 IriSP.PopcornReplacement.dailymotion.prototype.onStateChange = function(state) {
  1780 IriSP.PopcornReplacement.dailymotion.prototype.onStateChange = function(state) {
  1866     
  1781     
  1867     switch(state) {
  1782     switch(state) {
  1868         case 1:
  1783         case 1:
  1869             this.callbacks.onPlay();
  1784             this.trigger("play");
  1870             break;
  1785             break;
  1871 
  1786 
  1872         case 2:
  1787         case 2:
  1873             this.callbacks.onPause();
  1788             this.trigger("pause");
  1874             break;
  1789             break;
  1875 
  1790 
  1876         case 3:
  1791         case 3:
  1877             this.callbacks.onSeek({
  1792             this.trigger("seeked");
  1878                 position: this.player.getCurrentTime()
       
  1879             });
       
  1880             break;
  1793             break;
  1881     }
  1794     }
  1882     
  1795     
  1883 };/* To wrap a player the develop should create a new class derived from 
  1796 };/* To wrap a player the develop should create a new class derived from 
  1884    the IriSP.PopcornReplacement.player and defining the correct functions */
  1797    the IriSP.PopcornReplacement.player and defining the correct functions */
  1888     /* appel du parent pour initialiser les structures communes à tous les players */
  1801     /* appel du parent pour initialiser les structures communes à tous les players */
  1889     IriSP.PopcornReplacement.player.call(this, container, options);
  1802     IriSP.PopcornReplacement.player.call(this, container, options);
  1890   
  1803   
  1891     this.media.duration = options.duration; /* optional */
  1804     this.media.duration = options.duration; /* optional */
  1892  
  1805  
  1893     var _player = jwplayer(this.container);
  1806     var _player = jwplayer(this.container),
       
  1807         _this = this;
  1894   
  1808   
  1895   /* Définition des fonctions de l'API -  */
  1809   /* Définition des fonctions de l'API -  */
  1896     this.playerFns = {
  1810     this.playerFns = {
  1897         play: function() { return _player.play(); },
  1811         play: function() { return _player.play(true); },
  1898         pause: function() { return _player.pause(); },
  1812         pause: function() { return _player.pause(true); },
  1899         getPosition: function() { return _player.getPosition(); },
  1813         getPosition: function() { return _player.getPosition(); },
  1900         seek: function(pos) { return _player.seek(pos); },
  1814         seek: function(pos) { return _player.seek(pos); },
  1901         getMute: function() { return _player.getMute() },
  1815         getMute: function() { return _player.getMute() },
  1902         setMute: function(p) { return _player.setMute(p); },
  1816         setMute: function(p) { return _player.setMute(p); },
  1903         getVolume: function() { return _player.getVolume() / 100; },
  1817         getVolume: function() { return _player.getVolume() / 100; },
  1904         setVolume: function(p) { return _player.setVolume(Math.floor(100*p)); }
  1818         setVolume: function(p) { return _player.setVolume(Math.floor(100*p)); }
  1905     }
  1819     }
  1906 
  1820 
  1907     options.events = this.callbacks;
  1821     options.events = {
       
  1822         onReady:  function() {
       
  1823             _this.trigger("loadedmetadata");
       
  1824         },
       
  1825         onTime:   function() {
       
  1826             _this.trigger("timeupdate");
       
  1827         },
       
  1828         onPlay:   function() {
       
  1829             _this.trigger("play");
       
  1830         },
       
  1831         onPause:  function() {
       
  1832             _this.trigger("pause");
       
  1833         },
       
  1834         onSeek:   function() {
       
  1835             _this.trigger("seeked");
       
  1836         }
       
  1837     };
  1908 
  1838 
  1909     _player.setup(options);
  1839     _player.setup(options);
  1910 };
  1840 };
  1911 
  1841 
  1912 IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
  1842 IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
  1925         _h = this.$.height(),
  1855         _h = this.$.height(),
  1926         _this = this;
  1856         _this = this;
  1927     
  1857     
  1928     IriSP._(metadata.currentMedia.medias).each(function(_media) {
  1858     IriSP._(metadata.currentMedia.medias).each(function(_media) {
  1929         var _tmpId = Popcorn.guid("video"),
  1859         var _tmpId = Popcorn.guid("video"),
  1930             _videoEl = IriSP.jQuery('<video>');
  1860             _videoEl = IriSP.jQuery('<video>'),
  1931             
  1861             _videoUrl = _media.video;
       
  1862         if (typeof options.url_transform === "function") {
       
  1863             _videoUrl = options.url_transform(_videoUrl);
       
  1864         }
       
  1865         
  1932         _videoEl
  1866         _videoEl
  1933             .attr({
  1867             .attr({
  1934                 src : _media.video,
  1868                 src : _videoUrl,
  1935                 id : _tmpId,
  1869                 id : _tmpId,
  1936                 width : _w,
  1870                 width : _w,
  1937                 height : _h
  1871                 height : _h
  1938             })
  1872             })
  1939             .css({
  1873             .css({
  1943             });
  1877             });
  1944 
  1878 
  1945         _this.$.append(_videoEl);
  1879         _this.$.append(_videoEl);
  1946         _media.videoEl = _videoEl;
  1880         _media.videoEl = _videoEl;
  1947         _media.popcorn = Popcorn("#" + _tmpId);
  1881         _media.popcorn = Popcorn("#" + _tmpId);
       
  1882         _media.loadedMetadata = false;
       
  1883         _media.popcorn.on("loadedmetadata", function() {
       
  1884             _media.loadedMetadata = true;
       
  1885             var _allLoaded = true;
       
  1886             for (var _i = 0; _i < metadata.currentMedia.medias.length; _i++) {
       
  1887                 _allLoaded = _allLoaded && metadata.currentMedia.medias[_i].loadedMetadata;
       
  1888             }
       
  1889             if (_allLoaded) {
       
  1890                 _this.changeCurrentAnnotation();
       
  1891                 _this.trigger("loadedmetadata");
       
  1892             }
       
  1893         });
  1948         _media.popcorn.on("timeupdate", function() {
  1894         _media.popcorn.on("timeupdate", function() {
  1949             if (!_this.media.paused && _media === _this.currentMedia) {
  1895             if (!_this.media.paused && _media === _this.currentMedia) {
  1950                 var _time = _media.popcorn.currentTime();
  1896                 var _time = Math.round( 1000 * _media.popcorn.currentTime() );
  1951              //   var _status = "Timeupdate from " + _media.id + " at time " + _time;
  1897 //                var _status = "Timeupdate from " + _media.id + " at time " + _time;
  1952                 if ( _time < _this.segmentEnd ) {
  1898                 if ( _time < _this.segmentEnd ) {
  1953                     if ( _time >= _this.segmentBegin ) {
  1899                     if ( _time >= _this.segmentBegin ) {
  1954                         _this.timecode = _time - _this.timedelta;
  1900                         _this.timecode = _time - _this.timedelta;
  1955                   //      _status += " within segment";
  1901 //                        _status += " within segment";
  1956                     } else {
  1902                     } else {
  1957                         _this.timecode = _this.segmentBegin - _this.timedelta;
  1903                         _this.timecode = _this.segmentBegin - _this.timedelta;
  1958                         _media.popcorn.currentTime(_this.segmentBegin);
  1904                         _media.popcorn.currentTime(_this.segmentBegin / 1000);
  1959                    //     _status += " before segment begin";
  1905 //                        _status += " before segment";
  1960                     }
  1906                     }
  1961                 } else {
  1907                 } else {
  1962                     _this.timecode = _this.segmentEnd - _this.timedelta;
  1908                     _this.timecode = _this.segmentEnd - _this.timedelta;
  1963                     _media.popcorn.pause();
  1909                     _media.popcorn.pause();
  1964                     _this.changeCurrentAnnotation();
  1910                     _this.changeCurrentAnnotation();
  1965                  //   _status += " after segment end";
  1911 //                    _status += " after segment";
  1966                 }
  1912                 }
  1967             /*    _status += ", translated to " + _this.timecode;
  1913 //                _status += " (" + _this.segmentBegin + " to " + _this.segmentEnd + ")" + ", translated to " + _this.timecode;
  1968                 console.log(_status); */
  1914 //                console.log(_status);
  1969                 _this.trigger("timeupdate");
  1915                 _this.trigger("timeupdate");
  1970             }
  1916             }
  1971         });
  1917         });
  1972     });
  1918     });
  1973     
  1919     
  1980         },
  1926         },
  1981         pause: function() {
  1927         pause: function() {
  1982             _this.currentMedia.popcorn.pause();
  1928             _this.currentMedia.popcorn.pause();
  1983         },
  1929         },
  1984         getPosition: function() {
  1930         getPosition: function() {
  1985             return _this.timecode;
  1931             return _this.timecode / 1000;
  1986         },
  1932         },
  1987         seek: function(pos) {
  1933         seek: function(pos) {
  1988             _this.timecode = pos;
  1934             _this.timecode = Math.round(pos * 1000);
  1989             _this.changeCurrentAnnotation();
  1935             _this.changeCurrentAnnotation();
  1990         },
  1936         },
  1991         getMute: function() {
  1937         getMute: function() {
  1992             return
  1938             var _res = (
  1993                 typeof _this.currentMedia !== "undefined"
  1939                 typeof _this.currentMedia !== "undefined"
  1994                 ? _this.currentMedia.popcorn.muted()
  1940                 ? _this.currentMedia.popcorn.muted()
  1995                 : false;
  1941                 : false
       
  1942             );
       
  1943             return _res;
  1996         },
  1944         },
  1997         setMute: function(p) {
  1945         setMute: function(p) {
  1998             var _mute = !!p;
  1946             var _mute = !!p;
  1999             for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
  1947             for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
  2000                 _this.mashup.medias[_i].popcorn.muted(_mute);
  1948                 _this.mashup.medias[_i].popcorn.muted(_mute);
  2001             }
  1949             }
  2002         },
  1950         },
  2003         getVolume: function() {
  1951         getVolume: function() {
  2004             return
  1952             var _res = (
  2005                 typeof _this.currentMedia !== "undefined"
  1953                 typeof _this.currentMedia !== "undefined"
  2006                 ? _this.currentMedia.popcorn.volume()
  1954                 ? _this.currentMedia.popcorn.volume()
  2007                 : .5;
  1955                 : .5
       
  1956             );
       
  1957             return _res;
  2008         },
  1958         },
  2009         setVolume: function(_vol) {
  1959         setVolume: function(_vol) {
  2010             for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
  1960             for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
  2011                 _this.mashup.medias[_i].popcorn.volume(_vol);
  1961                 _this.mashup.medias[_i].popcorn.volume(_vol);
  2012             }
  1962             }
  2013         }
  1963         }
  2014     }
  1964     }
  2015 /*
  1965     
  2016     options.events = this.callbacks;
       
  2017 
       
  2018     _player.setup(options);
       
  2019     */
       
  2020 };
  1966 };
  2021 
  1967 
  2022 IriSP.PopcornReplacement.htmlMashup.prototype = new IriSP.PopcornReplacement.player("", {});
  1968 IriSP.PopcornReplacement.htmlMashup.prototype = new IriSP.PopcornReplacement.player("", {});
  2023 
  1969 
  2024 IriSP.PopcornReplacement.htmlMashup.prototype.changeCurrentAnnotation = function() {
  1970 IriSP.PopcornReplacement.htmlMashup.prototype.changeCurrentAnnotation = function() {
  2025     var _annotation = this.mashup.getAnnotationAtTime( 1000 * this.timecode );
  1971     var _annotation = this.mashup.getAnnotationAtTime( this.timecode );
  2026     if (typeof _annotation == "undefined") {
  1972     if (typeof _annotation == "undefined") {
  2027         if (typeof this.currentMedia !== "undefined") {
  1973         if (typeof this.currentMedia !== "undefined") {
  2028             this.currentMedia.popcorn.pause();
  1974             this.currentMedia.popcorn.pause();
  2029             this.media.paused = true;
  1975             if (!this.media.paused) {
       
  1976                 this.media.paused = true;
       
  1977                 this.trigger("pause");
       
  1978             }
  2030         }
  1979         }
  2031         return;
  1980         return;
  2032     }
  1981     }
  2033     if (_annotation !== this.currentAnnotation) {
  1982     if (_annotation !== this.currentAnnotation) {
  2034         this.currentAnnotation = _annotation;
  1983         this.currentAnnotation = _annotation;
  2035         this.segmentBegin = this.currentAnnotation.annotation.begin.getSeconds();
  1984         this.segmentBegin = this.currentAnnotation.annotation.begin.milliseconds;
  2036         this.segmentEnd = this.currentAnnotation.annotation.end.getSeconds();
  1985         this.segmentEnd = this.currentAnnotation.annotation.end.milliseconds;
  2037         this.timedelta = this.segmentBegin - this.currentAnnotation.begin.getSeconds();
  1986         this.timedelta = this.segmentBegin - this.currentAnnotation.begin.milliseconds;
  2038         this.currentMedia = this.currentAnnotation.getMedia();
  1987         this.currentMedia = this.currentAnnotation.getMedia();
  2039         
  1988         
  2040         for (var _i = 0; _i < this.mashup.medias.length; _i++) {
  1989         for (var _i = 0; _i < this.mashup.medias.length; _i++) {
  2041             if (this.mashup.medias[_i].id !== this.currentMedia.id) {
  1990             if (this.mashup.medias[_i].id !== this.currentMedia.id) {
  2042                 this.mashup.medias[_i].videoEl.hide();
  1991                 this.mashup.medias[_i].videoEl.hide();
  2043                 this.mashup.medias[_i].popcorn.pause();
  1992                 this.mashup.medias[_i].popcorn.pause();
  2044             } else {
  1993             } else {
  2045                 this.mashup.medias[_i].videoEl.show();
  1994                 this.mashup.medias[_i].videoEl.show();
  2046             }
  1995             }
  2047         }
  1996         }
       
  1997 /* PRELOADING */
       
  1998         var _this = this,
       
  1999             _preloadedMedias = [],
       
  2000             _toPreload = this.mashup.getAnnotations().filter(function(_a) {
       
  2001             return (_a.begin >= _this.currentAnnotation.end && _a.getMedia().id !== _this.currentMedia.id);
       
  2002         });
       
  2003         IriSP._(_toPreload).each(function(_a) {
       
  2004             var _media = _a.getMedia();
       
  2005             if (IriSP._(_preloadedMedias).indexOf(_media.id) === -1) {
       
  2006                 _preloadedMedias.push(_media.id);
       
  2007                 _media.popcorn.currentTime(_a.annotation.begin.getSeconds());
       
  2008                 //console.log("Preloading ", _media.id, " at t=", _a.annotation.begin.getSeconds());
       
  2009             }
       
  2010         });
       
  2011         
       
  2012 //        console.log("Changed segment: media="+ this.currentMedia.id + ", from=" + this.segmentBegin + " to=" + this.segmentEnd +", timedelta = ", this.timedelta)
       
  2013 //    } else {
       
  2014 //        console.log("changeCurrentAnnotation called, but segment hasn't changed");
  2048     }
  2015     }
  2049     if (this.currentMedia.popcorn.readyState()) {
  2016     if (this.currentMedia.popcorn.readyState()) {
  2050         this.currentMedia.popcorn.currentTime(this.timecode + this.timedelta);
  2017         this.currentMedia.popcorn.currentTime( (this.timecode + this.timedelta) / 1000);
       
  2018         this.trigger("timeupdate");
  2051     }
  2019     }
  2052     if (!this.media.paused) {
  2020     if (!this.media.paused) {
  2053         this.currentMedia.popcorn.play();
  2021         this.currentMedia.popcorn.play();
  2054     }
  2022     }
  2055 }
  2023 }
  2058 
  2026 
  2059 /** jwplayer player wrapper */
  2027 /** jwplayer player wrapper */
  2060 IriSP.PopcornReplacement.mashup = function(container, options) {
  2028 IriSP.PopcornReplacement.mashup = function(container, options) {
  2061     /* Appel du constructeur de la classe parente */
  2029     /* Appel du constructeur de la classe parente */
  2062     IriSP.PopcornReplacement.player.call(this, container, options);   
  2030     IriSP.PopcornReplacement.player.call(this, container, options);   
  2063     
  2031 
  2064     var _this = this;
  2032     var _this = this;
  2065 
  2033 
  2066     /* Définition des fonctions de commande :
  2034     /* Définition des fonctions de commande :
  2067      this.playerFns.play, .pause, .getPosition, .seek,
  2035      this.playerFns.play, .pause, .getPosition, .seek,
  2068      .getMute, .setMute, .getVolume, .setVolume
  2036      .getMute, .setMute, .getVolume, .setVolume
  2161 };
  2129 };
  2162 
  2130 
  2163 IriSP.PopcornReplacement.mashup.prototype = new IriSP.PopcornReplacement.player("", {});
  2131 IriSP.PopcornReplacement.mashup.prototype = new IriSP.PopcornReplacement.player("", {});
  2164 
  2132 
  2165 IriSP.PopcornReplacement.mashup.prototype.onReady = function() {
  2133 IriSP.PopcornReplacement.mashup.prototype.onReady = function() {
  2166     
       
  2167     this.player = document.getElementById(this.container);
  2134     this.player = document.getElementById(this.container);
  2168     
  2135     this.trigger("loadedmetadata");
  2169     this.callbacks.onReady();
       
  2170 };
  2136 };
  2171 
  2137 
  2172 IriSP.PopcornReplacement.mashup.prototype.onProgress = function(progressInfo) {
  2138 IriSP.PopcornReplacement.mashup.prototype.onProgress = function(progressInfo) {
  2173     
  2139     this.trigger("timeupdate");
  2174     this.callbacks.onTime({
       
  2175         position: progressInfo.mediaTime
       
  2176     });
       
  2177 }
  2140 }
  2178 
  2141 
  2179 IriSP.PopcornReplacement.mashup.prototype.onStateChange = function(state) {
  2142 IriSP.PopcornReplacement.mashup.prototype.onStateChange = function(state) {
  2180     
  2143 
  2181     switch(state) {
  2144     switch(state) {
  2182         case 1:
  2145         case 1:
  2183             this.callbacks.onPlay();
  2146             this.trigger("play");
  2184             break;
  2147             break;
  2185 
  2148 
  2186         case 2:
  2149         case 2:
  2187             this.callbacks.onPause();
  2150             this.trigger("pause");
  2188             break;
  2151             break;
  2189 
  2152 
  2190         case 3:
  2153         case 3:
  2191             this.callbacks.onSeek({
  2154             this.trigger("seeked");
  2192                 position: this.player.getCurrentTime()
       
  2193             });
       
  2194             break;
  2155             break;
  2195     }
  2156     }
  2196     
  2157 
  2197 };/* LDT Platform Serializer */
  2158 };/* LDT Platform Serializer */
  2198 
  2159 
  2199 if (typeof IriSP.serializers === "undefined") {
  2160 if (typeof IriSP.serializers === "undefined") {
  2200     IriSP.serializers = {}
  2161     IriSP.serializers = {}
  2201 }
  2162 }
  2328                     })
  2289                     })
  2329                 }
  2290                 }
  2330             }
  2291             }
  2331         },
  2292         },
  2332         mashup : {
  2293         mashup : {
  2333             serialized_name : "mashups",
  2294             serialized_name : "lists",
  2334             deserializer : function(_data, _source) {
  2295             deserializer : function(_data, _source) {
       
  2296                 if (typeof _data.meta !== "object" || typeof _data.meta.listtype !== "string" || _data.meta.listtype !== "mashup") {
       
  2297                     return undefined;
       
  2298                 }
  2335                 var _res = new IriSP.Model.Mashup(_data.id, _source);
  2299                 var _res = new IriSP.Model.Mashup(_data.id, _source);
  2336                 _res.title = _data.meta["dc:title"];
  2300                 _res.title = _data.meta["dc:title"];
  2337                 _res.description = _data.meta["dc:description"];
  2301                 _res.description = _data.meta["dc:description"];
  2338                 for (var _i = 0; _i < _data.segments.length; _i++) {
  2302                 for (var _i = 0; _i < _data.items.length; _i++) {
  2339                     _res.addSegmentById(_data.segments[_i]);
  2303                     _res.addSegmentById(_data.items[_i]);
  2340                 }
  2304                 }
  2341                 return _res;        
  2305                 return _res;        
  2342             },
  2306             },
  2343             serializer : function(_data, _source) {
  2307             serializer : function(_data, _source) {
  2344                 return {
  2308                 return {
  2345                     "dc:title": _data.title,
  2309                     meta : {
  2346                     "dc:description": _data.description,
  2310                         "dc:title": _data.title,
  2347                     segments: _data.segments.map(function(_annotation) {
  2311                         "dc:description": _data.description,
       
  2312                         listtype: "mashup"
       
  2313                     },
       
  2314                     items: _data.segments.map(function(_annotation) {
  2348                         return _id;
  2315                         return _id;
  2349                     })
  2316                     }),
       
  2317                     id: _data.id
  2350                 }
  2318                 }
  2351             }
  2319             }
  2352         }
  2320         }
  2353     },
  2321     },
  2354     serialize : function(_source) {
  2322     serialize : function(_source) {
  2375                 _list = new IriSP.Model.List(_source.directory);
  2343                 _list = new IriSP.Model.List(_source.directory);
  2376             if (typeof _listdata !== "undefined" && _listdata !== null) {
  2344             if (typeof _listdata !== "undefined" && _listdata !== null) {
  2377                 if (_listdata.hasOwnProperty("length")) {
  2345                 if (_listdata.hasOwnProperty("length")) {
  2378                     var _l = _listdata.length;
  2346                     var _l = _listdata.length;
  2379                     for (var _i = 0; _i < _l; _i++) {
  2347                     for (var _i = 0; _i < _l; _i++) {
  2380                         _list.push(_type.deserializer(_listdata[_i], _source));
  2348                         var _element = _type.deserializer(_listdata[_i], _source);
       
  2349                         if (typeof _element !== "undefined" && _element) {
       
  2350                             _list.push(_element);
       
  2351                         }
  2381                     }
  2352                     }
  2382                 } else {
  2353                 } else {
  2383                     _list.push(_type.deserializer(_listdata, _source));
  2354                     var _element = _type.deserializer(_listdata, _source);
       
  2355                     if (typeof _element !== "undefined" && _element) {
       
  2356                         _list.push(_element);
       
  2357                     }
  2384                 }
  2358                 }
  2385             }
  2359             }
  2386             _source.addList(_typename, _list);
  2360             _source.addList(_typename, _list);
  2387         });
  2361         });
  2388         
  2362         
  2389         if (typeof _data.meta !== "undefined") {
  2363         if (typeof _data.meta !== "undefined") {
  2390             _source.projectId = _data.meta.id;
  2364             _source.projectId = _data.meta.id;
  2391         }
  2365         }
  2392         
  2366         
  2393         if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") {
  2367         if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") {
  2394             _source.setCurrentMediaId(_data.meta.main_media["id-ref"]);
  2368             _source.mainMedia = _data.meta.main_media["id-ref"];
  2395         }
  2369         }
  2396         _source.setDefaultCurrentMedia();
       
  2397     }
  2370     }
  2398 }
  2371 }
  2399 
  2372 
  2400 /* Used when Putting annotations on the platform */
  2373 /* Used when Putting annotations on the platform */
  2401 
  2374