src/js/popcorn.youtube.js
author hamidouk
Tue, 18 Oct 2011 11:45:45 +0200
branchpopcorn-port
changeset 80 8d0dbb1e62c8
parent 51 1444edeae73f
child 91 a66b10b06c01
permissions -rw-r--r--
added a mock serializer object for unit testing.
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
        dataLoaded = false,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    18
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    19
        // state code for volume changed polling
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    20
        volumeChanged = false,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    21
        lastMuted = false,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    22
        lastVolume = 0;
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
    container.id = media.id + Popcorn.guid();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    25
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    26
    media.appendChild( container );
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
    var youtubeInit = function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    29
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    30
      var flashvars,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    31
          params,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    32
          attributes,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    33
          src;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    34
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    35
      // 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
    36
      onYouTubePlayerReady[ container.id ] = function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    37
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    38
        youtubeObject = document.getElementById( container.id );
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
        // more youtube callback nonsense
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    41
        onYouTubePlayerReady.stateChangeEventHandler[ container.id ] = function( state ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    42
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    43
          // playing is state 1
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    44
          // paused is state 2
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    45
          if ( state === 1 ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    46
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    47
            media.paused && media.play();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    48
          // youtube fires paused events while seeking
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    49
          // 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
    50
          } else if ( state === 2 ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    51
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    52
            // 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
    53
            // calling youtube.seekTo triggers multiple events
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    54
            // 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
    55
            if ( seeking && seekTime === currentTime && seekTime !== youtubeObject.getCurrentTime() ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    56
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    57
              seeking = false;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    58
              youtubeObject.seekTo( currentTime );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    59
              return;
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    62
            currentTime = youtubeObject.getCurrentTime();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    63
            media.dispatchEvent( "timeupdate" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    64
            !media.paused && media.pause();
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    68
        // 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
    69
        youtubeObject.addEventListener( "onStateChange", "onYouTubePlayerReady.stateChangeEventHandler." + container.id );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    70
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    71
        var timeupdate = function() {
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
          if ( !media.paused ) {
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
            currentTime = youtubeObject.getCurrentTime();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    76
            media.dispatchEvent( "timeupdate" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    77
            setTimeout( timeupdate, 10 );
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    81
        var volumeupdate = function() {
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
          if ( lastMuted !== youtubeObject.isMuted() ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    84
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    85
            lastMuted = youtubeObject.isMuted();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    86
            media.dispatchEvent( "volumechange" );
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    89
          if ( lastVolume !== youtubeObject.getVolume() ) {
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
            lastVolume = youtubeObject.getVolume();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    92
            media.dispatchEvent( "volumechange" );
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    95
          setTimeout( volumeupdate, 250 );
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    98
        media.play = function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
    99
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   100
          media.paused = false;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   101
          media.dispatchEvent( "play" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   102
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   103
          if ( dataLoaded ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   104
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   105
            media.dispatchEvent( "loadeddata" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   106
            dataLoaded = false;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   107
          }
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
          media.dispatchEvent( "playing" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   110
          timeupdate();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   111
          youtubeObject.playVideo();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   112
        };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   113
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   114
        media.pause = function() {
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
          if ( !media.paused ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   117
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   118
            media.paused = true;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   119
            media.dispatchEvent( "pause" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   120
            youtubeObject.pauseVideo();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   121
          }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   122
        };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   123
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   124
        Popcorn.player.defineProperty( media, "currentTime", {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   125
          set: function( val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   126
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   127
            // make sure val is a number
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   128
            currentTime = seekTime = +val;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   129
            seeking = true;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   130
            media.dispatchEvent( "seeked" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   131
            media.dispatchEvent( "timeupdate" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   132
            youtubeObject.seekTo( currentTime );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   133
            return currentTime;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   134
          },
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   135
          get: function() {
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
            return currentTime;
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
        });
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
        Popcorn.player.defineProperty( media, "muted", {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   142
          set: function( val ) {
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
            if ( youtubeObject.isMuted() !== val ) {
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
              if ( val ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   147
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   148
                youtubeObject.mute();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   149
              } else {
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
                youtubeObject.unMute();
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   154
              lastMuted = youtubeObject.isMuted();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   155
              media.dispatchEvent( "volumechange" );
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
            return youtubeObject.isMuted();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   159
          },
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   160
          get: function() {
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
            return youtubeObject.isMuted();
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
        });
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   165
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   166
        Popcorn.player.defineProperty( media, "volume", {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   167
          set: function( val ) {
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
            if ( youtubeObject.getVolume() !== val ) {
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
              youtubeObject.setVolume( val );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   172
              lastVolume = youtubeObject.getVolume();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   173
              media.dispatchEvent( "volumechange" );
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
            return youtubeObject.getVolume();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   177
          },
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   178
          get: function() {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   179
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   180
            return youtubeObject.getVolume();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   181
          }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   182
        });
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   183
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   184
        media.readyState = 4;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   185
        media.dispatchEvent( "load" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   186
        dataLoaded = true;
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   187
        media.duration = youtubeObject.getDuration();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   188
        media.dispatchEvent( "durationchange" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   189
        volumeupdate();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   190
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   191
        if ( !media.paused ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   192
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   193
          media.play();
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   196
        media.paused && media.dispatchEvent( "loadeddata" );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   197
      };
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
      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
   200
      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
   201
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   202
      flashvars = {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   203
        playerapiid: container.id,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   204
        controls: options.controls,
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   205
        iv_load_policy: options.annotations
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   206
      };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   207
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   208
      params = {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   209
        wmode: "transparent",
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   210
        allowScriptAccess: "always"
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   211
      };
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
      attributes = {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   214
        id: container.id
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
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   217
      src = /^.*[\/=](.{11})/.exec( media.src )[ 1 ];
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
      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
   220
                          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
   221
                          flashvars, params, attributes );
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   222
    };
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   223
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   224
    if ( !window.swfobject ) {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   225
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   226
      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
   227
    } else {
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   228
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   229
      youtubeInit();
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   230
    }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   231
  }
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   232
});
1444edeae73f Adding required popcorn files. Also changed the build file to include those
hamidouk
parents:
diff changeset
   233