src/js/modules/mediafragment.js
branchpopcorn-port
changeset 466 d54cf60bb842
parent 462 3583ef3b208b
child 587 cd051898866e
equal deleted inserted replaced
465:daa60afb3a50 466:d54cf60bb842
     1 /* mediafragment module */
     1 /* mediafragment module */
     2 
     2 
     3 IriSP.MediaFragment = function(Popcorn, config, Serializer) {
     3 IriSP.MediaFragment = function(Popcorn, config, Serializer) {
     4   IriSP.Module.call(this, Popcorn, config, Serializer);
     4   IriSP.Module.call(this, Popcorn, config, Serializer);
     5 
     5 
       
     6   this.mutex = false; /* a mutex because we access the url from two different functions */
       
     7 
     6   this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this, IriSP.MediaFragment.advanceTime));
     8   this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this, IriSP.MediaFragment.advanceTime));
     7 //  this._Popcorn.listen( "pause", IriSP.wrap(this, IriSP.MediaFragment.updateTime));
     9   this._Popcorn.listen( "pause", IriSP.wrap(this, IriSP.MediaFragment.updateTime));
     8 //  this._Popcorn.listen( "seeked", IriSP.wrap(this, IriSP.MediaFragment.updateTime));
    10   this._Popcorn.listen( "seeked", IriSP.wrap(this, IriSP.MediaFragment.updateTime));
     9   this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this, IriSP.MediaFragment.updateAnnotation));
    11   this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this, IriSP.MediaFragment.updateAnnotation));
    10   this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this, IriSP.MediaFragment.updateAnnotation));
    12   this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this, IriSP.MediaFragment.updateAnnotation));
    11 };
    13 };
    12 
    14 
    13 IriSP.MediaFragment.advanceTime = function() {
    15 IriSP.MediaFragment.advanceTime = function() {
    34                   }
    36                   }
    35               }
    37               }
    36 };
    38 };
    37 
    39 
    38 IriSP.MediaFragment.updateTime = function() {
    40 IriSP.MediaFragment.updateTime = function() {
       
    41   if (this.mutex === true) {
       
    42     return;
       
    43   }
       
    44 
    39   var history = window.history;
    45   var history = window.history;
    40   if ( !history.pushState ) {
    46   if ( !history.pushState ) {
    41     return false;
    47     return false;
    42   }
    48   }
    43   
    49   
    45   history.replaceState( {}, "", splitArr[0] + "#t=" + this._Popcorn.currentTime().toFixed( 2 ) );
    51   history.replaceState( {}, "", splitArr[0] + "#t=" + this._Popcorn.currentTime().toFixed( 2 ) );
    46 };
    52 };
    47 
    53 
    48 
    54 
    49 IriSP.MediaFragment.updateAnnotation = function(annotationId) {
    55 IriSP.MediaFragment.updateAnnotation = function(annotationId) {
       
    56   var _this = this;
       
    57   this.mutex = true;
       
    58 
    50   var history = window.history;
    59   var history = window.history;
    51   if ( !history.pushState ) {
    60   if ( !history.pushState ) {
    52     return false;
    61     return false;
    53   }
    62   }
    54   
    63   
    55   splitArr = window.location.href.split( "#" )
    64   splitArr = window.location.href.split( "#" )
    56   history.replaceState( {}, "", splitArr[0] + "#a=" + annotationId);
    65   history.replaceState( {}, "", splitArr[0] + "#a=" + annotationId);
    57  
    66  
       
    67   window.setTimeout(function() { _this.mutex = false }, 50);
    58 };
    68 };
    59 
    69 
    60 // lookup and seek to the beginning of an annotation
    70 // lookup and seek to the beginning of an annotation
    61 IriSP.MediaFragment.lookupAnnotation = function(annotationId) {
    71 IriSP.MediaFragment.lookupAnnotation = function(annotationId) {
    62   var annotation = undefined;
    72   var annotation = undefined;