PageRenderTime 71ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/media/foundry/2.1/scripts_/jplayer.js

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