src/js/model.js
changeset 965 eadb7290c325
parent 964 d7d56ea2d0a6
child 969 353b0881a0b9
equal deleted inserted replaced
964:d7d56ea2d0a6 965:eadb7290c325
   444 IriSP.Model.Media = function(_id, _source) {
   444 IriSP.Model.Media = function(_id, _source) {
   445     IriSP.Model.Element.call(this, _id, _source);
   445     IriSP.Model.Element.call(this, _id, _source);
   446     this.elementType = 'media';
   446     this.elementType = 'media';
   447     this.duration = new IriSP.Model.Time();
   447     this.duration = new IriSP.Model.Time();
   448     this.video = '';
   448     this.video = '';
       
   449     var _this = this;
       
   450     this.on("timeupdate", function(_time) {
       
   451         _this.getAnnotations().filter(function(_a) {
       
   452             return (_a.end <= _time || _a.begin > _time) && _a.playing
       
   453         }).forEach(function(_a) {
       
   454             _a.playing = false;
       
   455             _a.trigger("leave");
       
   456         });
       
   457         _this.getAnnotations().filter(function(_a) {
       
   458             return _a.begin <= _time && _a.end > _time && !_a.playing
       
   459         }).forEach(function(_a) {
       
   460             _a.playing = true;
       
   461             _a.trigger("enter");
       
   462         });
       
   463     });
   449 }
   464 }
   450 
   465 
   451 IriSP.Model.Media.prototype = new IriSP.Model.Element();
   466 IriSP.Model.Media.prototype = new IriSP.Model.Element();
   452 
   467 
   453 /* Default functions to be overriden by players */
   468 /* Default functions to be overriden by players */
   518 IriSP.Model.Annotation = function(_id, _source) {
   533 IriSP.Model.Annotation = function(_id, _source) {
   519     IriSP.Model.Element.call(this, _id, _source);
   534     IriSP.Model.Element.call(this, _id, _source);
   520     this.elementType = 'annotation';
   535     this.elementType = 'annotation';
   521     this.begin = new IriSP.Model.Time();
   536     this.begin = new IriSP.Model.Time();
   522     this.end = new IriSP.Model.Time();
   537     this.end = new IriSP.Model.Time();
       
   538     this.playing = false;
   523     var _this = this;
   539     var _this = this;
   524     this.on("click", function() {
   540     this.on("click", function() {
   525         _this.getMedia().setCurrentTime(_this.begin);
   541         _this.getMedia().setCurrentTime(_this.begin);
   526     })
   542     });
   527 }
   543 }
   528 
   544 
   529 IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
   545 IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
   530 
   546 
   531 IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) {
   547 IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) {
   577     this.begin = new IriSP.Model.Time(_mashup.duration);
   593     this.begin = new IriSP.Model.Time(_mashup.duration);
   578     this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration());
   594     this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration());
   579     this.title = this.annotation.title;
   595     this.title = this.annotation.title;
   580     this.description = this.annotation.description;
   596     this.description = this.annotation.description;
   581     this.color = this.annotation.color;
   597     this.color = this.annotation.color;
       
   598     var _this = this;
       
   599     this.on("click", function() {
       
   600         _mashup.setCurrentTime(_this.begin);
       
   601     });
   582 }
   602 }
   583 
   603 
   584 IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null);
   604 IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null);
   585 
   605 
   586 IriSP.Model.MashedAnnotation.prototype.getMedia = function() {
   606 IriSP.Model.MashedAnnotation.prototype.getMedia = function() {
   609     IriSP.Model.Element.call(this, _id, _source);
   629     IriSP.Model.Element.call(this, _id, _source);
   610     this.elementType = 'mashup';
   630     this.elementType = 'mashup';
   611     this.duration = new IriSP.Model.Time();
   631     this.duration = new IriSP.Model.Time();
   612     this.segments = new IriSP.Model.List(_source.directory);
   632     this.segments = new IriSP.Model.List(_source.directory);
   613     this.medias = new IriSP.Model.List(_source.directory);
   633     this.medias = new IriSP.Model.List(_source.directory);
       
   634     var _currentMedia = null;
       
   635     var _this = this;
       
   636     this.on("timeupdate", function(_time) {
       
   637         _this.getAnnotations().filter(function(_a) {
       
   638             return (_a.end <= _time || _a.begin > _time) && _a.playing
       
   639         }).forEach(function(_a) {
       
   640             _a.playing = false;
       
   641             _a.trigger("leave");
       
   642         });
       
   643         _this.getAnnotations().filter(function(_a) {
       
   644             return _a.begin <= _time && _a.end > _time && !_a.playing
       
   645         }).forEach(function(_a) {
       
   646             _a.playing = true;
       
   647             _a.trigger("enter");
       
   648             var _m = _a.getMedia();
       
   649             if (_m !== _currentMedia) {
       
   650                 if (_currentMedia) {
       
   651                     _currentMedia.trigger("leave");
       
   652                 }
       
   653                 _m.trigger("enter");
       
   654                 _currentMedia = _m;
       
   655             }
       
   656         });
       
   657     });
   614 }
   658 }
   615 
   659 
   616 IriSP.Model.Mashup.prototype = new IriSP.Model.Element();
   660 IriSP.Model.Mashup.prototype = new IriSP.Model.Element();
   617 
   661 
   618 IriSP.Model.Mashup.prototype.addSegment = function(_annotation) {
   662 IriSP.Model.Mashup.prototype.addSegment = function(_annotation) {