src/js/libs/popcorn.jwplayer.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 110 048125f1a167
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
110
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     1
var jwplayerObjects = {};
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     2
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     3
Popcorn.player( "jwplayer", {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     4
  _setup: function( options ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     5
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     6
    var media = this,
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     7
        player = {},
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     8
        container = document.createElement( "div" ),
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
     9
        currentTime = 0,
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    10
        seekTime = 0,
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    11
        seeking = false,
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    12
        dataLoaded = false;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    13
    container.id = media.id + Popcorn.guid();
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    14
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    15
    media.appendChild( container );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    16
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    17
  var initApi = function () {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    18
    jwplayer( container.id ).onTime(function() {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    19
        currentTime = jwplayer(container.id).getPosition();
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    20
        media.dispatchEvent( "timeupdate" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    21
       // timeout = setTimeout( timeupdate, 10 );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    22
    });
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    23
    
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    24
    media.play = function() {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    25
      media.paused = false;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    26
      media.dispatchEvent( "play" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    27
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    28
      media.dispatchEvent( "playing" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    29
      jwplayer( container.id ).play();
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    30
    };
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    31
    
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    32
    media.pause = function() {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    33
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    34
      if ( !media.paused ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    35
        media.paused = true;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    36
        media.dispatchEvent( "pause" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    37
        jwplayer( container.id ).pause();
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    38
      }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    39
    };
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    40
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    41
    Popcorn.player.defineProperty( media, "currentTime", {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    42
          set: function( val ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    43
            // make sure val is a number
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    44
            currentTime = seekTime = +val;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    45
            seeking = true;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    46
            media.dispatchEvent( "seeked" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    47
            media.dispatchEvent( "timeupdate" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    48
            jwplayer( container.id ).seek( currentTime );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    49
            return currentTime;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    50
          },
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    51
          get: function() {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    52
            return jwplayer( container.id ).getPosition();            
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    53
          }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    54
        });
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    55
 
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    56
    Popcorn.player.defineProperty( media, "muted", {   
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    57
        set: function( val ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    58
          if ( jwplayer( container.id ).getMute() !== val ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    59
            if ( val ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    60
              jwplayer( container.id ).setMute(true);
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    61
            } else {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    62
              jwplayer( container.id ).setMute(false);
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    63
            }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    64
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    65
            media.dispatchEvent( "volumechange" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    66
          }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    67
          
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    68
          return jwplayer( container.id ).getMute();
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    69
        },
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    70
        get: function() {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    71
          return jwplayer( container.id ).getMute();
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    72
        }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    73
    });
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    74
  
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    75
    Popcorn.player.defineProperty( media, "volume", {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    76
    
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    77
      set: function( val ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    78
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    79
        if ( jwplayer( container.id ).getVolume() !== val *100 ) {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    80
          jwplayer( container.id ).setVolume( val * 100);
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    81
          media.dispatchEvent( "volumechange" );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    82
        }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    83
        
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    84
        return (jwplayer( container.id ).getVolume()) / 100;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    85
      },
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    86
      
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    87
      get: function() {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    88
        return jwplayer( container.id ).getVolume() / 100;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    89
      }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    90
    });
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    91
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    92
    media.readyState = 4;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    93
    media.dispatchEvent( 'load' );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    94
    dataLoaded = true;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    95
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    96
    media.duration = options.duration;
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    97
    media.dispatchEvent( 'durationchange' );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    98
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
    99
    media.paused && media.dispatchEvent( 'loadeddata' );
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   100
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   101
    };
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   102
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   103
    options.events = {
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   104
        onReady: initApi
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   105
      };
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   106
      
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   107
    jwplayer( container.id ).setup(options);
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   108
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   109
  }
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   110
});
048125f1a167 moved external libraries to their own subdir.
hamidouk
parents:
diff changeset
   111