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