test/integration/allocine_dossier_independant/js/libs/popcorn.jwplayer.js
author cavaliet
Thu, 26 Apr 2012 12:09:56 +0200
changeset 878 c983360f0e7a
parent 819 9b8e68803f6f
permissions -rw-r--r--
SlideShareWidget better management of container.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     1
var jwplayerObjects = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     2
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     3
Popcorn.player( "jwplayer", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     4
  _setup: function( options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     5
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     6
    var media = this,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     7
        player = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     8
        container = document.createElement( "div" ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     9
        currentTime = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    10
        seekTime = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    11
        seeking = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    12
        dataLoaded = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    13
    container.id = media.id + Popcorn.guid();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    14
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    15
    media.appendChild( container );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    16
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    17
  var initApi = function () {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    18
    jwplayer( container.id ).onTime(function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    19
        currentTime = jwplayer(container.id).getPosition();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    20
        media.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    21
       // timeout = setTimeout( timeupdate, 10 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    22
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    23
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    24
    media.play = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    25
      media.paused = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    26
      media.dispatchEvent( "play" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    27
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    28
      media.dispatchEvent( "playing" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    29
      jwplayer( container.id ).play();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    30
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    31
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    32
    media.pause = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    33
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    34
      if ( !media.paused ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    35
        media.paused = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    36
        media.dispatchEvent( "pause" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    37
        jwplayer( container.id ).pause();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    38
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    39
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    40
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    41
    Popcorn.player.defineProperty( media, "currentTime", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    42
          set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    43
            // make sure val is a number
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    44
            currentTime = seekTime = +val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    45
            seeking = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    46
            media.dispatchEvent( "seeked" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    47
            media.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    48
            jwplayer( container.id ).seek( currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    49
            return currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    50
          },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    51
          get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    52
            return jwplayer( container.id ).getPosition();            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    53
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    54
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    55
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    56
    Popcorn.player.defineProperty( media, "muted", {   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    57
        set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    58
          if ( jwplayer( container.id ).getMute() !== val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    59
            if ( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    60
              jwplayer( container.id ).setMute(true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    61
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    62
              jwplayer( container.id ).setMute(false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    63
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    64
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    65
            media.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    66
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    67
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    68
          return jwplayer( container.id ).getMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    69
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    70
        get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    71
          return jwplayer( container.id ).getMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    72
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    73
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    74
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    75
    Popcorn.player.defineProperty( media, "volume", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    76
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    77
      set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    78
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    79
        if ( jwplayer( container.id ).getVolume() !== val *100 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    80
          jwplayer( container.id ).setVolume( val * 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    81
          media.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    82
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    83
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    84
        return (jwplayer( container.id ).getVolume()) / 100;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    85
      },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    86
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    87
      get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    88
        return jwplayer( container.id ).getVolume() / 100;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    89
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    90
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    91
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    92
    media.readyState = 4;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    93
    media.dispatchEvent( 'load' );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    94
    dataLoaded = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    95
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    96
    media.duration = options.duration;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    97
    media.dispatchEvent( 'durationchange' );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    98
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    99
    media.paused && media.dispatchEvent( 'loadeddata' );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   100
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   101
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   102
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   103
    options.events = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   104
        onReady: initApi
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   105
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   106
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   107
    jwplayer( container.id ).setup(options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   108
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   109
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   110
});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   111