[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 /*! 2 * MediaElement.js 3 * http://www.mediaelementjs.com/ 4 * 5 * Wrapper that mimics native HTML5 MediaElement (audio and video) 6 * using a variety of technologies (pure JavaScript, Flash, iframe) 7 * 8 * Copyright 2010-2017, John Dyer (http://j.hn/) 9 * License: MIT 10 * 11 */(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(_dereq_,module,exports){ 12 'use strict'; 13 14 var VimeoApi = { 15 16 promise: null, 17 18 load: function load(settings) { 19 20 if (typeof Vimeo !== 'undefined') { 21 VimeoApi._createPlayer(settings); 22 } else { 23 VimeoApi.promise = VimeoApi.promise || mejs.Utils.loadScript('https://player.vimeo.com/api/player.js'); 24 VimeoApi.promise.then(function () { 25 VimeoApi._createPlayer(settings); 26 }); 27 } 28 }, 29 30 _createPlayer: function _createPlayer(settings) { 31 var player = new Vimeo.Player(settings.iframe); 32 window['__ready__' + settings.id](player); 33 }, 34 35 getVimeoId: function getVimeoId(url) { 36 if (url == null) { 37 return null; 38 } 39 40 var parts = url.split('?'); 41 url = parts[0]; 42 43 var playerLinkMatch = url.match(/https:\/\/player.vimeo.com\/video\/(\d+)$/); 44 if (playerLinkMatch) { 45 return parseInt(playerLinkMatch[1], 10); 46 } 47 48 var vimeoLinkMatch = url.match(/https:\/\/vimeo.com\/(\d+)$/); 49 if (vimeoLinkMatch) { 50 return parseInt(vimeoLinkMatch[1], 10); 51 } 52 53 var privateVimeoLinkMatch = url.match(/https:\/\/vimeo.com\/(\d+)\/\w+$/); 54 if (privateVimeoLinkMatch) { 55 return parseInt(privateVimeoLinkMatch[1], 10); 56 } 57 58 return NaN; 59 } 60 }; 61 62 var vimeoIframeRenderer = { 63 64 name: 'vimeo_iframe', 65 options: { 66 prefix: 'vimeo_iframe' 67 }, 68 69 canPlayType: function canPlayType(type) { 70 return ~['video/vimeo', 'video/x-vimeo'].indexOf(type.toLowerCase()); 71 }, 72 73 create: function create(mediaElement, options, mediaFiles) { 74 var apiStack = [], 75 vimeo = {}, 76 readyState = 4; 77 78 var paused = true, 79 volume = 1, 80 oldVolume = volume, 81 currentTime = 0, 82 bufferedTime = 0, 83 ended = false, 84 duration = 0, 85 vimeoPlayer = null, 86 url = ''; 87 88 vimeo.options = options; 89 vimeo.id = mediaElement.id + '_' + options.prefix; 90 vimeo.mediaElement = mediaElement; 91 92 var errorHandler = function errorHandler(error) { 93 mediaElement.generateError('Code ' + error.name + ': ' + error.message, mediaFiles); 94 }; 95 96 var props = mejs.html5media.properties, 97 assignGettersSetters = function assignGettersSetters(propName) { 98 99 var capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1); 100 101 vimeo['get' + capName] = function () { 102 if (vimeoPlayer !== null) { 103 var value = null; 104 105 switch (propName) { 106 case 'currentTime': 107 return currentTime; 108 case 'duration': 109 return duration; 110 case 'volume': 111 return volume; 112 case 'muted': 113 return volume === 0; 114 case 'paused': 115 return paused; 116 case 'ended': 117 return ended; 118 case 'src': 119 vimeoPlayer.getVideoUrl().then(function (_url) { 120 url = _url; 121 }).catch(function (error) { 122 return errorHandler(error); 123 }); 124 return url; 125 case 'buffered': 126 return { 127 start: function start() { 128 return 0; 129 }, 130 end: function end() { 131 return bufferedTime * duration; 132 }, 133 length: 1 134 }; 135 case 'readyState': 136 return readyState; 137 } 138 return value; 139 } else { 140 return null; 141 } 142 }; 143 144 vimeo['set' + capName] = function (value) { 145 if (vimeoPlayer !== null) { 146 switch (propName) { 147 case 'src': 148 var _url2 = typeof value === 'string' ? value : value[0].src, 149 videoId = VimeoApi.getVimeoId(_url2); 150 151 vimeoPlayer.loadVideo(videoId).then(function () { 152 if (mediaElement.originalNode.autoplay) { 153 vimeoPlayer.play(); 154 } 155 }).catch(function (error) { 156 return errorHandler(error); 157 }); 158 break; 159 case 'currentTime': 160 vimeoPlayer.setCurrentTime(value).then(function () { 161 currentTime = value; 162 setTimeout(function () { 163 var event = mejs.Utils.createEvent('timeupdate', vimeo); 164 mediaElement.dispatchEvent(event); 165 }, 50); 166 }).catch(function (error) { 167 return errorHandler(error); 168 }); 169 break; 170 case 'volume': 171 vimeoPlayer.setVolume(value).then(function () { 172 volume = value; 173 oldVolume = volume; 174 setTimeout(function () { 175 var event = mejs.Utils.createEvent('volumechange', vimeo); 176 mediaElement.dispatchEvent(event); 177 }, 50); 178 }).catch(function (error) { 179 return errorHandler(error); 180 }); 181 break; 182 case 'loop': 183 vimeoPlayer.setLoop(value).catch(function (error) { 184 return errorHandler(error); 185 }); 186 break; 187 case 'muted': 188 if (value) { 189 vimeoPlayer.setVolume(0).then(function () { 190 volume = 0; 191 setTimeout(function () { 192 var event = mejs.Utils.createEvent('volumechange', vimeo); 193 mediaElement.dispatchEvent(event); 194 }, 50); 195 }).catch(function (error) { 196 return errorHandler(error); 197 }); 198 } else { 199 vimeoPlayer.setVolume(oldVolume).then(function () { 200 volume = oldVolume; 201 setTimeout(function () { 202 var event = mejs.Utils.createEvent('volumechange', vimeo); 203 mediaElement.dispatchEvent(event); 204 }, 50); 205 }).catch(function (error) { 206 return errorHandler(error); 207 }); 208 } 209 break; 210 case 'readyState': 211 var event = mejs.Utils.createEvent('canplay', vimeo); 212 mediaElement.dispatchEvent(event); 213 break; 214 default: 215 216 break; 217 } 218 } else { 219 apiStack.push({ type: 'set', propName: propName, value: value }); 220 } 221 }; 222 }; 223 224 for (var i = 0, total = props.length; i < total; i++) { 225 assignGettersSetters(props[i]); 226 } 227 228 var methods = mejs.html5media.methods, 229 assignMethods = function assignMethods(methodName) { 230 vimeo[methodName] = function () { 231 if (vimeoPlayer !== null) { 232 switch (methodName) { 233 case 'play': 234 paused = false; 235 return vimeoPlayer.play(); 236 case 'pause': 237 paused = true; 238 return vimeoPlayer.pause(); 239 case 'load': 240 return null; 241 } 242 } else { 243 apiStack.push({ type: 'call', methodName: methodName }); 244 } 245 }; 246 }; 247 248 for (var _i = 0, _total = methods.length; _i < _total; _i++) { 249 assignMethods(methods[_i]); 250 } 251 252 window['__ready__' + vimeo.id] = function (_vimeoPlayer) { 253 254 mediaElement.vimeoPlayer = vimeoPlayer = _vimeoPlayer; 255 256 if (apiStack.length) { 257 for (var _i2 = 0, _total2 = apiStack.length; _i2 < _total2; _i2++) { 258 var stackItem = apiStack[_i2]; 259 260 if (stackItem.type === 'set') { 261 var propName = stackItem.propName, 262 capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1); 263 264 vimeo['set' + capName](stackItem.value); 265 } else if (stackItem.type === 'call') { 266 vimeo[stackItem.methodName](); 267 } 268 } 269 } 270 271 if (mediaElement.originalNode.muted) { 272 vimeoPlayer.setVolume(0); 273 volume = 0; 274 } 275 276 var vimeoIframe = document.getElementById(vimeo.id); 277 var events = void 0; 278 279 events = ['mouseover', 'mouseout']; 280 281 var assignEvents = function assignEvents(e) { 282 var event = mejs.Utils.createEvent(e.type, vimeo); 283 mediaElement.dispatchEvent(event); 284 }; 285 286 for (var _i3 = 0, _total3 = events.length; _i3 < _total3; _i3++) { 287 vimeoIframe.addEventListener(events[_i3], assignEvents, false); 288 } 289 290 vimeoPlayer.on('loaded', function () { 291 vimeoPlayer.getDuration().then(function (loadProgress) { 292 duration = loadProgress; 293 if (duration > 0) { 294 bufferedTime = duration * loadProgress; 295 if (mediaElement.originalNode.autoplay) { 296 paused = false; 297 ended = false; 298 var event = mejs.Utils.createEvent('play', vimeo); 299 mediaElement.dispatchEvent(event); 300 } 301 } 302 }).catch(function (error) { 303 errorHandler(error, vimeo); 304 }); 305 }); 306 vimeoPlayer.on('progress', function () { 307 vimeoPlayer.getDuration().then(function (loadProgress) { 308 duration = loadProgress; 309 310 if (duration > 0) { 311 bufferedTime = duration * loadProgress; 312 if (mediaElement.originalNode.autoplay) { 313 var initEvent = mejs.Utils.createEvent('play', vimeo); 314 mediaElement.dispatchEvent(initEvent); 315 316 var playingEvent = mejs.Utils.createEvent('playing', vimeo); 317 mediaElement.dispatchEvent(playingEvent); 318 } 319 } 320 321 var event = mejs.Utils.createEvent('progress', vimeo); 322 mediaElement.dispatchEvent(event); 323 }).catch(function (error) { 324 return errorHandler(error); 325 }); 326 }); 327 vimeoPlayer.on('timeupdate', function () { 328 vimeoPlayer.getCurrentTime().then(function (seconds) { 329 currentTime = seconds; 330 var event = mejs.Utils.createEvent('timeupdate', vimeo); 331 mediaElement.dispatchEvent(event); 332 }).catch(function (error) { 333 return errorHandler(error); 334 }); 335 }); 336 vimeoPlayer.on('play', function () { 337 paused = false; 338 ended = false; 339 var event = mejs.Utils.createEvent('play', vimeo); 340 mediaElement.dispatchEvent(event); 341 342 var playingEvent = mejs.Utils.createEvent('playing', vimeo); 343 mediaElement.dispatchEvent(playingEvent); 344 }); 345 vimeoPlayer.on('pause', function () { 346 paused = true; 347 ended = false; 348 349 var event = mejs.Utils.createEvent('pause', vimeo); 350 mediaElement.dispatchEvent(event); 351 }); 352 vimeoPlayer.on('ended', function () { 353 paused = false; 354 ended = true; 355 356 var event = mejs.Utils.createEvent('ended', vimeo); 357 mediaElement.dispatchEvent(event); 358 }); 359 360 events = ['rendererready', 'loadedmetadata', 'loadeddata', 'canplay']; 361 362 for (var _i4 = 0, _total4 = events.length; _i4 < _total4; _i4++) { 363 var event = mejs.Utils.createEvent(events[_i4], vimeo); 364 mediaElement.dispatchEvent(event); 365 } 366 }; 367 368 var height = mediaElement.originalNode.height, 369 width = mediaElement.originalNode.width, 370 vimeoContainer = document.createElement('iframe'), 371 standardUrl = 'https://player.vimeo.com/video/' + VimeoApi.getVimeoId(mediaFiles[0].src); 372 373 var queryArgs = ~mediaFiles[0].src.indexOf('?') ? '?' + mediaFiles[0].src.slice(mediaFiles[0].src.indexOf('?') + 1) : ''; 374 var args = []; 375 376 if (mediaElement.originalNode.autoplay && queryArgs.indexOf('autoplay') === -1) { 377 args.push('autoplay=1'); 378 } 379 if (mediaElement.originalNode.loop && queryArgs.indexOf('loop') === -1) { 380 args.push('loop=1'); 381 } 382 383 queryArgs = '' + queryArgs + (queryArgs ? '&' : '?') + args.join('&'); 384 385 vimeoContainer.setAttribute('id', vimeo.id); 386 vimeoContainer.setAttribute('width', width); 387 vimeoContainer.setAttribute('height', height); 388 vimeoContainer.setAttribute('frameBorder', '0'); 389 vimeoContainer.setAttribute('src', '' + standardUrl + queryArgs); 390 vimeoContainer.setAttribute('webkitallowfullscreen', 'true'); 391 vimeoContainer.setAttribute('mozallowfullscreen', 'true'); 392 vimeoContainer.setAttribute('allowfullscreen', 'true'); 393 vimeoContainer.setAttribute('allow', 'autoplay'); 394 395 mediaElement.originalNode.parentNode.insertBefore(vimeoContainer, mediaElement.originalNode); 396 mediaElement.originalNode.style.display = 'none'; 397 398 VimeoApi.load({ 399 iframe: vimeoContainer, 400 id: vimeo.id 401 }); 402 403 vimeo.hide = function () { 404 vimeo.pause(); 405 if (vimeoPlayer) { 406 vimeoContainer.style.display = 'none'; 407 } 408 }; 409 vimeo.setSize = function (width, height) { 410 vimeoContainer.setAttribute('width', width); 411 vimeoContainer.setAttribute('height', height); 412 }; 413 vimeo.show = function () { 414 if (vimeoPlayer) { 415 vimeoContainer.style.display = ''; 416 } 417 }; 418 419 vimeo.destroy = function () {}; 420 421 return vimeo; 422 } 423 }; 424 425 mejs.Utils.typeChecks.push(function (url) { 426 return (/(\/\/player\.vimeo|vimeo\.com)/i.test(url) ? 'video/x-vimeo' : null 427 ); 428 }); 429 430 mejs.Renderers.add(vimeoIframeRenderer); 431 432 },{}]},{},[1]);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 25 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |