src/js/popcorn.jwplayer.js
author hamidouk
Mon, 17 Oct 2011 16:03:20 +0200
branchpopcorn-port
changeset 79 1b5393f529dd
parent 62 aa30f4339117
permissions -rw-r--r--
fixed critical infinite recursion bug in popcorn.jwplayer.js.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     1
var jwplayerObjects = {};
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     2
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     3
Popcorn.player( "jwplayer", {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     4
  _setup: function( options ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     5
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     6
    var media = this,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     7
        player = {},
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     8
        container = document.createElement( "div" ),
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
     9
        currentTime = 0,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    10
        seekTime = 0,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    11
        seeking = false,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    12
        dataLoaded = false;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    13
    container.id = media.id + Popcorn.guid();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    14
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    15
    media.appendChild( container );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    16
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    17
  var initApi = function () {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    18
    jwplayer( container.id ).onTime(function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    19
        currentTime = jwplayer(container.id).getPosition();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    20
        media.dispatchEvent( "timeupdate" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    21
       // timeout = setTimeout( timeupdate, 10 );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    22
    });
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    23
    
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    24
    media.play = function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    25
      media.paused = false;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    26
      media.dispatchEvent( "play" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    27
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    28
      media.dispatchEvent( "playing" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    29
      jwplayer( container.id ).play();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    30
    };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    31
    
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    32
    media.pause = function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    33
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    34
      if ( !media.paused ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    35
        media.paused = true;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    36
        media.dispatchEvent( "pause" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    37
        jwplayer( container.id ).pause();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    38
      }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    39
    };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    40
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    41
    Popcorn.player.defineProperty( media, "currentTime", {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    42
          set: function( val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    43
            // make sure val is a number
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    44
            currentTime = seekTime = +val;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    45
            seeking = true;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    46
            media.dispatchEvent( "seeked" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    47
            media.dispatchEvent( "timeupdate" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    48
            jwplayer( container.id ).seek( currentTime );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    49
            return currentTime;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    50
          },
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    51
          get: function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    52
            return jwplayer( container.id ).getPosition();            
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    53
          }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    54
        });
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    55
 
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    56
    Popcorn.player.defineProperty( media, "muted", {   
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    57
        set: function( val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    58
          if ( jwplayer( container.id ).getMute() !== val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    59
            if ( val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    60
              jwplayer( container.id ).setMute(true);
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    61
            } else {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    62
              jwplayer( container.id ).setMute(false);
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    63
            }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    64
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    65
            media.dispatchEvent( "volumechange" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    66
          }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    67
          
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    68
          return jwplayer( container.id ).getMute();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    69
        },
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    70
        get: function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    71
          return jwplayer( container.id ).getMute();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    72
        }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    73
    });
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    74
  
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    75
    Popcorn.player.defineProperty( media, "volume", {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    76
    
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    77
      set: function( val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    78
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    79
        if ( jwplayer( container.id ).getVolume() !== val *100 ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    80
          jwplayer( container.id ).setVolume( val * 100);
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    81
          media.dispatchEvent( "volumechange" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    82
        }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    83
        
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    84
        return (jwplayer( container.id ).getVolume()) / 100;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    85
      },
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    86
      
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    87
      get: function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    88
        return jwplayer( container.id ).getVolume() / 100;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    89
      }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    90
    });
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    91
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    92
    media.readyState = 4;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    93
    media.dispatchEvent( 'load' );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    94
    dataLoaded = true;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    95
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    96
    media.duration = options.duration;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    97
    media.dispatchEvent( 'durationchange' );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    98
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    99
    media.paused && media.dispatchEvent( 'loadeddata' );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   100
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   101
    };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   102
54
bbcf7423f543 Rajouté des fichiers nécessaires à jwplayer.js.
hamidouk
parents: 51
diff changeset
   103
    options.events = {
62
aa30f4339117 removed a comma which made ie trip-out
hamidouk
parents: 55
diff changeset
   104
        onReady: initApi
79
1b5393f529dd fixed critical infinite recursion bug in popcorn.jwplayer.js.
hamidouk
parents: 62
diff changeset
   105
      };
1b5393f529dd fixed critical infinite recursion bug in popcorn.jwplayer.js.
hamidouk
parents: 62
diff changeset
   106
      
54
bbcf7423f543 Rajouté des fichiers nécessaires à jwplayer.js.
hamidouk
parents: 51
diff changeset
   107
    jwplayer( container.id ).setup(options);
51
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   108
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   109
  }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   110
});
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   111