src/js/libs/popcorn.mediafragment.js
author hamidouk
Wed, 09 Nov 2011 14:49:20 +0100
branchpopcorn-port
changeset 216 d1e891627286
child 263 2d87a07fa3d0
permissions -rw-r--r--
added and activated the mediafragment plugin?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     1
// PLUGIN: Mediafragment
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     2
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     3
(function ( Popcorn ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     4
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     5
  /**
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     6
   * Mediafragment popcorn plug-in
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     7
   * Adds (limited) support for mediafragment requests 
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     8
   * to a popcorn video.  
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     9
   * @param {Object} options
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    10
   *
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    11
  **/
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    12
    Popcorn.plugin( "mediafragment" , {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    13
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    14
      manifest: {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    15
        about: {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    16
          name: "Popcorn mediafragment plugin",
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    17
          version: "0.1",
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    18
          author: "Karim Hamidou",
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    19
          website: "http://neyret.fr/~karim"
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    20
        },
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    21
        options: {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    22
        }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    23
      },
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    24
      
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    25
    _setup: function( options ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    26
        var advanceTime = function() {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    27
              var url = window.location.href;
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    28
              
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    29
              if ( url.split("#")[1] != null ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    30
                  pageoffset = url.split( "#" )[1];							
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    31
                  
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    32
                  if ( pageoffset.substring( 2 ) != null ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    33
                    var offsettime = pageoffset.substring( 2 );						
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    34
                    this.currentTime(parseFloat(offsettime));
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    35
                  }							
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    36
              }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    37
        }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    38
        
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    39
        var updateTime = function() {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    40
            splitArr = window.location.href.split("#")			
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    41
            history.replaceState({}, "", splitArr[0] + "#t=" + this.currentTime().toFixed(2));
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    42
        };
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    43
        
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    44
        this.listen( 'loadedmetadata', advanceTime );        
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    45
        this.listen("pause", updateTime);
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    46
        this.listen("seeked", updateTime);
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    47
        
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    48
    },
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    49
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    50
    _teardown: function( options ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    51
      // FIXME: anything to implement here ?
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    52
    }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    53
  });
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    54
})( Popcorn );