PageRenderTime 61ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/jplayer/2.3.8/jquery.jplayer/jquery.jplayer.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 1389 lines | 1126 code | 105 blank | 158 comment | 158 complexity | 0c07eaeffff2739ff5ee4b062412c15c MD5 | raw file
  1. /*
  2. * jPlayer Plugin for jQuery JavaScript Library
  3. * http://www.jplayer.org
  4. *
  5. * Copyright (c) 2009 - 2013 Happyworm Ltd
  6. * Dual licensed under the MIT and GPL licenses.
  7. * - http://www.opensource.org/licenses/mit-license.php
  8. * - http://www.gnu.org/copyleft/gpl.html
  9. *
  10. * Author: Mark J Panaghiston
  11. * Version: 2.3.8
  12. * Date: 30th May 2013
  13. */
  14. /* Code verified using http://www.jshint.com/ */
  15. /*jshint asi:false, bitwise:false, boss:false, browser:true, curly:true, debug:false, eqeqeq:true, eqnull:false, evil:false, forin:false, immed:false, jquery:true, laxbreak:false, newcap:true, noarg:true, noempty:true, nonew:true, onevar:false, passfail:false, plusplus:false, regexp:false, undef:true, sub:false, strict:false, white:false, smarttabs:true */
  16. /*global define:false, ActiveXObject:false, alert:false */
  17. /* Support for Zepto 1.0 compiled with optional data module.
  18. * You will need to manually switch the 2 sets of lines in the code below.
  19. * Search terms: "jQuery Switch" and "Zepto Switch"
  20. */
  21. (function (root, factory) {
  22. if (typeof define === 'function' && define.amd) {
  23. // AMD. Register as an anonymous module.
  24. define(['jquery'], factory); // jQuery Switch
  25. // define(['zepto'], factory); // Zepto Switch
  26. } else {
  27. // Browser globals
  28. factory(root.jQuery); // jQuery Switch
  29. // factory(root.Zepto); // Zepto Switch
  30. }
  31. }(this, function ($, undefined) {
  32. // Adapted from jquery.ui.widget.js (1.8.7): $.widget.bridge - Tweaked $.data(this,XYZ) to $(this).data(XYZ) for Zepto
  33. $.fn.jPlayer = function( options ) {
  34. var name = "jPlayer";
  35. var isMethodCall = typeof options === "string",
  36. args = Array.prototype.slice.call( arguments, 1 ),
  37. returnValue = this;
  38. // allow multiple hashes to be passed on init
  39. options = !isMethodCall && args.length ?
  40. $.extend.apply( null, [ true, options ].concat(args) ) :
  41. options;
  42. // prevent calls to internal methods
  43. if ( isMethodCall && options.charAt( 0 ) === "_" ) {
  44. return returnValue;
  45. }
  46. if ( isMethodCall ) {
  47. this.each(function() {
  48. // var instance = $.data( this, name ),
  49. var instance = $(this).data( name ),
  50. methodValue = instance && $.isFunction( instance[options] ) ?
  51. instance[ options ].apply( instance, args ) :
  52. instance;
  53. if ( methodValue !== instance && methodValue !== undefined ) {
  54. returnValue = methodValue;
  55. return false;
  56. }
  57. });
  58. } else {
  59. this.each(function() {
  60. // var instance = $.data( this, name );
  61. var instance = $(this).data( name );
  62. if ( instance ) {
  63. // instance.option( options || {} )._init(); // Orig jquery.ui.widget.js code: Not recommend for jPlayer. ie., Applying new options to an existing instance (via the jPlayer constructor) and performing the _init(). The _init() is what concerns me. It would leave a lot of event handlers acting on jPlayer instance and the interface.
  64. instance.option( options || {} ); // The new constructor only changes the options. Changing options only has basic support atm.
  65. } else {
  66. // $.data( this, name, new $.jPlayer( options, this ) );
  67. $(this).data( name, new $.jPlayer( options, this ) );
  68. }
  69. });
  70. }
  71. return returnValue;
  72. };
  73. $.jPlayer = function( options, element ) {
  74. // allow instantiation without initializing for simple inheritance
  75. if ( arguments.length ) {
  76. this.element = $(element);
  77. this.options = $.extend(true, {},
  78. this.options,
  79. options
  80. );
  81. var self = this;
  82. this.element.bind( "remove.jPlayer", function() {
  83. self.destroy();
  84. });
  85. this._init();
  86. }
  87. };
  88. // End of: (Adapted from jquery.ui.widget.js (1.8.7))
  89. // Zepto is missing one of the animation methods.
  90. if(typeof $.fn.stop !== 'function') {
  91. $.fn.stop = function() {};
  92. }
  93. // Emulated HTML5 methods and properties
  94. $.jPlayer.emulateMethods = "load play pause";
  95. $.jPlayer.emulateStatus = "src readyState networkState currentTime duration paused ended playbackRate";
  96. $.jPlayer.emulateOptions = "muted volume";
  97. // Reserved event names generated by jPlayer that are not part of the HTML5 Media element spec
  98. $.jPlayer.reservedEvent = "ready flashreset resize repeat error warning";
  99. // Events generated by jPlayer
  100. $.jPlayer.event = {};
  101. $.each(
  102. [
  103. 'ready',
  104. 'flashreset', // Similar to the ready event if the Flash solution is set to display:none and then shown again or if it's reloaded for another reason by the browser. For example, using CSS position:fixed on Firefox for the full screen feature.
  105. 'resize', // Occurs when the size changes through a full/restore screen operation or if the size/sizeFull options are changed.
  106. 'repeat', // Occurs when the repeat status changes. Usually through clicks on the repeat button of the interface.
  107. 'click', // Occurs when the user clicks on one of the following: poster image, html video, flash video.
  108. 'error', // Event error code in event.jPlayer.error.type. See $.jPlayer.error
  109. 'warning', // Event warning code in event.jPlayer.warning.type. See $.jPlayer.warning
  110. // Other events match HTML5 spec.
  111. 'loadstart',
  112. 'progress',
  113. 'suspend',
  114. 'abort',
  115. 'emptied',
  116. 'stalled',
  117. 'play',
  118. 'pause',
  119. 'loadedmetadata',
  120. 'loadeddata',
  121. 'waiting',
  122. 'playing',
  123. 'canplay',
  124. 'canplaythrough',
  125. 'seeking',
  126. 'seeked',
  127. 'timeupdate',
  128. 'ended',
  129. 'ratechange',
  130. 'durationchange',
  131. 'volumechange'
  132. ],
  133. function() {
  134. $.jPlayer.event[ this ] = 'jPlayer_' + this;
  135. }
  136. );
  137. $.jPlayer.htmlEvent = [ // These HTML events are bubbled through to the jPlayer event, without any internal action.
  138. "loadstart",
  139. // "progress", // jPlayer uses internally before bubbling.
  140. // "suspend", // jPlayer uses internally before bubbling.
  141. "abort",
  142. // "error", // jPlayer uses internally before bubbling.
  143. "emptied",
  144. "stalled",
  145. // "play", // jPlayer uses internally before bubbling.
  146. // "pause", // jPlayer uses internally before bubbling.
  147. "loadedmetadata",
  148. "loadeddata",
  149. // "waiting", // jPlayer uses internally before bubbling.
  150. // "playing", // jPlayer uses internally before bubbling.
  151. "canplay",
  152. "canplaythrough",
  153. // "seeking", // jPlayer uses internally before bubbling.
  154. // "seeked", // jPlayer uses internally before bubbling.
  155. // "timeupdate", // jPlayer uses internally before bubbling.
  156. // "ended", // jPlayer uses internally before bubbling.
  157. "ratechange"
  158. // "durationchange" // jPlayer uses internally before bubbling.
  159. // "volumechange" // jPlayer uses internally before bubbling.
  160. ];
  161. $.jPlayer.pause = function() {
  162. $.each($.jPlayer.prototype.instances, function(i, element) {
  163. if(element.data("jPlayer").status.srcSet) { // Check that media is set otherwise would cause error event.
  164. element.jPlayer("pause");
  165. }
  166. });
  167. };
  168. // Default for jPlayer option.timeFormat
  169. $.jPlayer.timeFormat = {
  170. showHour: false,
  171. showMin: true,
  172. showSec: true,
  173. padHour: false,
  174. padMin: true,
  175. padSec: true,
  176. sepHour: ":",
  177. sepMin: ":",
  178. sepSec: ""
  179. };
  180. var ConvertTime = function() {
  181. this.init();
  182. };
  183. ConvertTime.prototype = {
  184. init: function() {
  185. this.options = {
  186. timeFormat: $.jPlayer.timeFormat
  187. };
  188. },
  189. time: function(s) { // function used on jPlayer.prototype._convertTime to enable per instance options.
  190. s = (s && typeof s === 'number') ? s : 0;
  191. var myTime = new Date(s * 1000),
  192. hour = myTime.getUTCHours(),
  193. min = this.options.timeFormat.showHour ? myTime.getUTCMinutes() : myTime.getUTCMinutes() + hour * 60,
  194. sec = this.options.timeFormat.showMin ? myTime.getUTCSeconds() : myTime.getUTCSeconds() + min * 60,
  195. strHour = (this.options.timeFormat.padHour && hour < 10) ? "0" + hour : hour,
  196. strMin = (this.options.timeFormat.padMin && min < 10) ? "0" + min : min,
  197. strSec = (this.options.timeFormat.padSec && sec < 10) ? "0" + sec : sec,
  198. strTime = "";
  199. strTime += this.options.timeFormat.showHour ? strHour + this.options.timeFormat.sepHour : "";
  200. strTime += this.options.timeFormat.showMin ? strMin + this.options.timeFormat.sepMin : "";
  201. strTime += this.options.timeFormat.showSec ? strSec + this.options.timeFormat.sepSec : "";
  202. return strTime;
  203. }
  204. };
  205. var myConvertTime = new ConvertTime();
  206. $.jPlayer.convertTime = function(s) {
  207. return myConvertTime.time(s);
  208. };
  209. // Adapting jQuery 1.4.4 code for jQuery.browser. Required since jQuery 1.3.2 does not detect Chrome as webkit.
  210. $.jPlayer.uaBrowser = function( userAgent ) {
  211. var ua = userAgent.toLowerCase();
  212. // Useragent RegExp
  213. var rwebkit = /(webkit)[ \/]([\w.]+)/;
  214. var ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/;
  215. var rmsie = /(msie) ([\w.]+)/;
  216. var rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;
  217. var match = rwebkit.exec( ua ) ||
  218. ropera.exec( ua ) ||
  219. rmsie.exec( ua ) ||
  220. ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
  221. [];
  222. return { browser: match[1] || "", version: match[2] || "0" };
  223. };
  224. // Platform sniffer for detecting mobile devices
  225. $.jPlayer.uaPlatform = function( userAgent ) {
  226. var ua = userAgent.toLowerCase();
  227. // Useragent RegExp
  228. var rplatform = /(ipad|iphone|ipod|android|blackberry|playbook|windows ce|webos)/;
  229. var rtablet = /(ipad|playbook)/;
  230. var randroid = /(android)/;
  231. var rmobile = /(mobile)/;
  232. var platform = rplatform.exec( ua ) || [];
  233. var tablet = rtablet.exec( ua ) ||
  234. !rmobile.exec( ua ) && randroid.exec( ua ) ||
  235. [];
  236. if(platform[1]) {
  237. platform[1] = platform[1].replace(/\s/g, "_"); // Change whitespace to underscore. Enables dot notation.
  238. }
  239. return { platform: platform[1] || "", tablet: tablet[1] || "" };
  240. };
  241. $.jPlayer.browser = {
  242. };
  243. $.jPlayer.platform = {
  244. };
  245. var browserMatch = $.jPlayer.uaBrowser(navigator.userAgent);
  246. if ( browserMatch.browser ) {
  247. $.jPlayer.browser[ browserMatch.browser ] = true;
  248. $.jPlayer.browser.version = browserMatch.version;
  249. }
  250. var platformMatch = $.jPlayer.uaPlatform(navigator.userAgent);
  251. if ( platformMatch.platform ) {
  252. $.jPlayer.platform[ platformMatch.platform ] = true;
  253. $.jPlayer.platform.mobile = !platformMatch.tablet;
  254. $.jPlayer.platform.tablet = !!platformMatch.tablet;
  255. }
  256. // Internet Explorer (IE) Browser Document Mode Sniffer. Based on code at:
  257. // http://msdn.microsoft.com/en-us/library/cc288325%28v=vs.85%29.aspx#GetMode
  258. $.jPlayer.getDocMode = function() {
  259. var docMode;
  260. if ($.jPlayer.browser.msie) {
  261. if (document.documentMode) { // IE8 or later
  262. docMode = document.documentMode;
  263. } else { // IE 5-7
  264. docMode = 5; // Assume quirks mode unless proven otherwise
  265. if (document.compatMode) {
  266. if (document.compatMode === "CSS1Compat") {
  267. docMode = 7; // standards mode
  268. }
  269. }
  270. }
  271. }
  272. return docMode;
  273. };
  274. $.jPlayer.browser.documentMode = $.jPlayer.getDocMode();
  275. $.jPlayer.nativeFeatures = {
  276. init: function() {
  277. /* Fullscreen function naming influenced by W3C naming.
  278. * No support for: Mozilla Proposal: https://wiki.mozilla.org/Gecko:FullScreenAPI
  279. */
  280. var d = document,
  281. v = d.createElement('video'),
  282. spec = {
  283. // http://www.w3.org/TR/fullscreen/
  284. w3c: [
  285. 'fullscreenEnabled',
  286. 'fullscreenElement',
  287. 'requestFullscreen',
  288. 'exitFullscreen',
  289. 'fullscreenchange',
  290. 'fullscreenerror'
  291. ],
  292. // https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  293. moz: [
  294. 'mozFullScreenEnabled',
  295. 'mozFullScreenElement',
  296. 'mozRequestFullScreen',
  297. 'mozCancelFullScreen',
  298. 'mozfullscreenchange',
  299. 'mozfullscreenerror'
  300. ],
  301. // http://developer.apple.com/library/safari/#documentation/WebKit/Reference/ElementClassRef/Element/Element.html
  302. // http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/DocumentAdditionsReference/DocumentAdditions/DocumentAdditions.html
  303. webkit: [
  304. '',
  305. 'webkitCurrentFullScreenElement',
  306. 'webkitRequestFullScreen',
  307. 'webkitCancelFullScreen',
  308. 'webkitfullscreenchange',
  309. ''
  310. ],
  311. // http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/HTMLVideoElementClassReference/HTMLVideoElement/HTMLVideoElement.html
  312. webkitVideo: [
  313. 'webkitSupportsFullscreen',
  314. 'webkitDisplayingFullscreen',
  315. 'webkitEnterFullscreen',
  316. 'webkitExitFullscreen',
  317. '',
  318. ''
  319. ]
  320. },
  321. specOrder = [
  322. 'w3c',
  323. 'moz',
  324. 'webkit',
  325. 'webkitVideo'
  326. ],
  327. fs, i, il;
  328. this.fullscreen = fs = {
  329. support: {
  330. w3c: !!d[spec.w3c[0]],
  331. moz: !!d[spec.moz[0]],
  332. webkit: typeof d[spec.webkit[3]] === 'function',
  333. webkitVideo: typeof v[spec.webkitVideo[2]] === 'function'
  334. },
  335. used: {}
  336. };
  337. // Store the name of the spec being used and as a handy boolean.
  338. for(i = 0, il = specOrder.length; i < il; i++) {
  339. var n = specOrder[i];
  340. if(fs.support[n]) {
  341. fs.spec = n;
  342. fs.used[n] = true;
  343. break;
  344. }
  345. }
  346. if(fs.spec) {
  347. var s = spec[fs.spec];
  348. fs.api = {
  349. fullscreenEnabled: true,
  350. fullscreenElement: function(elem) {
  351. elem = elem ? elem : d; // Video element required for webkitVideo
  352. return elem[s[1]];
  353. },
  354. requestFullscreen: function(elem) {
  355. return elem[s[2]]();
  356. },
  357. exitFullscreen: function(elem) {
  358. elem = elem ? elem : d; // Video element required for webkitVideo
  359. return elem[s[3]]();
  360. }
  361. };
  362. fs.event = {
  363. fullscreenchange: s[4],
  364. fullscreenerror: s[5]
  365. };
  366. } else {
  367. fs.api = {
  368. fullscreenEnabled: false,
  369. fullscreenElement: function() {
  370. return null;
  371. },
  372. requestFullscreen: function() {},
  373. exitFullscreen: function() {}
  374. };
  375. fs.event = {};
  376. }
  377. }
  378. };
  379. $.jPlayer.nativeFeatures.init();
  380. // The keyboard control system.
  381. // The current jPlayer instance in focus.
  382. $.jPlayer.focus = null;
  383. // The list of element node names to ignore with key controls.
  384. $.jPlayer.keyIgnoreElementNames = "INPUT TEXTAREA";
  385. // The function that deals with key presses.
  386. var keyBindings = function(event) {
  387. var f = $.jPlayer.focus,
  388. ignoreKey;
  389. // A jPlayer instance must be in focus. ie., keyEnabled and the last one played.
  390. if(f) {
  391. // What generated the key press?
  392. $.each( $.jPlayer.keyIgnoreElementNames.split(/\s+/g), function(i, name) {
  393. // The strings should already be uppercase.
  394. if(event.target.nodeName.toUpperCase() === name.toUpperCase()) {
  395. ignoreKey = true;
  396. return false; // exit each.
  397. }
  398. });
  399. if(!ignoreKey) {
  400. // See if the key pressed matches any of the bindings.
  401. $.each(f.options.keyBindings, function(action, binding) {
  402. // The binding could be a null when the default has been disabled. ie., 1st clause in if()
  403. if(binding && event.which === binding.key && $.isFunction(binding.fn)) {
  404. event.preventDefault(); // Key being used by jPlayer, so prevent default operation.
  405. binding.fn(f);
  406. return false; // exit each.
  407. }
  408. });
  409. }
  410. }
  411. };
  412. $.jPlayer.keys = function(en) {
  413. var event = "keydown.jPlayer";
  414. // Remove any binding, just in case enabled more than once.
  415. $(document.documentElement).unbind(event);
  416. if(en) {
  417. $(document.documentElement).bind(event, keyBindings);
  418. }
  419. };
  420. // Enable the global key control handler ready for any jPlayer instance with the keyEnabled option enabled.
  421. $.jPlayer.keys(true);
  422. $.jPlayer.prototype = {
  423. count: 0, // Static Variable: Change it via prototype.
  424. version: { // Static Object
  425. script: "2.3.8",
  426. needFlash: "2.3.5",
  427. flash: "unknown"
  428. },
  429. options: { // Instanced in $.jPlayer() constructor
  430. swfPath: "js", // Path to Jplayer.swf. Can be relative, absolute or server root relative.
  431. solution: "html, flash", // Valid solutions: html, flash. Order defines priority. 1st is highest,
  432. supplied: "mp3", // Defines which formats jPlayer will try and support and the priority by the order. 1st is highest,
  433. preload: 'metadata', // HTML5 Spec values: none, metadata, auto.
  434. volume: 0.8, // The volume. Number 0 to 1.
  435. muted: false,
  436. wmode: "opaque", // Valid wmode: window, transparent, opaque, direct, gpu.
  437. backgroundColor: "#000000", // To define the jPlayer div and Flash background color.
  438. cssSelectorAncestor: "#jp_container_1",
  439. cssSelector: { // * denotes properties that should only be required when video media type required. _cssSelector() would require changes to enable splitting these into Audio and Video defaults.
  440. videoPlay: ".jp-video-play", // *
  441. play: ".jp-play",
  442. pause: ".jp-pause",
  443. stop: ".jp-stop",
  444. seekBar: ".jp-seek-bar",
  445. playBar: ".jp-play-bar",
  446. mute: ".jp-mute",
  447. unmute: ".jp-unmute",
  448. volumeBar: ".jp-volume-bar",
  449. volumeBarValue: ".jp-volume-bar-value",
  450. volumeMax: ".jp-volume-max",
  451. currentTime: ".jp-current-time",
  452. duration: ".jp-duration",
  453. fullScreen: ".jp-full-screen", // *
  454. restoreScreen: ".jp-restore-screen", // *
  455. repeat: ".jp-repeat",
  456. repeatOff: ".jp-repeat-off",
  457. gui: ".jp-gui", // The interface used with autohide feature.
  458. noSolution: ".jp-no-solution" // For error feedback when jPlayer cannot find a solution.
  459. },
  460. smoothPlayBar: false, // Smooths the play bar transitions, which affects clicks and short media with big changes per second.
  461. fullScreen: false, // Native Full Screen
  462. fullWindow: false,
  463. autohide: {
  464. restored: false, // Controls the interface autohide feature.
  465. full: true, // Controls the interface autohide feature.
  466. fadeIn: 200, // Milliseconds. The period of the fadeIn anim.
  467. fadeOut: 600, // Milliseconds. The period of the fadeOut anim.
  468. hold: 1000 // Milliseconds. The period of the pause before autohide beings.
  469. },
  470. loop: false,
  471. repeat: function(event) { // The default jPlayer repeat event handler
  472. if(event.jPlayer.options.loop) {
  473. $(this).unbind(".jPlayerRepeat").bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function() {
  474. $(this).jPlayer("play");
  475. });
  476. } else {
  477. $(this).unbind(".jPlayerRepeat");
  478. }
  479. },
  480. nativeVideoControls: {
  481. // Works well on standard browsers.
  482. // Phone and tablet browsers can have problems with the controls disappearing.
  483. },
  484. noFullWindow: {
  485. msie: /msie [0-6]\./,
  486. ipad: /ipad.*?os [0-4]\./,
  487. iphone: /iphone/,
  488. ipod: /ipod/,
  489. android_pad: /android [0-3]\.(?!.*?mobile)/,
  490. android_phone: /android.*?mobile/,
  491. blackberry: /blackberry/,
  492. windows_ce: /windows ce/,
  493. iemobile: /iemobile/,
  494. webos: /webos/
  495. },
  496. noVolume: {
  497. ipad: /ipad/,
  498. iphone: /iphone/,
  499. ipod: /ipod/,
  500. android_pad: /android(?!.*?mobile)/,
  501. android_phone: /android.*?mobile/,
  502. blackberry: /blackberry/,
  503. windows_ce: /windows ce/,
  504. iemobile: /iemobile/,
  505. webos: /webos/,
  506. playbook: /playbook/
  507. },
  508. timeFormat: {
  509. // Specific time format for this instance. The supported options are defined in $.jPlayer.timeFormat
  510. // For the undefined options we use the default from $.jPlayer.timeFormat
  511. },
  512. keyEnabled: false, // Enables keyboard controls.
  513. audioFullScreen: false, // Enables keyboard controls to enter full screen with audio media.
  514. keyBindings: { // The key control object, defining the key codes and the functions to execute.
  515. // The parameter, f = $.jPlayer.focus, will be checked truethy before attempting to call any of these functions.
  516. // Properties may be added to this object, in key/fn pairs, to enable other key controls. EG, for the playlist add-on.
  517. play: {
  518. key: 32, // space
  519. fn: function(f) {
  520. if(f.status.paused) {
  521. f.play();
  522. } else {
  523. f.pause();
  524. }
  525. }
  526. },
  527. fullScreen: {
  528. key: 13, // enter
  529. fn: function(f) {
  530. if(f.status.video || f.options.audioFullScreen) {
  531. f._setOption("fullScreen", !f.options.fullScreen);
  532. }
  533. }
  534. },
  535. muted: {
  536. key: 8, // backspace
  537. fn: function(f) {
  538. f._muted(!f.options.muted);
  539. }
  540. },
  541. volumeUp: {
  542. key: 38, // UP
  543. fn: function(f) {
  544. f.volume(f.options.volume + 0.1);
  545. }
  546. },
  547. volumeDown: {
  548. key: 40, // DOWN
  549. fn: function(f) {
  550. f.volume(f.options.volume - 0.1);
  551. }
  552. }
  553. },
  554. verticalVolume: false, // Calculate volume from the bottom of the volume bar. Default is from the left. Also volume affects either width or height.
  555. // globalVolume: false, // Not implemented: Set to make volume changes affect all jPlayer instances
  556. // globalMute: false, // Not implemented: Set to make mute changes affect all jPlayer instances
  557. idPrefix: "jp", // Prefix for the ids of html elements created by jPlayer. For flash, this must not include characters: . - + * / \
  558. noConflict: "jQuery",
  559. emulateHtml: false, // Emulates the HTML5 Media element on the jPlayer element.
  560. errorAlerts: false,
  561. warningAlerts: false
  562. },
  563. optionsAudio: {
  564. size: {
  565. width: "0px",
  566. height: "0px",
  567. cssClass: ""
  568. },
  569. sizeFull: {
  570. width: "0px",
  571. height: "0px",
  572. cssClass: ""
  573. }
  574. },
  575. optionsVideo: {
  576. size: {
  577. width: "480px",
  578. height: "270px",
  579. cssClass: "jp-video-270p"
  580. },
  581. sizeFull: {
  582. width: "100%",
  583. height: "100%",
  584. cssClass: "jp-video-full"
  585. }
  586. },
  587. instances: {}, // Static Object
  588. status: { // Instanced in _init()
  589. src: "",
  590. media: {},
  591. paused: true,
  592. format: {},
  593. formatType: "",
  594. waitForPlay: true, // Same as waitForLoad except in case where preloading.
  595. waitForLoad: true,
  596. srcSet: false,
  597. video: false, // True if playing a video
  598. seekPercent: 0,
  599. currentPercentRelative: 0,
  600. currentPercentAbsolute: 0,
  601. currentTime: 0,
  602. duration: 0,
  603. videoWidth: 0, // Intrinsic width of the video in pixels.
  604. videoHeight: 0, // Intrinsic height of the video in pixels.
  605. readyState: 0,
  606. networkState: 0,
  607. playbackRate: 1,
  608. ended: 0
  609. /* Persistant status properties created dynamically at _init():
  610. width
  611. height
  612. cssClass
  613. nativeVideoControls
  614. noFullWindow
  615. noVolume
  616. */
  617. },
  618. internal: { // Instanced in _init()
  619. ready: false
  620. // instance: undefined
  621. // domNode: undefined
  622. // htmlDlyCmdId: undefined
  623. // autohideId: undefined
  624. // cmdsIgnored
  625. },
  626. solution: { // Static Object: Defines the solutions built in jPlayer.
  627. html: true,
  628. flash: true
  629. },
  630. // 'MPEG-4 support' : canPlayType('video/mp4; codecs="mp4v.20.8"')
  631. format: { // Static Object
  632. mp3: {
  633. codec: 'audio/mpeg; codecs="mp3"',
  634. flashCanPlay: true,
  635. media: 'audio'
  636. },
  637. m4a: { // AAC / MP4
  638. codec: 'audio/mp4; codecs="mp4a.40.2"',
  639. flashCanPlay: true,
  640. media: 'audio'
  641. },
  642. oga: { // OGG
  643. codec: 'audio/ogg; codecs="vorbis"',
  644. flashCanPlay: false,
  645. media: 'audio'
  646. },
  647. wav: { // PCM
  648. codec: 'audio/wav; codecs="1"',
  649. flashCanPlay: false,
  650. media: 'audio'
  651. },
  652. webma: { // WEBM
  653. codec: 'audio/webm; codecs="vorbis"',
  654. flashCanPlay: false,
  655. media: 'audio'
  656. },
  657. fla: { // FLV / F4A
  658. codec: 'audio/x-flv',
  659. flashCanPlay: true,
  660. media: 'audio'
  661. },
  662. rtmpa: { // RTMP AUDIO
  663. codec: 'audio/rtmp; codecs="rtmp"',
  664. flashCanPlay: true,
  665. media: 'audio'
  666. },
  667. m4v: { // H.264 / MP4
  668. codec: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
  669. flashCanPlay: true,
  670. media: 'video'
  671. },
  672. ogv: { // OGG
  673. codec: 'video/ogg; codecs="theora, vorbis"',
  674. flashCanPlay: false,
  675. media: 'video'
  676. },
  677. webmv: { // WEBM
  678. codec: 'video/webm; codecs="vorbis, vp8"',
  679. flashCanPlay: false,
  680. media: 'video'
  681. },
  682. flv: { // FLV / F4V
  683. codec: 'video/x-flv',
  684. flashCanPlay: true,
  685. media: 'video'
  686. },
  687. rtmpv: { // RTMP VIDEO
  688. codec: 'video/rtmp; codecs="rtmp"',
  689. flashCanPlay: true,
  690. media: 'video'
  691. }
  692. },
  693. _init: function() {
  694. var self = this;
  695. this.element.empty();
  696. this.status = $.extend({}, this.status); // Copy static to unique instance.
  697. this.internal = $.extend({}, this.internal); // Copy static to unique instance.
  698. // Initialize the time format
  699. this.options.timeFormat = $.extend({}, $.jPlayer.timeFormat, this.options.timeFormat);
  700. // On iOS, assume commands will be ignored before user initiates them.
  701. this.internal.cmdsIgnored = $.jPlayer.platform.ipad || $.jPlayer.platform.iphone || $.jPlayer.platform.ipod;
  702. this.internal.domNode = this.element.get(0);
  703. // Add key bindings focus to 1st jPlayer instanced with key control enabled.
  704. if(this.options.keyEnabled && !$.jPlayer.focus) {
  705. $.jPlayer.focus = this;
  706. }
  707. this.formats = []; // Array based on supplied string option. Order defines priority.
  708. this.solutions = []; // Array based on solution string option. Order defines priority.
  709. this.require = {}; // Which media types are required: video, audio.
  710. this.htmlElement = {}; // DOM elements created by jPlayer
  711. this.html = {}; // In _init()'s this.desired code and setmedia(): Accessed via this[solution], where solution from this.solutions array.
  712. this.html.audio = {};
  713. this.html.video = {};
  714. this.flash = {}; // In _init()'s this.desired code and setmedia(): Accessed via this[solution], where solution from this.solutions array.
  715. this.css = {};
  716. this.css.cs = {}; // Holds the css selector strings
  717. this.css.jq = {}; // Holds jQuery selectors. ie., $(css.cs.method)
  718. this.ancestorJq = []; // Holds jQuery selector of cssSelectorAncestor. Init would use $() instead of [], but it is only 1.4+
  719. this.options.volume = this._limitValue(this.options.volume, 0, 1); // Limit volume value's bounds.
  720. // Create the formats array, with prority based on the order of the supplied formats string
  721. $.each(this.options.supplied.toLowerCase().split(","), function(index1, value1) {
  722. var format = value1.replace(/^\s+|\s+$/g, ""); //trim
  723. if(self.format[format]) { // Check format is valid.
  724. var dupFound = false;
  725. $.each(self.formats, function(index2, value2) { // Check for duplicates
  726. if(format === value2) {
  727. dupFound = true;
  728. return false;
  729. }
  730. });
  731. if(!dupFound) {
  732. self.formats.push(format);
  733. }
  734. }
  735. });
  736. // Create the solutions array, with prority based on the order of the solution string
  737. $.each(this.options.solution.toLowerCase().split(","), function(index1, value1) {
  738. var solution = value1.replace(/^\s+|\s+$/g, ""); //trim
  739. if(self.solution[solution]) { // Check solution is valid.
  740. var dupFound = false;
  741. $.each(self.solutions, function(index2, value2) { // Check for duplicates
  742. if(solution === value2) {
  743. dupFound = true;
  744. return false;
  745. }
  746. });
  747. if(!dupFound) {
  748. self.solutions.push(solution);
  749. }
  750. }
  751. });
  752. this.internal.instance = "jp_" + this.count;
  753. this.instances[this.internal.instance] = this.element;
  754. // Check the jPlayer div has an id and create one if required. Important for Flash to know the unique id for comms.
  755. if(!this.element.attr("id")) {
  756. this.element.attr("id", this.options.idPrefix + "_jplayer_" + this.count);
  757. }
  758. this.internal.self = $.extend({}, {
  759. id: this.element.attr("id"),
  760. jq: this.element
  761. });
  762. this.internal.audio = $.extend({}, {
  763. id: this.options.idPrefix + "_audio_" + this.count,
  764. jq: undefined
  765. });
  766. this.internal.video = $.extend({}, {
  767. id: this.options.idPrefix + "_video_" + this.count,
  768. jq: undefined
  769. });
  770. this.internal.flash = $.extend({}, {
  771. id: this.options.idPrefix + "_flash_" + this.count,
  772. jq: undefined,
  773. swf: this.options.swfPath + (this.options.swfPath.toLowerCase().slice(-4) !== ".swf" ? (this.options.swfPath && this.options.swfPath.slice(-1) !== "/" ? "/" : "") + "Jplayer.swf" : "")
  774. });
  775. this.internal.poster = $.extend({}, {
  776. id: this.options.idPrefix + "_poster_" + this.count,
  777. jq: undefined
  778. });
  779. // Register listeners defined in the constructor
  780. $.each($.jPlayer.event, function(eventName,eventType) {
  781. if(self.options[eventName] !== undefined) {
  782. self.element.bind(eventType + ".jPlayer", self.options[eventName]); // With .jPlayer namespace.
  783. self.options[eventName] = undefined; // Destroy the handler pointer copy on the options. Reason, events can be added/removed in other ways so this could be obsolete and misleading.
  784. }
  785. });
  786. // Determine if we require solutions for audio, video or both media types.
  787. this.require.audio = false;
  788. this.require.video = false;
  789. $.each(this.formats, function(priority, format) {
  790. self.require[self.format[format].media] = true;
  791. });
  792. // Now required types are known, finish the options default settings.
  793. if(this.require.video) {
  794. this.options = $.extend(true, {},
  795. this.optionsVideo,
  796. this.options
  797. );
  798. } else {
  799. this.options = $.extend(true, {},
  800. this.optionsAudio,
  801. this.options
  802. );
  803. }
  804. this._setSize(); // update status and jPlayer element size
  805. // Determine the status for Blocklisted options.
  806. this.status.nativeVideoControls = this._uaBlocklist(this.options.nativeVideoControls);
  807. this.status.noFullWindow = this._uaBlocklist(this.options.noFullWindow);
  808. this.status.noVolume = this._uaBlocklist(this.options.noVolume);
  809. // Create event handlers if native fullscreen is supported
  810. if($.jPlayer.nativeFeatures.fullscreen.api.fullscreenEnabled) {
  811. this._fullscreenAddEventListeners();
  812. }
  813. // The native controls are only for video and are disabled when audio is also used.
  814. this._restrictNativeVideoControls();
  815. // Create the poster image.
  816. this.htmlElement.poster = document.createElement('img');
  817. this.htmlElement.poster.id = this.internal.poster.id;
  818. this.htmlElement.poster.onload = function() { // Note that this did not work on Firefox 3.6: poster.addEventListener("onload", function() {}, false); Did not investigate x-browser.
  819. if(!self.status.video || self.status.waitForPlay) {
  820. self.internal.poster.jq.show();
  821. }
  822. };
  823. this.element.append(this.htmlElement.poster);
  824. this.internal.poster.jq = $("#" + this.internal.poster.id);
  825. this.internal.poster.jq.css({'width': this.status.width, 'height': this.status.height});
  826. this.internal.poster.jq.hide();
  827. this.internal.poster.jq.bind("click.jPlayer", function() {
  828. self._trigger($.jPlayer.event.click);
  829. });
  830. // Generate the required media elements
  831. this.html.audio.available = false;
  832. if(this.require.audio) { // If a supplied format is audio
  833. this.htmlElement.audio = document.createElement('audio');
  834. this.htmlElement.audio.id = this.internal.audio.id;
  835. this.html.audio.available = !!this.htmlElement.audio.canPlayType && this._testCanPlayType(this.htmlElement.audio); // Test is for IE9 on Win Server 2008.
  836. }
  837. this.html.video.available = false;
  838. if(this.require.video) { // If a supplied format is video
  839. this.htmlElement.video = document.createElement('video');
  840. this.htmlElement.video.id = this.internal.video.id;
  841. this.html.video.available = !!this.htmlElement.video.canPlayType && this._testCanPlayType(this.htmlElement.video); // Test is for IE9 on Win Server 2008.
  842. }
  843. this.flash.available = this._checkForFlash(10.1);
  844. this.html.canPlay = {};
  845. this.flash.canPlay = {};
  846. $.each(this.formats, function(priority, format) {
  847. self.html.canPlay[format] = self.html[self.format[format].media].available && "" !== self.htmlElement[self.format[format].media].canPlayType(self.format[format].codec);
  848. self.flash.canPlay[format] = self.format[format].flashCanPlay && self.flash.available;
  849. });
  850. this.html.desired = false;
  851. this.flash.desired = false;
  852. $.each(this.solutions, function(solutionPriority, solution) {
  853. if(solutionPriority === 0) {
  854. self[solution].desired = true;
  855. } else {
  856. var audioCanPlay = false;
  857. var videoCanPlay = false;
  858. $.each(self.formats, function(formatPriority, format) {
  859. if(self[self.solutions[0]].canPlay[format]) { // The other solution can play
  860. if(self.format[format].media === 'video') {
  861. videoCanPlay = true;
  862. } else {
  863. audioCanPlay = true;
  864. }
  865. }
  866. });
  867. self[solution].desired = (self.require.audio && !audioCanPlay) || (self.require.video && !videoCanPlay);
  868. }
  869. });
  870. // This is what jPlayer will support, based on solution and supplied.
  871. this.html.support = {};
  872. this.flash.support = {};
  873. $.each(this.formats, function(priority, format) {
  874. self.html.support[format] = self.html.canPlay[format] && self.html.desired;
  875. self.flash.support[format] = self.flash.canPlay[format] && self.flash.desired;
  876. });
  877. // If jPlayer is supporting any format in a solution, then the solution is used.
  878. this.html.used = false;
  879. this.flash.used = false;
  880. $.each(this.solutions, function(solutionPriority, solution) {
  881. $.each(self.formats, function(formatPriority, format) {
  882. if(self[solution].support[format]) {
  883. self[solution].used = true;
  884. return false;
  885. }
  886. });
  887. });
  888. // Init solution active state and the event gates to false.
  889. this._resetActive();
  890. this._resetGate();
  891. // Set up the css selectors for the control and feedback entities.
  892. this._cssSelectorAncestor(this.options.cssSelectorAncestor);
  893. // If neither html nor flash are being used by this browser, then media playback is not possible. Trigger an error event.
  894. if(!(this.html.used || this.flash.used)) {
  895. this._error( {
  896. type: $.jPlayer.error.NO_SOLUTION,
  897. context: "{solution:'" + this.options.solution + "', supplied:'" + this.options.supplied + "'}",
  898. message: $.jPlayer.errorMsg.NO_SOLUTION,
  899. hint: $.jPlayer.errorHint.NO_SOLUTION
  900. });
  901. if(this.css.jq.noSolution.length) {
  902. this.css.jq.noSolution.show();
  903. }
  904. } else {
  905. if(this.css.jq.noSolution.length) {
  906. this.css.jq.noSolution.hide();
  907. }
  908. }
  909. // Add the flash solution if it is being used.
  910. if(this.flash.used) {
  911. var htmlObj,
  912. flashVars = 'jQuery=' + encodeURI(this.options.noConflict) + '&id=' + encodeURI(this.internal.self.id) + '&vol=' + this.options.volume + '&muted=' + this.options.muted;
  913. // Code influenced by SWFObject 2.2: http://code.google.com/p/swfobject/
  914. // Non IE browsers have an initial Flash size of 1 by 1 otherwise the wmode affected the Flash ready event.
  915. if($.jPlayer.browser.msie && (Number($.jPlayer.browser.version) < 9 || $.jPlayer.browser.documentMode < 9)) {
  916. var objStr = '<object id="' + this.internal.flash.id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="0" height="0" tabindex="-1"></object>';
  917. var paramStr = [
  918. '<param name="movie" value="' + this.internal.flash.swf + '" />',
  919. '<param name="FlashVars" value="' + flashVars + '" />',
  920. '<param name="allowScriptAccess" value="always" />',
  921. '<param name="bgcolor" value="' + this.options.backgroundColor + '" />',
  922. '<param name="wmode" value="' + this.options.wmode + '" />'
  923. ];
  924. htmlObj = document.createElement(objStr);
  925. for(var i=0; i < paramStr.length; i++) {
  926. htmlObj.appendChild(document.createElement(paramStr[i]));
  927. }
  928. } else {
  929. var createParam = function(el, n, v) {
  930. var p = document.createElement("param");
  931. p.setAttribute("name", n);
  932. p.setAttribute("value", v);
  933. el.appendChild(p);
  934. };
  935. htmlObj = document.createElement("object");
  936. htmlObj.setAttribute("id", this.internal.flash.id);
  937. htmlObj.setAttribute("name", this.internal.flash.id);
  938. htmlObj.setAttribute("data", this.internal.flash.swf);
  939. htmlObj.setAttribute("type", "application/x-shockwave-flash");
  940. htmlObj.setAttribute("width", "1"); // Non-zero
  941. htmlObj.setAttribute("height", "1"); // Non-zero
  942. htmlObj.setAttribute("tabindex", "-1");
  943. createParam(htmlObj, "flashvars", flashVars);
  944. createParam(htmlObj, "allowscriptaccess", "always");
  945. createParam(htmlObj, "bgcolor", this.options.backgroundColor);
  946. createParam(htmlObj, "wmode", this.options.wmode);
  947. }
  948. this.element.append(htmlObj);
  949. this.internal.flash.jq = $(htmlObj);
  950. }
  951. // Add the HTML solution if being used.
  952. if(this.html.used) {
  953. // The HTML Audio handlers
  954. if(this.html.audio.available) {
  955. this._addHtmlEventListeners(this.htmlElement.audio, this.html.audio);
  956. this.element.append(this.htmlElement.audio);
  957. this.internal.audio.jq = $("#" + this.internal.audio.id);
  958. }
  959. // The HTML Video handlers
  960. if(this.html.video.available) {
  961. this._addHtmlEventListeners(this.htmlElement.video, this.html.video);
  962. this.element.append(this.htmlElement.video);
  963. this.internal.video.jq = $("#" + this.internal.video.id);
  964. if(this.status.nativeVideoControls) {
  965. this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
  966. } else {
  967. this.internal.video.jq.css({'width':'0px', 'height':'0px'}); // Using size 0x0 since a .hide() causes issues in iOS
  968. }
  969. this.internal.video.jq.bind("click.jPlayer", function() {
  970. self._trigger($.jPlayer.event.click);
  971. });
  972. }
  973. }
  974. // Create the bridge that emulates the HTML Media element on the jPlayer DIV
  975. if( this.options.emulateHtml ) {
  976. this._emulateHtmlBridge();
  977. }
  978. if(this.html.used && !this.flash.used) { // If only HTML, then emulate flash ready() call after 100ms.
  979. setTimeout( function() {
  980. self.internal.ready = true;
  981. self.version.flash = "n/a";
  982. self._trigger($.jPlayer.event.repeat); // Trigger the repeat event so its handler can initialize itself with the loop option.
  983. self._trigger($.jPlayer.event.ready);
  984. }, 100);
  985. }
  986. // Initialize the interface components with the options.
  987. this._updateNativeVideoControls();
  988. // The other controls are now setup in _cssSelectorAncestor()
  989. if(this.css.jq.videoPlay.length) {
  990. this.css.jq.videoPlay.hide();
  991. }
  992. $.jPlayer.prototype.count++; // Change static variable via prototype.
  993. },
  994. destroy: function() {
  995. // MJP: The background change remains. Would need to store the original to restore it correctly.
  996. // MJP: The jPlayer element's size change remains.
  997. // Clear the media to reset the GUI and stop any downloads. Streams on some browsers had persited. (Chrome)
  998. this.clearMedia();
  999. // Remove the size/sizeFull cssClass from the cssSelectorAncestor
  1000. this._removeUiClass();
  1001. // Remove the times from the GUI
  1002. if(this.css.jq.currentTime.length) {
  1003. this.css.jq.currentTime.text("");
  1004. }
  1005. if(this.css.jq.duration.length) {
  1006. this.css.jq.duration.text("");
  1007. }
  1008. // Remove any bindings from the interface controls.
  1009. $.each(this.css.jq, function(fn, jq) {
  1010. // Check selector is valid before trying to execute method.
  1011. if(jq.length) {
  1012. jq.unbind(".jPlayer");
  1013. }
  1014. });
  1015. // Remove the click handlers for $.jPlayer.event.click
  1016. this.internal.poster.jq.unbind(".jPlayer");
  1017. if(this.internal.video.jq) {
  1018. this.internal.video.jq.unbind(".jPlayer");
  1019. }
  1020. // Remove the fullscreen event handlers
  1021. this._fullscreenRemoveEventListeners();
  1022. // Remove key bindings
  1023. if(this === $.jPlayer.focus) {
  1024. $.jPlayer.focus = null;
  1025. }
  1026. // Destroy the HTML bridge.
  1027. if(this.options.emulateHtml) {
  1028. this._destroyHtmlBridge();
  1029. }
  1030. this.element.removeData("jPlayer"); // Remove jPlayer data
  1031. this.element.unbind(".jPlayer"); // Remove all event handlers created by the jPlayer constructor
  1032. this.element.empty(); // Remove the inserted child elements
  1033. delete this.instances[this.internal.instance]; // Clear the instance on the static instance object
  1034. },
  1035. enable: function() { // Plan to implement
  1036. // options.disabled = false
  1037. },
  1038. disable: function () { // Plan to implement
  1039. // options.disabled = true
  1040. },
  1041. _testCanPlayType: function(elem) {
  1042. // IE9 on Win Server 2008 did not implement canPlayType(), but it has the property.
  1043. try {
  1044. elem.canPlayType(this.format.mp3.codec); // The type is irrelevant.
  1045. return true;
  1046. } catch(err) {
  1047. return false;
  1048. }
  1049. },
  1050. _uaBlocklist: function(list) {
  1051. // list : object with properties that are all regular expressions. Property names are irrelevant.
  1052. // Returns true if the user agent is matched in list.
  1053. var ua = navigator.userAgent.toLowerCase(),
  1054. block = false;
  1055. $.each(list, function(p, re) {
  1056. if(re && re.test(ua)) {
  1057. block = true;
  1058. return false; // exit $.each.
  1059. }
  1060. });
  1061. return block;
  1062. },
  1063. _restrictNativeVideoControls: function() {
  1064. // Fallback to noFullWindow when nativeVideoControls is true and audio media is being used. Affects when both media types are used.
  1065. if(this.require.audio) {
  1066. if(this.status.nativeVideoControls) {
  1067. this.status.nativeVideoControls = false;
  1068. this.status.noFullWindow = true;
  1069. }
  1070. }
  1071. },
  1072. _updateNativeVideoControls: function() {
  1073. if(this.html.video.available && this.html.used) {
  1074. // Turn the HTML Video controls on/off
  1075. this.htmlElement.video.controls = this.status.nativeVideoControls;
  1076. // Show/hide the jPlayer GUI.
  1077. this._updateAutohide();
  1078. // For when option changed. The poster image is not updated, as it is dealt with in setMedia(). Acceptable degradation since seriously doubt these options will change on the fly. Can again review later.
  1079. if(this.status.nativeVideoControls && this.require.video) {
  1080. this.internal.poster.jq.hide();
  1081. this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
  1082. } else if(this.status.waitForPlay && this.status.video) {
  1083. this.internal.poster.jq.show();
  1084. this.internal.video.jq.css({'width': '0px', 'height': '0px'});
  1085. }
  1086. }
  1087. },
  1088. _addHtmlEventListeners: function(mediaElement, entity) {
  1089. var self = this;
  1090. mediaElement.preload = this.options.preload;
  1091. mediaElement.muted = this.options.muted;
  1092. mediaElement.volume = this.options.volume;
  1093. // Create the event listeners
  1094. // Only want the active entity to affect jPlayer and bubble events.
  1095. // Using entity.gate so that object is referenced and gate property always current
  1096. mediaElement.addEventListener("progress", function() {
  1097. if(entity.gate) {
  1098. if(self.internal.cmdsIgnored && this.readyState > 0) { // Detect iOS executed the command
  1099. self.internal.cmdsIgnored = false;
  1100. }
  1101. self._getHtmlStatus(mediaElement);
  1102. self._updateInterface();
  1103. self._trigger($.jPlayer.event.progress);
  1104. }
  1105. }, false);
  1106. mediaElement.addEventListener("timeupdate", function() {
  1107. if(entity.gate) {
  1108. self._getHtmlStatus(mediaElement);
  1109. self._updateInterface();
  1110. self._trigger($.jPlayer.event.timeupdate);
  1111. }
  1112. }, false);
  1113. mediaElement.addEventListener("durationchange", function() {
  1114. if(entity.gate) {
  1115. self._getHtmlStatus(mediaElement);
  1116. self._updateInterface();
  1117. self._trigger($.jPlayer.event.durationchange);
  1118. }
  1119. }, false);
  1120. mediaElement.addEventListener("play", function() {
  1121. if(entity.gate) {
  1122. self._updateButtons(true);
  1123. self._html_checkWaitForPlay(); // So the native controls update this variable and puts the hidden interface in the correct state. Affects toggling native controls.
  1124. self._trigger($.jPlayer.event.play);
  1125. }
  1126. }, false);
  1127. mediaElement.addEventListener("playing", function() {
  1128. if(entity.gate) {
  1129. self._updateButtons(true);
  1130. self._seeked();
  1131. self._trigger($.jPlayer.event.playing);
  1132. }
  1133. }, false);
  1134. mediaElement.addEventListener("pause", function() {
  1135. if(entity.gate) {
  1136. self._updateButtons(false);
  1137. self._trigger($.jPlayer.event.pause);
  1138. }
  1139. }, false);
  1140. mediaElement.addEventListener("waiting", function() {
  1141. if(entity.gate) {
  1142. self._seeking();
  1143. self._trigger($.jPlayer.event.waiting);
  1144. }
  1145. }, false);
  1146. mediaElement.addEventListener("seeking", function() {
  1147. if(entity.gate) {
  1148. self._seeking();
  1149. self._trigger($.jPlayer.event.seeking);
  1150. }
  1151. }, false);
  1152. mediaElement.addEventListener("seeked", function() {
  1153. if(entity.gate) {
  1154. self._seeked();
  1155. self._trigger($.jPlayer.event.seeked);
  1156. }
  1157. }, false);
  1158. mediaElement.addEventListener("volumechange", function() {
  1159. if(entity.gate) {
  1160. // Read the values back from the element as the Blackberry PlayBook shares the volume with the physical buttons master volume control.
  1161. // However, when tested 6th July 2011, those buttons do not generate an event. The physical play/pause button does though.
  1162. self.options.volume = mediaElement.volume;
  1163. self.options.muted = mediaElement.muted;
  1164. self._updateMute();
  1165. self._updateVolume();
  1166. self._trigger($.jPlayer.event.volumechange);
  1167. }
  1168. }, false);
  1169. mediaElement.addEventListener("suspend", function() { // Seems to be the only way of capturing that the iOS4 browser did not actually play the media from the page code. ie., It needs a user gesture.
  1170. if(entity.gate) {
  1171. self._seeked();
  1172. self._trigger($.jPlayer.event.suspend);
  1173. }
  1174. }, false);
  1175. mediaElement.addEventListener("ended", function() {
  1176. if(entity.gate) {
  1177. // Order of the next few commands are important. Change the time and then pause.
  1178. // Solves a bug in Firefox, where issuing pause 1st causes the media to play from the start. ie., The pause is ignored.
  1179. if(!$.jPlayer.browser.webkit) { // Chrome crashes if you do this in conjunction with a setMedia command in an ended event handler. ie., The playlist demo.
  1180. self.htmlElement.media.currentTime = 0; // Safari does not care about this command. ie., It works with or without this line. (Both Safari and Chrome are Webkit.)
  1181. }
  1182. self.htmlElement.media.pause(); // Pause otherwise a click on the progress bar will play from that point, when it shouldn't, since it stopped playback.
  1183. self._updateButtons(false);
  1184. self._getHtmlStatus(mediaElement, true); // With override true. Otherwise Chrome leaves progress at full.
  1185. self._updateInterface();
  1186. self._trigger($.jPlayer.event.ended);
  1187. }
  1188. }, false);
  1189. mediaElement.addEventListener("error", function() {
  1190. if(entity.gate) {
  1191. self._updateButtons(false);
  1192. self._seeked();
  1193. if(self.status.srcSet) { // Deals with case of clearMedia() causing an error event.
  1194. clearTimeout(self.internal.htmlDlyCmdId); // Clears any delayed commands used in the HTML solution.
  1195. self.status.waitForLoad = true; // Allows the load operation to try again.
  1196. self.status.waitForPlay = true; // Reset since a play was captured.
  1197. if(self.status.video && !self.status.nativeVideoControls) {
  1198. self.internal.video.jq.css({'width':'0px', 'height':'0px'});
  1199. }
  1200. if(self._validString(self.status.media.poster) && !self.status.nativeVideoControls) {
  1201. self.internal.poster.jq.show();
  1202. }
  1203. if(self.css.jq.videoPlay.length) {
  1204. self.css.jq.videoPlay.show();
  1205. }
  1206. self._error( {
  1207. type: $.jPlayer.error.URL,
  1208. context: self.status.src, // this.src shows absolute urls. Want context to show the url given.
  1209. message: $.jPlayer.errorMsg.URL,
  1210. hint: $.jPlayer.errorHint.URL
  1211. });
  1212. }
  1213. }
  1214. }, false);
  1215. // Create all the other event listeners that bubble up to a jPlayer event from html, without being used by jPlayer.
  1216. $.each($.jPlayer.htmlEvent, function(i, eventType) {
  1217. mediaElement.addEventListener(this, function() {
  1218. if(entity.gate) {
  1219. self._trigger($.jPlayer.event[eventType]);
  1220. }
  1221. }, false);
  1222. });
  1223. },
  1224. _getHtmlStatus: function(media, override) {
  1225. var ct = 0, cpa = 0, sp = 0, cpr = 0;
  1226. // Fixes the duration bug in iOS, where the durationchange event occurs when media.duration is not always correct.
  1227. // Fixes the initial duration bug in BB OS7, where the media.duration is infinity and displays as NaN:NaN due to Date() using inifity.
  1228. if(isFinite(media.duration)) {
  1229. this.status.duration = media.duration;
  1230. }
  1231. ct = media.currentTime;
  1232. cpa = (this.status.duration > 0) ? 100 * ct / this.status.duration : 0;
  1233. if((typeof media.seekable === "object") && (media.seekable.length > 0)) {
  1234. sp = (this.status.duration > 0) ? 100 * media.seekable.end(media.seekable.length-1) / this.status.duration : 100;
  1235. cpr = (this.status.duration > 0) ? 100 * media.currentTime / media.seekable.end(media.seekable.length-1) : 0; // Duration conditional for iOS duration bug. ie., seekable.end is a NaN in that case.
  1236. } else {
  1237. sp = 100;
  1238. cpr = cpa;
  1239. }
  1240. if(override) {
  1241. ct = 0;
  1242. cpr = 0;
  1243. cpa = 0;
  1244. }
  1245. this.status.seekPercent = sp;
  1246. this.status.currentPercentRelative = cpr;
  1247. this.status.currentPercentAbsolute = cpa;
  1248. this.status.currentTime = ct;
  1249. this.status.videoWidth = media.videoWidth;
  1250. this.status.videoHeight = media.videoHeight;
  1251. this.status.readyState = media.readyState;
  1252. this.status.networkState = media.networkState;
  1253. this.status.playbackRate = media.playbackRate;
  1254. this.status.ended = media.ended;
  1255. },
  1256. _resetStatus: function() {
  1257. this.status = $.extend({}, this.status, $.jPlayer.prototype.status); // Maintains the status properties that persist through a reset.
  1258. },
  1259. _trigger: function(eventType, error, warning) { // eventType always valid as called using $.jPlayer.event.eventType
  1260. var event = $.Event(eventType);
  1261. event.jPlayer = {};
  1262. event.jPlayer.version = $.extend({}, this.version);
  1263. event.jPlayer.options = $.extend(true, {}, this.options); // Deep copy
  1264. event.jPlayer.status = $.extend(true, {}, this.status); // Deep copy
  1265. event.jPlayer.html = $.extend(true, {}, this.html); // Deep copy
  1266. event.jPlayer.flash = $.extend(true, {}, this.flash); // Deep copy
  1267. if(error) {
  1268. event.jPlayer.error = $.extend({}, error);
  1269. }
  1270. if(warning) {
  1271. event.jPlayer.warning = $.extend({}, warning);
  1272. }
  1273. this.element.trigger(event);
  1274. },
  1275. jPlayerFlashEvent: function(eventType, status) { // Called from Flash
  1276. if(eventType === $.jPlayer.event.ready) {
  1277. if(!this.internal.ready) {
  1278. this.internal.ready = true;
  1279. this.internal.flash.jq.css({'width':'0px', 'height':'0px'}); // Once Flash generates the ready event, minimise to zero as it is not affected by wmode anymore.
  1280. this.version.flash = status.version;
  1281. if(this.version.needFlash !== this.version.flash) {
  1282. this._error( {
  1283. type: $.jPlayer.error.VERSION,
  1284. context: this.version.flash,