PageRenderTime 38ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 1ms

/ajax/libs/jplayer/2.2.0/jquery.jplayer/jquery.jplayer.js

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