src/widgets/Mediafragment.js
branchplayers-as-widgets
changeset 957 4da0a5740b6c
parent 916 ec6849bbbdcc
child 964 d7d56ea2d0a6
equal deleted inserted replaced
956:7c1d08cf6956 957:4da0a5740b6c
     8             if (/^#/.test(_msg.data)) {
     8             if (/^#/.test(_msg.data)) {
     9                 this.setWindowHash(_msg.data);
     9                 this.setWindowHash(_msg.data);
    10             }
    10             }
    11         })
    11         })
    12     };
    12     };
    13     this.bindPopcorn("pause","setHashToTime");
    13     this.onMdpEvent("Mediafragment.setHashToAnnotation","setHashToAnnotation");
    14     this.bindPopcorn("seeked","setHashToTime");
       
    15     this.bindPopcorn("IriSP.Mediafragment.setHashToAnnotation","setHashToAnnotation");
       
    16     this.blocked = false;
    14     this.blocked = false;
    17 }
    15 }
    18 
    16 
    19 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    17 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    20 
    18 
    21 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    19 IriSP.Widgets.Mediafragment.prototype.draw = function() {
       
    20     this.onMediaEvent("pause","setHashToTime");
       
    21     this.onMediaEvent("seeked","setHashToTime");
    22     this.goToHash();
    22     this.goToHash();
    23 }
    23 }
    24 
    24 
    25 IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) {
    25 IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) {
    26     if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") {
    26     if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") {
    50                 this.last_hash_key = _subtab[0];
    50                 this.last_hash_key = _subtab[0];
    51                 this.last_hash_value = _subtab[1];
    51                 this.last_hash_value = _subtab[1];
    52                 if (this.last_hash_key == "id") {
    52                 if (this.last_hash_key == "id") {
    53                     var _annotation = this.source.getElement(this.last_hash_value);
    53                     var _annotation = this.source.getElement(this.last_hash_value);
    54                     if (typeof _annotation !== "undefined") {
    54                     if (typeof _annotation !== "undefined") {
    55                         this.player.popcorn.currentTime(_annotation.begin.getSeconds());
    55                         this.media.setCurrentTime(_annotation.begin);
    56                     }
    56                     }
    57                 }
    57                 }
    58                 if (this.last_hash_key == "t") {
    58                 if (this.last_hash_key == "t") {
    59                     this.player.popcorn.currentTime(this.last_hash_value);
    59                     this.media.setCurrentTime(1000*this.last_hash_value);
    60                 }
    60                 }
    61                 break;
    61                 break;
    62             }
    62             }
    63         }
    63         }
    64     }
    64     }
    66 
    66 
    67 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
    67 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
    68     this.setHash( 'id', _annotationId );
    68     this.setHash( 'id', _annotationId );
    69 }
    69 }
    70 
    70 
    71 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) {
    71 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() {
    72     if (_time !== NaN) {
    72     this.setHash( 't', this.media.getCurrentTime().getSeconds() );
    73         this.setHash( 't', this.player.popcorn.currentTime() );
       
    74     }
       
    75 }
    73 }
    76 
    74 
    77 IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) {
    75 IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) {
    78     if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) {
    76     if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) {
    79         this.last_hash_key = _key;
    77         this.last_hash_key = _key;
    98 IriSP.Widgets.Mediafragment.prototype.block = function() {
    96 IriSP.Widgets.Mediafragment.prototype.block = function() {
    99     if (typeof this.blockTimeout !== "undefined") {
    97     if (typeof this.blockTimeout !== "undefined") {
   100         window.clearTimeout(this.blockTimeout);
    98         window.clearTimeout(this.blockTimeout);
   101     }
    99     }
   102     this.blocked = true;
   100     this.blocked = true;
   103     this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1000);
   101     this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1500);
   104 }
   102 }