test/integration/allocine_dossier_independant/js/libs/popcorn.youtube.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
// A global callback for youtube... that makes me angry
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     2
var onYouTubePlayerReady = function( containerId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     3
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     4
  onYouTubePlayerReady[ containerId ] && onYouTubePlayerReady[ containerId ]();
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
onYouTubePlayerReady.stateChangeEventHandler = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     7
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     8
Popcorn.player( "youtube", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     9
  _setup: function( options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    10
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    11
    var media = this,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    12
        youtubeObject,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    13
        container = document.createElement( "div" ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    14
        currentTime = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    15
        seekTime = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    16
        seeking = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    17
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    18
        // state code for volume changed polling
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    19
        volumeChanged = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    20
        lastMuted = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    21
        lastVolume = 0;
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
    container.id = media.id + Popcorn.guid();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    24
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    25
    media.appendChild( container );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    26
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    27
    var youtubeInit = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    28
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    29
      var flashvars,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    30
          params,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    31
          attributes,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    32
          src;
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
      // expose a callback to this scope, that is called from the global callback youtube calls
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    35
      onYouTubePlayerReady[ container.id ] = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    36
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    37
        youtubeObject = document.getElementById( container.id );
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
        // more youtube callback nonsense
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    40
        onYouTubePlayerReady.stateChangeEventHandler[ container.id ] = function( state ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    41
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    42
          // playing is state 1
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    43
          // paused is state 2
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    44
          if ( state === 1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    45
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    46
            media.paused && media.play();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    47
          // youtube fires paused events while seeking
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    48
          // this is the only way to get seeking events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    49
          } else if ( state === 2 ) {
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
            // silly logic forced on me by the youtube API
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    52
            // calling youtube.seekTo triggers multiple events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    53
            // with the second events getCurrentTime being the old time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    54
            if ( seeking && seekTime === currentTime && seekTime !== youtubeObject.getCurrentTime() ) {
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
              seeking = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    57
              youtubeObject.seekTo( currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    58
              return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    59
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    60
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    61
            currentTime = youtubeObject.getCurrentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    62
            media.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    63
            !media.paused && media.pause();
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
        };
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
        // youtube requires callbacks to be a string to a function path from the global scope
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    68
        youtubeObject.addEventListener( "onStateChange", "onYouTubePlayerReady.stateChangeEventHandler." + container.id );
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
        var timeupdate = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    71
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    72
          if ( !media.paused ) {
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
            currentTime = youtubeObject.getCurrentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    75
            media.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    76
            setTimeout( timeupdate, 10 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    77
          }
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    80
        var volumeupdate = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    81
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    82
          if ( lastMuted !== youtubeObject.isMuted() ) {
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
            lastMuted = youtubeObject.isMuted();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    85
            media.dispatchEvent( "volumechange" );
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    88
          if ( lastVolume !== youtubeObject.getVolume() ) {
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
            lastVolume = youtubeObject.getVolume();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    91
            media.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    92
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    93
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    94
          setTimeout( volumeupdate, 250 );
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    97
        media.play = function() {
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 = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   100
          media.dispatchEvent( "play" );
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
          media.dispatchEvent( "playing" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   103
          timeupdate();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   104
          youtubeObject.playVideo();
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
        media.pause = function() {
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
          if ( !media.paused ) {
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
            media.paused = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   112
            media.dispatchEvent( "pause" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   113
            youtubeObject.pauseVideo();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   114
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   115
        };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   116
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   117
        Popcorn.player.defineProperty( media, "currentTime", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   118
          set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   119
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   120
            // make sure val is a number
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   121
            currentTime = seekTime = +val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   122
            seeking = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   123
            media.dispatchEvent( "seeked" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   124
            media.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   125
            youtubeObject.seekTo( currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   126
            return currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   127
          },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   128
          get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   129
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   130
            return currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   131
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   132
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   133
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   134
        Popcorn.player.defineProperty( media, "muted", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   135
          set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   136
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   137
            if ( youtubeObject.isMuted() !== val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   138
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   139
              if ( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   140
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   141
                youtubeObject.mute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   142
              } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   143
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   144
                youtubeObject.unMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   145
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   146
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   147
              lastMuted = youtubeObject.isMuted();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   148
              media.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   149
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   150
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   151
            return youtubeObject.isMuted();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   152
          },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   153
          get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   154
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   155
            return youtubeObject.isMuted();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   156
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   157
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   158
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   159
        Popcorn.player.defineProperty( media, "volume", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   160
          set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   161
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   162
            if ( youtubeObject.getVolume() !== val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   163
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   164
              youtubeObject.setVolume( val );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   165
              lastVolume = youtubeObject.getVolume();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   166
              media.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   167
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   168
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   169
            return youtubeObject.getVolume();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   170
          },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   171
          get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   172
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   173
            return youtubeObject.getVolume();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   174
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   175
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   176
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   177
        media.readyState = 4;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   178
        media.dispatchEvent( "load" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   179
        media.duration = youtubeObject.getDuration();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   180
        media.dispatchEvent( "durationchange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   181
        volumeupdate();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   182
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   183
        media.dispatchEvent( "loadeddata" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   184
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   185
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   186
      options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   187
      options.annotations = +options.annotations === 1 || +options.annotations === 3 ? options.annotations : 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   188
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   189
      flashvars = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   190
        playerapiid: container.id,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   191
        controls: options.controls,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   192
        iv_load_policy: options.annotations
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   193
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   194
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   195
      params = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   196
        wmode: "transparent",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   197
        allowScriptAccess: "always"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   198
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   199
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   200
      attributes = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   201
        id: container.id
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   202
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   203
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   204
      src = /^.*[\/=](.{11})/.exec( media.src )[ 1 ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   205
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   206
      swfobject.embedSWF( "http://www.youtube.com/e/" + src + "?enablejsapi=1&playerapiid=" + container.id + "&version=3",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   207
                          container.id, media.offsetWidth, media.offsetHeight, "8", null,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   208
                          flashvars, params, attributes );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   209
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   210
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   211
    if ( !window.swfobject ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   212
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   213
      Popcorn.getScript( "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", youtubeInit );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   214
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   215
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   216
      youtubeInit();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   217
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   218
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   219
});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   220