1 /** The minplayer namespace. */ 2 var minplayer = minplayer || {}; 3 4 /** All the media player implementations */ 5 minplayer.players = minplayer.players || {}; 6 7 /** 8 * @constructor 9 * @extends minplayer.players.base 10 * @class The vimeo media player. 11 * 12 * @param {object} context The jQuery context. 13 * @param {object} options This components options. 14 * @param {function} ready Called when the player is ready. 15 */ 16 minplayer.players.vimeo = function(context, options, ready) { 17 18 // Derive from players base. 19 minplayer.players.base.call(this, context, options, ready); 20 }; 21 22 /** Derive from minplayer.players.base. */ 23 minplayer.players.vimeo.prototype = new minplayer.players.base(); 24 25 /** Reset the constructor. */ 26 minplayer.players.vimeo.prototype.constructor = minplayer.players.vimeo; 27 28 /** 29 * @see minplayer.players.base#getPriority 30 * @return {number} The priority of this media player. 31 */ 32 minplayer.players.vimeo.getPriority = function() { 33 return 10; 34 }; 35 36 /** 37 * @see minplayer.players.base#canPlay 38 * @return {boolean} If this player can play this media type. 39 */ 40 minplayer.players.vimeo.canPlay = function(file) { 41 42 // Check for the mimetype for vimeo. 43 if (file.mimetype === 'video/vimeo') { 44 return true; 45 } 46 47 // If the path is a vimeo path, then return true. 48 return (file.path.search(/^http(s)?\:\/\/(www\.)?vimeo\.com/i) === 0); 49 }; 50 51 /** 52 * Return the ID for a provided media file. 53 * 54 * @param {object} file A {@link minplayer.file} object. 55 * @return {string} The ID for the provided media. 56 */ 57 minplayer.players.vimeo.getMediaId = function(file) { 58 var regex = /^http[s]?\:\/\/(www\.)?vimeo\.com\/(\?v\=)?([0-9]+)/i; 59 if (file.path.search(regex) === 0) { 60 return file.path.replace(regex, '$3'); 61 } 62 else { 63 return file.path; 64 } 65 }; 66 67 /** 68 * @see minplayer.players.base#reset 69 */ 70 minplayer.players.vimeo.prototype.reset = function() { 71 72 // Reset the flash variables.. 73 minplayer.players.base.prototype.reset.call(this); 74 }; 75 76 /** 77 * @see minplayer.players.base#create 78 * @return {object} The media player entity. 79 */ 80 minplayer.players.vimeo.prototype.create = function() { 81 minplayer.players.base.prototype.create.call(this); 82 83 // Insert the Vimeo Froogaloop player. 84 var tag = document.createElement('script'); 85 tag.src = 'http://a.vimeocdn.com/js/froogaloop2.min.js'; 86 var firstScriptTag = document.getElementsByTagName('script')[0]; 87 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 88 89 // Create the iframe for this player. 90 var iframe = document.createElement('iframe'); 91 iframe.setAttribute('id', this.options.id + '-player'); 92 iframe.setAttribute('type', 'text/html'); 93 iframe.setAttribute('width', '100%'); 94 iframe.setAttribute('height', '100%'); 95 iframe.setAttribute('frameborder', '0'); 96 97 // Get the source. 98 var src = 'http://player.vimeo.com/video/'; 99 src += this.mediaFile.id + '?'; 100 101 // Add the parameters to the src. 102 src += jQuery.param({ 103 'wmode': 'opaque', 104 'api': 1, 105 'player_id': this.options.id + '-player', 106 'title': 0, 107 'byline': 0, 108 'portrait': 0, 109 'autoplay': this.options.autoplay, 110 'loop': this.options.loop 111 }); 112 113 // Set the source of the iframe. 114 iframe.setAttribute('src', src); 115 116 // Now register this player when the froogaloop code is loaded. 117 var _this = this; 118 var check = setInterval(function() { 119 if (window.Froogaloop) { 120 clearInterval(check); 121 _this.media = window.Froogaloop(iframe); 122 _this.media.addEvent('ready', function() { 123 _this.onReady(); 124 }); 125 } 126 }, 200); 127 128 // Trigger that the load has started. 129 this.trigger('loadstart'); 130 131 // Return the player. 132 return iframe; 133 }; 134 135 /** 136 * @see minplayer.players.base#onReady 137 */ 138 minplayer.players.vimeo.prototype.onReady = function(player_id) { 139 // Store the this pointer within this context. 140 var _this = this; 141 142 // Add the other listeners. 143 this.media.addEvent('loadProgress', function(progress) { 144 145 // Set the duration, bytesLoaded, and bytesTotal. 146 _this.duration.set(parseFloat(progress.duration)); 147 _this.bytesLoaded.set(progress.bytesLoaded); 148 _this.bytesTotal.set(progress.bytesTotal); 149 }); 150 151 this.media.addEvent('playProgress', function(progress) { 152 153 // Set the duration and current time. 154 _this.duration.set(parseFloat(progress.duration)); 155 _this.currentTime.set(parseFloat(progress.seconds)); 156 }); 157 158 this.media.addEvent('play', function() { 159 _this.onPlaying(); 160 }); 161 162 this.media.addEvent('pause', function() { 163 _this.onPaused(); 164 }); 165 166 this.media.addEvent('finish', function() { 167 _this.onComplete(); 168 }); 169 170 minplayer.players.base.prototype.onReady.call(this); 171 this.onLoaded(); 172 }; 173 174 /** 175 * Checks to see if this player can be found. 176 * @return {bool} TRUE - Player is found, FALSE - otherwise. 177 */ 178 minplayer.players.vimeo.prototype.playerFound = function() { 179 var iframe = this.display.find('iframe#' + this.options.id + '-player'); 180 return (iframe.length > 0); 181 }; 182 183 /** 184 * @see minplayer.players.base#play 185 */ 186 minplayer.players.vimeo.prototype.play = function() { 187 minplayer.players.base.prototype.play.call(this); 188 if (this.isReady()) { 189 this.media.api('play'); 190 } 191 }; 192 193 /** 194 * @see minplayer.players.base#pause 195 */ 196 minplayer.players.vimeo.prototype.pause = function() { 197 minplayer.players.base.prototype.pause.call(this); 198 if (this.isReady()) { 199 this.media.api('pause'); 200 } 201 }; 202 203 /** 204 * @see minplayer.players.base#stop 205 */ 206 minplayer.players.vimeo.prototype.stop = function() { 207 minplayer.players.base.prototype.stop.call(this); 208 if (this.isReady()) { 209 this.media.api('unload'); 210 } 211 }; 212 213 /** 214 * @see minplayer.players.base#seek 215 */ 216 minplayer.players.vimeo.prototype.seek = function(pos) { 217 minplayer.players.base.prototype.seek.call(this, pos); 218 if (this.isReady()) { 219 this.media.api('seekTo', pos); 220 } 221 }; 222 223 /** 224 * @see minplayer.players.base#setVolume 225 */ 226 minplayer.players.vimeo.prototype.setVolume = function(vol) { 227 minplayer.players.base.prototype.setVolume.call(this, vol); 228 if (this.isReady()) { 229 this.volume.set(vol); 230 this.media.api('setVolume', vol); 231 } 232 }; 233 234 /** 235 * @see minplayer.players.base#getVolume 236 */ 237 minplayer.players.vimeo.prototype.getVolume = function(callback) { 238 var _this = this; 239 this.media.api('getVolume', function(vol) { 240 callback(vol); 241 }); 242 }; 243