jquery.jplayer.js 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350
  1. /*
  2. * jPlayer Plugin for jQuery JavaScript Library
  3. * http://www.jplayer.org
  4. *
  5. * Copyright (c) 2009 - 2011 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.1.0
  12. * Date: 1st September 2011
  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, nomem:false, onevar:false, passfail:false, plusplus:false, regexp:false, undef:true, sub:false, strict:false, white:false */
  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.1.0",
  213. needFlash: "2.1.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. m4v: { // H.264 / MP4
  397. codec: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
  398. flashCanPlay: true,
  399. media: 'video'
  400. },
  401. ogv: { // OGG
  402. codec: 'video/ogg; codecs="theora, vorbis"',
  403. flashCanPlay: false,
  404. media: 'video'
  405. },
  406. webmv: { // WEBM
  407. codec: 'video/webm; codecs="vorbis, vp8"',
  408. flashCanPlay: false,
  409. media: 'video'
  410. },
  411. flv: { // FLV / F4V
  412. codec: 'video/x-flv',
  413. flashCanPlay: true,
  414. media: 'video'
  415. }
  416. },
  417. _init: function() {
  418. var self = this;
  419. this.element.empty();
  420. this.status = $.extend({}, this.status); // Copy static to unique instance.
  421. this.internal = $.extend({}, this.internal); // Copy static to unique instance.
  422. this.internal.domNode = this.element.get(0);
  423. this.formats = []; // Array based on supplied string option. Order defines priority.
  424. this.solutions = []; // Array based on solution string option. Order defines priority.
  425. this.require = {}; // Which media types are required: video, audio.
  426. this.htmlElement = {}; // DOM elements created by jPlayer
  427. this.html = {}; // In _init()'s this.desired code and setmedia(): Accessed via this[solution], where solution from this.solutions array.
  428. this.html.audio = {};
  429. this.html.video = {};
  430. this.flash = {}; // In _init()'s this.desired code and setmedia(): Accessed via this[solution], where solution from this.solutions array.
  431. this.css = {};
  432. this.css.cs = {}; // Holds the css selector strings
  433. this.css.jq = {}; // Holds jQuery selectors. ie., $(css.cs.method)
  434. this.ancestorJq = []; // Holds jQuery selector of cssSelectorAncestor. Init would use $() instead of [], but it is only 1.4+
  435. this.options.volume = this._limitValue(this.options.volume, 0, 1); // Limit volume value's bounds.
  436. // Create the formats array, with prority based on the order of the supplied formats string
  437. $.each(this.options.supplied.toLowerCase().split(","), function(index1, value1) {
  438. var format = value1.replace(/^\s+|\s+$/g, ""); //trim
  439. if(self.format[format]) { // Check format is valid.
  440. var dupFound = false;
  441. $.each(self.formats, function(index2, value2) { // Check for duplicates
  442. if(format === value2) {
  443. dupFound = true;
  444. return false;
  445. }
  446. });
  447. if(!dupFound) {
  448. self.formats.push(format);
  449. }
  450. }
  451. });
  452. // Create the solutions array, with prority based on the order of the solution string
  453. $.each(this.options.solution.toLowerCase().split(","), function(index1, value1) {
  454. var solution = value1.replace(/^\s+|\s+$/g, ""); //trim
  455. if(self.solution[solution]) { // Check solution is valid.
  456. var dupFound = false;
  457. $.each(self.solutions, function(index2, value2) { // Check for duplicates
  458. if(solution === value2) {
  459. dupFound = true;
  460. return false;
  461. }
  462. });
  463. if(!dupFound) {
  464. self.solutions.push(solution);
  465. }
  466. }
  467. });
  468. this.internal.instance = "jp_" + this.count;
  469. this.instances[this.internal.instance] = this.element;
  470. // Check the jPlayer div has an id and create one if required. Important for Flash to know the unique id for comms.
  471. if(!this.element.attr("id")) {
  472. this.element.attr("id", this.options.idPrefix + "_jplayer_" + this.count);
  473. }
  474. this.internal.self = $.extend({}, {
  475. id: this.element.attr("id"),
  476. jq: this.element
  477. });
  478. this.internal.audio = $.extend({}, {
  479. id: this.options.idPrefix + "_audio_" + this.count,
  480. jq: undefined
  481. });
  482. this.internal.video = $.extend({}, {
  483. id: this.options.idPrefix + "_video_" + this.count,
  484. jq: undefined
  485. });
  486. this.internal.flash = $.extend({}, {
  487. id: this.options.idPrefix + "_flash_" + this.count,
  488. jq: undefined,
  489. swf: this.options.swfPath + (this.options.swfPath.toLowerCase().slice(-4) !== ".swf" ? (this.options.swfPath && this.options.swfPath.slice(-1) !== "/" ? "/" : "") + "Jplayer.swf" : "")
  490. });
  491. this.internal.poster = $.extend({}, {
  492. id: this.options.idPrefix + "_poster_" + this.count,
  493. jq: undefined
  494. });
  495. // Register listeners defined in the constructor
  496. $.each($.jPlayer.event, function(eventName,eventType) {
  497. if(self.options[eventName] !== undefined) {
  498. self.element.bind(eventType + ".jPlayer", self.options[eventName]); // With .jPlayer namespace.
  499. 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.
  500. }
  501. });
  502. // Determine if we require solutions for audio, video or both media types.
  503. this.require.audio = false;
  504. this.require.video = false;
  505. $.each(this.formats, function(priority, format) {
  506. self.require[self.format[format].media] = true;
  507. });
  508. // Now required types are known, finish the options default settings.
  509. if(this.require.video) {
  510. this.options = $.extend(true, {},
  511. this.optionsVideo,
  512. this.options
  513. );
  514. } else {
  515. this.options = $.extend(true, {},
  516. this.optionsAudio,
  517. this.options
  518. );
  519. }
  520. this._setSize(); // update status and jPlayer element size
  521. // Determine the status for Blocklisted options.
  522. this.status.nativeVideoControls = this._uaBlocklist(this.options.nativeVideoControls);
  523. this.status.noFullScreen = this._uaBlocklist(this.options.noFullScreen);
  524. this.status.noVolume = this._uaBlocklist(this.options.noVolume);
  525. // The native controls are only for video and are disabled when audio is also used.
  526. this._restrictNativeVideoControls();
  527. // Create the poster image.
  528. this.htmlElement.poster = document.createElement('img');
  529. this.htmlElement.poster.id = this.internal.poster.id;
  530. 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.
  531. if(!self.status.video || self.status.waitForPlay) {
  532. self.internal.poster.jq.show();
  533. }
  534. };
  535. this.element.append(this.htmlElement.poster);
  536. this.internal.poster.jq = $("#" + this.internal.poster.id);
  537. this.internal.poster.jq.css({'width': this.status.width, 'height': this.status.height});
  538. this.internal.poster.jq.hide();
  539. this.internal.poster.jq.bind("click.jPlayer", function() {
  540. self._trigger($.jPlayer.event.click);
  541. });
  542. // Generate the required media elements
  543. this.html.audio.available = false;
  544. if(this.require.audio) { // If a supplied format is audio
  545. this.htmlElement.audio = document.createElement('audio');
  546. this.htmlElement.audio.id = this.internal.audio.id;
  547. this.html.audio.available = !!this.htmlElement.audio.canPlayType && this._testCanPlayType(this.htmlElement.audio); // Test is for IE9 on Win Server 2008.
  548. }
  549. this.html.video.available = false;
  550. if(this.require.video) { // If a supplied format is video
  551. this.htmlElement.video = document.createElement('video');
  552. this.htmlElement.video.id = this.internal.video.id;
  553. this.html.video.available = !!this.htmlElement.video.canPlayType && this._testCanPlayType(this.htmlElement.video); // Test is for IE9 on Win Server 2008.
  554. }
  555. this.flash.available = this._checkForFlash(10);
  556. this.html.canPlay = {};
  557. this.flash.canPlay = {};
  558. $.each(this.formats, function(priority, format) {
  559. self.html.canPlay[format] = self.html[self.format[format].media].available && "" !== self.htmlElement[self.format[format].media].canPlayType(self.format[format].codec);
  560. self.flash.canPlay[format] = self.format[format].flashCanPlay && self.flash.available;
  561. });
  562. this.html.desired = false;
  563. this.flash.desired = false;
  564. $.each(this.solutions, function(solutionPriority, solution) {
  565. if(solutionPriority === 0) {
  566. self[solution].desired = true;
  567. } else {
  568. var audioCanPlay = false;
  569. var videoCanPlay = false;
  570. $.each(self.formats, function(formatPriority, format) {
  571. if(self[self.solutions[0]].canPlay[format]) { // The other solution can play
  572. if(self.format[format].media === 'video') {
  573. videoCanPlay = true;
  574. } else {
  575. audioCanPlay = true;
  576. }
  577. }
  578. });
  579. self[solution].desired = (self.require.audio && !audioCanPlay) || (self.require.video && !videoCanPlay);
  580. }
  581. });
  582. // This is what jPlayer will support, based on solution and supplied.
  583. this.html.support = {};
  584. this.flash.support = {};
  585. $.each(this.formats, function(priority, format) {
  586. self.html.support[format] = self.html.canPlay[format] && self.html.desired;
  587. self.flash.support[format] = self.flash.canPlay[format] && self.flash.desired;
  588. });
  589. // If jPlayer is supporting any format in a solution, then the solution is used.
  590. this.html.used = false;
  591. this.flash.used = false;
  592. $.each(this.solutions, function(solutionPriority, solution) {
  593. $.each(self.formats, function(formatPriority, format) {
  594. if(self[solution].support[format]) {
  595. self[solution].used = true;
  596. return false;
  597. }
  598. });
  599. });
  600. // Init solution active state and the event gates to false.
  601. this._resetActive();
  602. this._resetGate();
  603. // Set up the css selectors for the control and feedback entities.
  604. this._cssSelectorAncestor(this.options.cssSelectorAncestor);
  605. // If neither html nor flash are being used by this browser, then media playback is not possible. Trigger an error event.
  606. if(!(this.html.used || this.flash.used)) {
  607. this._error( {
  608. type: $.jPlayer.error.NO_SOLUTION,
  609. context: "{solution:'" + this.options.solution + "', supplied:'" + this.options.supplied + "'}",
  610. message: $.jPlayer.errorMsg.NO_SOLUTION,
  611. hint: $.jPlayer.errorHint.NO_SOLUTION
  612. });
  613. if(this.css.jq.noSolution.length) {
  614. this.css.jq.noSolution.show();
  615. }
  616. } else {
  617. if(this.css.jq.noSolution.length) {
  618. this.css.jq.noSolution.hide();
  619. }
  620. }
  621. // Add the flash solution if it is being used.
  622. if(this.flash.used) {
  623. var htmlObj,
  624. flashVars = 'jQuery=' + encodeURI(this.options.noConflict) + '&id=' + encodeURI(this.internal.self.id) + '&vol=' + this.options.volume + '&muted=' + this.options.muted;
  625. // Code influenced by SWFObject 2.2: http://code.google.com/p/swfobject/
  626. // Non IE browsers have an initial Flash size of 1 by 1 otherwise the wmode affected the Flash ready event.
  627. if($.browser.msie && Number($.browser.version) <= 8) {
  628. var objStr = '<object id="' + this.internal.flash.id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="0" height="0"></object>';
  629. var paramStr = [
  630. '<param name="movie" value="' + this.internal.flash.swf + '" />',
  631. '<param name="FlashVars" value="' + flashVars + '" />',
  632. '<param name="allowScriptAccess" value="always" />',
  633. '<param name="bgcolor" value="' + this.options.backgroundColor + '" />',
  634. '<param name="wmode" value="' + this.options.wmode + '" />'
  635. ];
  636. htmlObj = document.createElement(objStr);
  637. for(var i=0; i < paramStr.length; i++) {
  638. htmlObj.appendChild(document.createElement(paramStr[i]));
  639. }
  640. } else {
  641. var createParam = function(el, n, v) {
  642. var p = document.createElement("param");
  643. p.setAttribute("name", n);
  644. p.setAttribute("value", v);
  645. el.appendChild(p);
  646. };
  647. htmlObj = document.createElement("object");
  648. htmlObj.setAttribute("id", this.internal.flash.id);
  649. htmlObj.setAttribute("data", this.internal.flash.swf);
  650. htmlObj.setAttribute("type", "application/x-shockwave-flash");
  651. htmlObj.setAttribute("width", "1"); // Non-zero
  652. htmlObj.setAttribute("height", "1"); // Non-zero
  653. createParam(htmlObj, "flashvars", flashVars);
  654. createParam(htmlObj, "allowscriptaccess", "always");
  655. createParam(htmlObj, "bgcolor", this.options.backgroundColor);
  656. createParam(htmlObj, "wmode", this.options.wmode);
  657. }
  658. this.element.append(htmlObj);
  659. this.internal.flash.jq = $(htmlObj);
  660. }
  661. // Add the HTML solution if being used.
  662. if(this.html.used) {
  663. // The HTML Audio handlers
  664. if(this.html.audio.available) {
  665. this._addHtmlEventListeners(this.htmlElement.audio, this.html.audio);
  666. this.element.append(this.htmlElement.audio);
  667. this.internal.audio.jq = $("#" + this.internal.audio.id);
  668. }
  669. // The HTML Video handlers
  670. if(this.html.video.available) {
  671. this._addHtmlEventListeners(this.htmlElement.video, this.html.video);
  672. this.element.append(this.htmlElement.video);
  673. this.internal.video.jq = $("#" + this.internal.video.id);
  674. if(this.status.nativeVideoControls) {
  675. this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
  676. } else {
  677. this.internal.video.jq.css({'width':'0px', 'height':'0px'}); // Using size 0x0 since a .hide() causes issues in iOS
  678. }
  679. this.internal.video.jq.bind("click.jPlayer", function() {
  680. self._trigger($.jPlayer.event.click);
  681. });
  682. }
  683. }
  684. // Create the bridge that emulates the HTML Media element on the jPlayer DIV
  685. if( this.options.emulateHtml ) {
  686. this._emulateHtmlBridge();
  687. }
  688. if(this.html.used && !this.flash.used) { // If only HTML, then emulate flash ready() call after 100ms.
  689. setTimeout( function() {
  690. self.internal.ready = true;
  691. self.version.flash = "n/a";
  692. self._trigger($.jPlayer.event.repeat); // Trigger the repeat event so its handler can initialize itself with the loop option.
  693. self._trigger($.jPlayer.event.ready);
  694. }, 100);
  695. }
  696. // Initialize the interface components with the options.
  697. 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.
  698. this._updateInterface();
  699. this._updateButtons(false);
  700. this._updateAutohide();
  701. this._updateVolume(this.options.volume);
  702. this._updateMute(this.options.muted);
  703. if(this.css.jq.videoPlay.length) {
  704. this.css.jq.videoPlay.hide();
  705. }
  706. $.jPlayer.prototype.count++; // Change static variable via prototype.
  707. },
  708. destroy: function() {
  709. // MJP: The background change remains. Would need to store the original to restore it correctly.
  710. // MJP: The jPlayer element's size change remains.
  711. // Clear the media to reset the GUI and stop any downloads. Streams on some browsers had persited. (Chrome)
  712. this.clearMedia();
  713. // Remove the size/sizeFull cssClass from the cssSelectorAncestor
  714. this._removeUiClass();
  715. // Remove the times from the GUI
  716. if(this.css.jq.currentTime.length) {
  717. this.css.jq.currentTime.text("");
  718. }
  719. if(this.css.jq.duration.length) {
  720. this.css.jq.duration.text("");
  721. }
  722. // Remove any bindings from the interface controls.
  723. $.each(this.css.jq, function(fn, jq) {
  724. // Check selector is valid before trying to execute method.
  725. if(jq.length) {
  726. jq.unbind(".jPlayer");
  727. }
  728. });
  729. // Remove the click handlers for $.jPlayer.event.click
  730. this.internal.poster.jq.unbind(".jPlayer");
  731. if(this.internal.video.jq) {
  732. this.internal.video.jq.unbind(".jPlayer");
  733. }
  734. // Destroy the HTML bridge.
  735. if(this.options.emulateHtml) {
  736. this._destroyHtmlBridge();
  737. }
  738. this.element.removeData("jPlayer"); // Remove jPlayer data
  739. this.element.unbind(".jPlayer"); // Remove all event handlers created by the jPlayer constructor
  740. this.element.empty(); // Remove the inserted child elements
  741. delete this.instances[this.internal.instance]; // Clear the instance on the static instance object
  742. },
  743. enable: function() { // Plan to implement
  744. // options.disabled = false
  745. },
  746. disable: function () { // Plan to implement
  747. // options.disabled = true
  748. },
  749. _testCanPlayType: function(elem) {
  750. // IE9 on Win Server 2008 did not implement canPlayType(), but it has the property.
  751. try {
  752. elem.canPlayType(this.format.mp3.codec); // The type is irrelevant.
  753. return true;
  754. } catch(err) {
  755. return false;
  756. }
  757. },
  758. _uaBlocklist: function(list) {
  759. // list : object with properties that are all regular expressions. Property names are irrelevant.
  760. // Returns true if the user agent is matched in list.
  761. var ua = navigator.userAgent.toLowerCase(),
  762. block = false;
  763. $.each(list, function(p, re) {
  764. if(re && re.test(ua)) {
  765. block = true;
  766. return false; // exit $.each.
  767. }
  768. });
  769. return block;
  770. },
  771. _restrictNativeVideoControls: function() {
  772. // Fallback to noFullScreen when nativeVideoControls is true and audio media is being used. Affects when both media types are used.
  773. if(this.require.audio) {
  774. if(this.status.nativeVideoControls) {
  775. this.status.nativeVideoControls = false;
  776. this.status.noFullScreen = true;
  777. }
  778. }
  779. },
  780. _updateNativeVideoControls: function() {
  781. if(this.html.video.available && this.html.used) {
  782. // Turn the HTML Video controls on/off
  783. this.htmlElement.video.controls = this.status.nativeVideoControls;
  784. // Show/hide the jPlayer GUI.
  785. this._updateAutohide();
  786. // 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.
  787. if(this.status.nativeVideoControls && this.require.video) {
  788. this.internal.poster.jq.hide();
  789. this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
  790. } else if(this.status.waitForPlay && this.status.video) {
  791. this.internal.poster.jq.show();
  792. this.internal.video.jq.css({'width': '0px', 'height': '0px'});
  793. }
  794. }
  795. },
  796. _addHtmlEventListeners: function(mediaElement, entity) {
  797. var self = this;
  798. mediaElement.preload = this.options.preload;
  799. mediaElement.muted = this.options.muted;
  800. mediaElement.volume = this.options.volume;
  801. // Create the event listeners
  802. // Only want the active entity to affect jPlayer and bubble events.
  803. // Using entity.gate so that object is referenced and gate property always current
  804. mediaElement.addEventListener("progress", function() {
  805. if(entity.gate) {
  806. self._getHtmlStatus(mediaElement);
  807. self._updateInterface();
  808. self._trigger($.jPlayer.event.progress);
  809. }
  810. }, false);
  811. mediaElement.addEventListener("timeupdate", function() {
  812. if(entity.gate) {
  813. self._getHtmlStatus(mediaElement);
  814. self._updateInterface();
  815. self._trigger($.jPlayer.event.timeupdate);
  816. }
  817. }, false);
  818. mediaElement.addEventListener("durationchange", function() {
  819. if(entity.gate) {
  820. self.status.duration = this.duration;
  821. self._getHtmlStatus(mediaElement);
  822. self._updateInterface();
  823. self._trigger($.jPlayer.event.durationchange);
  824. }
  825. }, false);
  826. mediaElement.addEventListener("play", function() {
  827. if(entity.gate) {
  828. self._updateButtons(true);
  829. self._html_checkWaitForPlay(); // So the native controls update this variable and puts the hidden interface in the correct state. Affects toggling native controls.
  830. self._trigger($.jPlayer.event.play);
  831. }
  832. }, false);
  833. mediaElement.addEventListener("playing", function() {
  834. if(entity.gate) {
  835. self._updateButtons(true);
  836. self._seeked();
  837. self._trigger($.jPlayer.event.playing);
  838. }
  839. }, false);
  840. mediaElement.addEventListener("pause", function() {
  841. if(entity.gate) {
  842. self._updateButtons(false);
  843. self._trigger($.jPlayer.event.pause);
  844. }
  845. }, false);
  846. mediaElement.addEventListener("waiting", function() {
  847. if(entity.gate) {
  848. self._seeking();
  849. self._trigger($.jPlayer.event.waiting);
  850. }
  851. }, false);
  852. mediaElement.addEventListener("seeking", function() {
  853. if(entity.gate) {
  854. self._seeking();
  855. self._trigger($.jPlayer.event.seeking);
  856. }
  857. }, false);
  858. mediaElement.addEventListener("seeked", function() {
  859. if(entity.gate) {
  860. self._seeked();
  861. self._trigger($.jPlayer.event.seeked);
  862. }
  863. }, false);
  864. mediaElement.addEventListener("volumechange", function() {
  865. if(entity.gate) {
  866. // Read the values back from the element as the Blackberry PlayBook shares the volume with the physical buttons master volume control.
  867. // However, when tested 6th July 2011, those buttons do not generate an event. The physical play/pause button does though.
  868. self.options.volume = mediaElement.volume;
  869. self.options.muted = mediaElement.muted;
  870. self._updateMute();
  871. self._updateVolume();
  872. self._trigger($.jPlayer.event.volumechange);
  873. }
  874. }, false);
  875. 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.
  876. if(entity.gate) {
  877. self._seeked();
  878. self._trigger($.jPlayer.event.suspend);
  879. }
  880. }, false);
  881. mediaElement.addEventListener("ended", function() {
  882. if(entity.gate) {
  883. // Order of the next few commands are important. Change the time and then pause.
  884. // Solves a bug in Firefox, where issuing pause 1st causes the media to play from the start. ie., The pause is ignored.
  885. 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.
  886. 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.)
  887. }
  888. 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.
  889. self._updateButtons(false);
  890. self._getHtmlStatus(mediaElement, true); // With override true. Otherwise Chrome leaves progress at full.
  891. self._updateInterface();
  892. self._trigger($.jPlayer.event.ended);
  893. }
  894. }, false);
  895. mediaElement.addEventListener("error", function() {
  896. if(entity.gate) {
  897. self._updateButtons(false);
  898. self._seeked();
  899. if(self.status.srcSet) { // Deals with case of clearMedia() causing an error event.
  900. clearTimeout(self.internal.htmlDlyCmdId); // Clears any delayed commands used in the HTML solution.
  901. self.status.waitForLoad = true; // Allows the load operation to try again.
  902. self.status.waitForPlay = true; // Reset since a play was captured.
  903. if(self.status.video && !self.status.nativeVideoControls) {
  904. self.internal.video.jq.css({'width':'0px', 'height':'0px'});
  905. }
  906. if(self._validString(self.status.media.poster) && !self.status.nativeVideoControls) {
  907. self.internal.poster.jq.show();
  908. }
  909. if(self.css.jq.videoPlay.length) {
  910. self.css.jq.videoPlay.show();
  911. }
  912. self._error( {
  913. type: $.jPlayer.error.URL,
  914. context: self.status.src, // this.src shows absolute urls. Want context to show the url given.
  915. message: $.jPlayer.errorMsg.URL,
  916. hint: $.jPlayer.errorHint.URL
  917. });
  918. }
  919. }
  920. }, false);
  921. // Create all the other event listeners that bubble up to a jPlayer event from html, without being used by jPlayer.
  922. $.each($.jPlayer.htmlEvent, function(i, eventType) {
  923. mediaElement.addEventListener(this, function() {
  924. if(entity.gate) {
  925. self._trigger($.jPlayer.event[eventType]);
  926. }
  927. }, false);
  928. });
  929. },
  930. _getHtmlStatus: function(media, override) {
  931. var ct = 0, d = 0, cpa = 0, sp = 0, cpr = 0;
  932. if(media.duration) { // Fixes the duration bug in iOS, where the durationchange event occurs when media.duration is not always correct.
  933. this.status.duration = media.duration;
  934. }
  935. ct = media.currentTime;
  936. cpa = (this.status.duration > 0) ? 100 * ct / this.status.duration : 0;
  937. if((typeof media.seekable === "object") && (media.seekable.length > 0)) {
  938. sp = (this.status.duration > 0) ? 100 * media.seekable.end(media.seekable.length-1) / this.status.duration : 100;
  939. cpr = 100 * media.currentTime / media.seekable.end(media.seekable.length-1);
  940. } else {
  941. sp = 100;
  942. cpr = cpa;
  943. }
  944. if(override) {
  945. ct = 0;
  946. cpr = 0;
  947. cpa = 0;
  948. }
  949. this.status.seekPercent = sp;
  950. this.status.currentPercentRelative = cpr;
  951. this.status.currentPercentAbsolute = cpa;
  952. this.status.currentTime = ct;
  953. this.status.readyState = media.readyState;
  954. this.status.networkState = media.networkState;
  955. this.status.playbackRate = media.playbackRate;
  956. this.status.ended = media.ended;
  957. },
  958. _resetStatus: function() {
  959. this.status = $.extend({}, this.status, $.jPlayer.prototype.status); // Maintains the status properties that persist through a reset.
  960. },
  961. _trigger: function(eventType, error, warning) { // eventType always valid as called using $.jPlayer.event.eventType
  962. var event = $.Event(eventType);
  963. event.jPlayer = {};
  964. event.jPlayer.version = $.extend({}, this.version);
  965. event.jPlayer.options = $.extend(true, {}, this.options); // Deep copy
  966. event.jPlayer.status = $.extend(true, {}, this.status); // Deep copy
  967. event.jPlayer.html = $.extend(true, {}, this.html); // Deep copy
  968. event.jPlayer.flash = $.extend(true, {}, this.flash); // Deep copy
  969. if(error) {
  970. event.jPlayer.error = $.extend({}, error);
  971. }
  972. if(warning) {
  973. event.jPlayer.warning = $.extend({}, warning);
  974. }
  975. this.element.trigger(event);
  976. },
  977. jPlayerFlashEvent: function(eventType, status) { // Called from Flash
  978. if(eventType === $.jPlayer.event.ready) {
  979. if(!this.internal.ready) {
  980. this.internal.ready = true;
  981. 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.
  982. this.version.flash = status.version;
  983. if(this.version.needFlash !== this.version.flash) {
  984. this._error( {
  985. type: $.jPlayer.error.VERSION,
  986. context: this.version.flash,
  987. message: $.jPlayer.errorMsg.VERSION + this.version.flash,
  988. hint: $.jPlayer.errorHint.VERSION
  989. });
  990. }
  991. this._trigger($.jPlayer.event.repeat); // Trigger the repeat event so its handler can initialize itself with the loop option.
  992. this._trigger(eventType);
  993. } else {
  994. // This condition occurs if the Flash is hidden and then shown again.
  995. // Firefox also reloads the Flash if the CSS position changes. position:fixed is used for full screen.
  996. // Only do this if the Flash is the solution being used at the moment. Affects Media players where both solution may be being used.
  997. if(this.flash.gate) {
  998. // Send the current status to the Flash now that it is ready (available) again.
  999. if(this.status.srcSet) {
  1000. // Need to read original status before issuing the setMedia command.
  1001. var currentTime = this.status.currentTime,
  1002. paused = this.status.paused;
  1003. this.setMedia(this.status.media);
  1004. if(currentTime > 0) {
  1005. if(paused) {
  1006. this.pause(currentTime);
  1007. } else {
  1008. this.play(currentTime);
  1009. }
  1010. }
  1011. }
  1012. this._trigger($.jPlayer.event.flashreset);
  1013. }
  1014. }
  1015. }
  1016. if(this.flash.gate) {
  1017. switch(eventType) {
  1018. case $.jPlayer.event.progress:
  1019. this._getFlashStatus(status);
  1020. this._updateInterface();
  1021. this._trigger(eventType);
  1022. break;
  1023. case $.jPlayer.event.timeupdate:
  1024. this._getFlashStatus(status);
  1025. this._updateInterface();
  1026. this._trigger(eventType);
  1027. break;
  1028. case $.jPlayer.event.play:
  1029. this._seeked();
  1030. this._updateButtons(true);
  1031. this._trigger(eventType);
  1032. break;
  1033. case $.jPlayer.event.pause:
  1034. this._updateButtons(false);
  1035. this._trigger(eventType);
  1036. break;
  1037. case $.jPlayer.event.ended:
  1038. this._updateButtons(false);
  1039. this._trigger(eventType);
  1040. break;
  1041. case $.jPlayer.event.click:
  1042. this._trigger(eventType); // This could be dealt with by the default
  1043. break;
  1044. case $.jPlayer.event.error:
  1045. this.status.waitForLoad = true; // Allows the load operation to try again.
  1046. this.status.waitForPlay = true; // Reset since a play was captured.
  1047. if(this.status.video) {
  1048. this.internal.flash.jq.css({'width':'0px', 'height':'0px'});
  1049. }
  1050. if(this._validString(this.status.media.poster)) {
  1051. this.internal.poster.jq.show();
  1052. }
  1053. if(this.css.jq.videoPlay.length && this.status.video) {
  1054. this.css.jq.videoPlay.show();
  1055. }
  1056. if(this.status.video) { // Set up for another try. Execute before error event.
  1057. this._flash_setVideo(this.status.media);
  1058. } else {
  1059. this._flash_setAudio(this.status.media);
  1060. }
  1061. this._updateButtons(false);
  1062. this._error( {
  1063. type: $.jPlayer.error.URL,
  1064. context:status.src,
  1065. message: $.jPlayer.errorMsg.URL,
  1066. hint: $.jPlayer.errorHint.URL
  1067. });
  1068. break;
  1069. case $.jPlayer.event.seeking:
  1070. this._seeking();
  1071. this._trigger(eventType);
  1072. break;
  1073. case $.jPlayer.event.seeked:
  1074. this._seeked();
  1075. this._trigger(eventType);
  1076. break;
  1077. case $.jPlayer.event.ready:
  1078. // The ready event is handled outside the switch statement.
  1079. // Captured here otherwise 2 ready events would be generated if the ready event handler used setMedia.
  1080. break;
  1081. default:
  1082. this._trigger(eventType);
  1083. }
  1084. }
  1085. return false;
  1086. },
  1087. _getFlashStatus: function(status) {
  1088. this.status.seekPercent = status.seekPercent;
  1089. this.status.currentPercentRelative = status.currentPercentRelative;
  1090. this.status.currentPercentAbsolute = status.currentPercentAbsolute;
  1091. this.status.currentTime = status.currentTime;
  1092. this.status.duration = status.duration;
  1093. // The Flash does not generate this information in this release
  1094. this.status.readyState = 4; // status.readyState;
  1095. this.status.networkState = 0; // status.networkState;
  1096. this.status.playbackRate = 1; // status.playbackRate;
  1097. this.status.ended = false; // status.ended;
  1098. },
  1099. _updateButtons: function(playing) {
  1100. if(playing !== undefined) {
  1101. this.status.paused = !playing;
  1102. if(this.css.jq.play.length && this.css.jq.pause.length) {
  1103. if(playing) {
  1104. this.css.jq.play.hide();
  1105. this.css.jq.pause.show();
  1106. } else {
  1107. this.css.jq.play.show();
  1108. this.css.jq.pause.hide();
  1109. }
  1110. }
  1111. }
  1112. if(this.css.jq.restoreScreen.length && this.css.jq.fullScreen.length) {
  1113. if(this.status.noFullScreen) {
  1114. this.css.jq.fullScreen.hide();
  1115. this.css.jq.restoreScreen.hide();
  1116. } else if(this.options.fullScreen) {
  1117. this.css.jq.fullScreen.hide();
  1118. this.css.jq.restoreScreen.show();
  1119. } else {
  1120. this.css.jq.fullScreen.show();
  1121. this.css.jq.restoreScreen.hide();
  1122. }
  1123. }
  1124. if(this.css.jq.repeat.length && this.css.jq.repeatOff.length) {
  1125. if(this.options.loop) {
  1126. this.css.jq.repeat.hide();
  1127. this.css.jq.repeatOff.show();
  1128. } else {
  1129. this.css.jq.repeat.show();
  1130. this.css.jq.repeatOff.hide();
  1131. }
  1132. }
  1133. },
  1134. _updateInterface: function() {
  1135. if(this.css.jq.seekBar.length) {
  1136. this.css.jq.seekBar.width(this.status.seekPercent+"%");
  1137. }
  1138. if(this.css.jq.playBar.length) {
  1139. this.css.jq.playBar.width(this.status.currentPercentRelative+"%");
  1140. }
  1141. if(this.css.jq.currentTime.length) {
  1142. this.css.jq.currentTime.text($.jPlayer.convertTime(this.status.currentTime));
  1143. }
  1144. if(this.css.jq.duration.length) {
  1145. this.css.jq.duration.text($.jPlayer.convertTime(this.status.duration));
  1146. }
  1147. },
  1148. _seeking: function() {
  1149. if(this.css.jq.seekBar.length) {
  1150. this.css.jq.seekBar.addClass("jp-seeking-bg");
  1151. }
  1152. },
  1153. _seeked: function() {
  1154. if(this.css.jq.seekBar.length) {
  1155. this.css.jq.seekBar.removeClass("jp-seeking-bg");
  1156. }
  1157. },
  1158. _resetGate: function() {
  1159. this.html.audio.gate = false;
  1160. this.html.video.gate = false;
  1161. this.flash.gate = false;
  1162. },
  1163. _resetActive: function() {
  1164. this.html.active = false;
  1165. this.flash.active = false;
  1166. },
  1167. setMedia: function(media) {
  1168. /* media[format] = String: URL of format. Must contain all of the supplied option's video or audio formats.
  1169. * media.poster = String: Video poster URL.
  1170. * media.subtitles = String: * NOT IMPLEMENTED * URL of subtitles SRT file
  1171. * media.chapters = String: * NOT IMPLEMENTED * URL of chapters SRT file
  1172. * media.stream = Boolean: * NOT IMPLEMENTED * Designating actual media streams. ie., "false/undefined" for files. Plan to refresh the flash every so often.
  1173. */
  1174. var self = this,
  1175. supported = false,
  1176. 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.
  1177. this._resetMedia();
  1178. this._resetGate();
  1179. this._resetActive();
  1180. $.each(this.formats, function(formatPriority, format) {
  1181. var isVideo = self.format[format].media === 'video';
  1182. $.each(self.solutions, function(solutionPriority, solution) {
  1183. if(self[solution].support[format] && self._validString(media[format])) { // Format supported in solution and url given for format.
  1184. var isHtml = solution === 'html';
  1185. if(isVideo) {
  1186. if(isHtml) {
  1187. self.html.video.gate = true;
  1188. self._html_setVideo(media);
  1189. self.html.active = true;
  1190. } else {
  1191. self.flash.gate = true;
  1192. self._flash_setVideo(media);
  1193. self.flash.active = true;
  1194. }
  1195. if(self.css.jq.videoPlay.length) {
  1196. self.css.jq.videoPlay.show();
  1197. }
  1198. self.status.video = true;
  1199. } else {
  1200. if(isHtml) {
  1201. self.html.audio.gate = true;
  1202. self._html_setAudio(media);
  1203. self.html.active = true;
  1204. } else {
  1205. self.flash.gate = true;
  1206. self._flash_setAudio(media);
  1207. self.flash.active = true;
  1208. }
  1209. if(self.css.jq.videoPlay.length) {
  1210. self.css.jq.videoPlay.hide();
  1211. }
  1212. self.status.video = false;
  1213. }
  1214. supported = true;
  1215. return false; // Exit $.each
  1216. }
  1217. });
  1218. if(supported) {
  1219. return false; // Exit $.each
  1220. }
  1221. });
  1222. if(supported) {
  1223. if(!(this.status.nativeVideoControls && this.html.video.gate)) {
  1224. // Set poster IMG if native video controls are not being used
  1225. // Note: With IE the IMG onload event occurs immediately when cached.
  1226. // Note: Poster hidden by default in _resetMedia()
  1227. if(this._validString(media.poster)) {
  1228. if(posterChanged) { // Since some browsers do not generate img onload event.
  1229. this.htmlElement.poster.src = media.poster;
  1230. } else {
  1231. this.internal.poster.jq.show();
  1232. }
  1233. }
  1234. }
  1235. this.status.srcSet = true;
  1236. this.status.media = $.extend({}, media);
  1237. this._updateButtons(false);
  1238. this._updateInterface();
  1239. } else { // jPlayer cannot support any formats provided in this browser
  1240. // Send an error event
  1241. this._error( {
  1242. type: $.jPlayer.error.NO_SUPPORT,
  1243. context: "{supplied:'" + this.options.supplied + "'}",
  1244. message: $.jPlayer.errorMsg.NO_SUPPORT,
  1245. hint: $.jPlayer.errorHint.NO_SUPPORT
  1246. });
  1247. }
  1248. },
  1249. _resetMedia: function() {
  1250. this._resetStatus();
  1251. this._updateButtons(false);
  1252. this._updateInterface();
  1253. this._seeked();
  1254. this.internal.poster.jq.hide();
  1255. clearTimeout(this.internal.htmlDlyCmdId);
  1256. if(this.html.active) {
  1257. this._html_resetMedia();
  1258. } else if(this.flash.active) {
  1259. this._flash_resetMedia();
  1260. }
  1261. },
  1262. clearMedia: function() {
  1263. this._resetMedia();
  1264. if(this.html.active) {
  1265. this._html_clearMedia();
  1266. } else if(this.flash.active) {
  1267. this._flash_clearMedia();
  1268. }
  1269. this._resetGate();
  1270. this._resetActive();
  1271. },
  1272. load: function() {
  1273. if(this.status.srcSet) {
  1274. if(this.html.active) {
  1275. this._html_load();
  1276. } else if(this.flash.active) {
  1277. this._flash_load();
  1278. }
  1279. } else {
  1280. this._urlNotSetError("load");
  1281. }
  1282. },
  1283. play: function(time) {
  1284. time = (typeof time === "number") ? time : NaN; // Remove jQuery event from click handler
  1285. if(this.status.srcSet) {
  1286. if(this.html.active) {
  1287. this._html_play(time);
  1288. } else if(this.flash.active) {
  1289. this._flash_play(time);
  1290. }
  1291. } else {
  1292. this._urlNotSetError("play");
  1293. }
  1294. },
  1295. videoPlay: function(e) { // Handles clicks on the play button over the video poster
  1296. this.play();
  1297. },
  1298. pause: function(time) {
  1299. time = (typeof time === "number") ? time : NaN; // Remove jQuery event from click handler
  1300. if(this.status.srcSet) {
  1301. if(this.html.active) {
  1302. this._html_pause(time);
  1303. } else if(this.flash.active) {
  1304. this._flash_pause(time);
  1305. }
  1306. } else {
  1307. this._urlNotSetError("pause");
  1308. }
  1309. },
  1310. pauseOthers: function() {
  1311. var self = this;
  1312. $.each(this.instances, function(i, element) {
  1313. if(self.element !== element) { // Do not this instance.
  1314. if(element.data("jPlayer").status.srcSet) { // Check that media is set otherwise would cause error event.
  1315. element.jPlayer("pause");
  1316. }
  1317. }
  1318. });
  1319. },
  1320. stop: function() {
  1321. if(this.status.srcSet) {
  1322. if(this.html.active) {
  1323. this._html_pause(0);
  1324. } else if(this.flash.active) {
  1325. this._flash_pause(0);
  1326. }
  1327. } else {
  1328. this._urlNotSetError("stop");
  1329. }
  1330. },
  1331. playHead: function(p) {
  1332. p = this._limitValue(p, 0, 100);
  1333. if(this.status.srcSet) {
  1334. if(this.html.active) {
  1335. this._html_playHead(p);
  1336. } else if(this.flash.active) {
  1337. this._flash_playHead(p);
  1338. }
  1339. } else {
  1340. this._urlNotSetError("playHead");
  1341. }
  1342. },
  1343. _muted: function(muted) {
  1344. this.options.muted = muted;
  1345. if(this.html.used) {
  1346. this._html_mute(muted);
  1347. }
  1348. if(this.flash.used) {
  1349. this._flash_mute(muted);
  1350. }
  1351. // The HTML solution generates this event from the media element itself.
  1352. if(!this.html.video.gate && !this.html.audio.gate) {
  1353. this._updateMute(muted);
  1354. this._updateVolume(this.options.volume);
  1355. this._trigger($.jPlayer.event.volumechange);
  1356. }
  1357. },
  1358. mute: function(mute) { // mute is either: undefined (true), an event object (true) or a boolean (muted).
  1359. mute = mute === undefined ? true : !!mute;
  1360. this._muted(mute);
  1361. },
  1362. unmute: function(unmute) { // unmute is either: undefined (true), an event object (true) or a boolean (!muted).
  1363. unmute = unmute === undefined ? true : !!unmute;
  1364. this._muted(!unmute);
  1365. },
  1366. _updateMute: function(mute) {
  1367. if(mute === undefined) {
  1368. mute = this.options.muted;
  1369. }
  1370. if(this.css.jq.mute.length && this.css.jq.unmute.length) {
  1371. if(this.status.noVolume) {
  1372. this.css.jq.mute.hide();
  1373. this.css.jq.unmute.hide();
  1374. } else if(mute) {
  1375. this.css.jq.mute.hide();
  1376. this.css.jq.unmute.show();
  1377. } else {
  1378. this.css.jq.mute.show();
  1379. this.css.jq.unmute.hide();
  1380. }
  1381. }
  1382. },
  1383. volume: function(v) {
  1384. v = this._limitValue(v, 0, 1);
  1385. this.options.volume = v;
  1386. if(this.html.used) {
  1387. this._html_volume(v);
  1388. }
  1389. if(this.flash.used) {
  1390. this._flash_volume(v);
  1391. }
  1392. // The HTML solution generates this event from the media element itself.
  1393. if(!this.html.video.gate && !this.html.audio.gate) {
  1394. this._updateVolume(v);
  1395. this._trigger($.jPlayer.event.volumechange);
  1396. }
  1397. },
  1398. volumeBar: function(e) { // Handles clicks on the volumeBar
  1399. if(this.css.jq.volumeBar.length) {
  1400. var offset = this.css.jq.volumeBar.offset(),
  1401. x = e.pageX - offset.left,
  1402. w = this.css.jq.volumeBar.width(),
  1403. y = this.css.jq.volumeBar.height() - e.pageY + offset.top,
  1404. h = this.css.jq.volumeBar.height();
  1405. if(this.options.verticalVolume) {
  1406. this.volume(y/h);
  1407. } else {
  1408. this.volume(x/w);
  1409. }
  1410. }
  1411. if(this.options.muted) {
  1412. this._muted(false);
  1413. }
  1414. },
  1415. volumeBarValue: function(e) { // Handles clicks on the volumeBarValue
  1416. this.volumeBar(e);
  1417. },
  1418. _updateVolume: function(v) {
  1419. if(v === undefined) {
  1420. v = this.options.volume;
  1421. }
  1422. v = this.options.muted ? 0 : v;
  1423. if(this.status.noVolume) {
  1424. if(this.css.jq.volumeBar.length) {
  1425. this.css.jq.volumeBar.hide();
  1426. }
  1427. if(this.css.jq.volumeBarValue.length) {
  1428. this.css.jq.volumeBarValue.hide();
  1429. }
  1430. if(this.css.jq.volumeMax.length) {
  1431. this.css.jq.volumeMax.hide();
  1432. }
  1433. } else {
  1434. if(this.css.jq.volumeBar.length) {
  1435. this.css.jq.volumeBar.show();
  1436. }
  1437. if(this.css.jq.volumeBarValue.length) {
  1438. this.css.jq.volumeBarValue.show();
  1439. this.css.jq.volumeBarValue[this.options.verticalVolume ? "height" : "width"]((v*100)+"%");
  1440. }
  1441. if(this.css.jq.volumeMax.length) {
  1442. this.css.jq.volumeMax.show();
  1443. }
  1444. }
  1445. },
  1446. volumeMax: function() { // Handles clicks on the volume max
  1447. this.volume(1);
  1448. if(this.options.muted) {
  1449. this._muted(false);
  1450. }
  1451. },
  1452. _cssSelectorAncestor: function(ancestor) {
  1453. var self = this;
  1454. this.options.cssSelectorAncestor = ancestor;
  1455. this._removeUiClass();
  1456. this.ancestorJq = ancestor ? $(ancestor) : []; // Would use $() instead of [], but it is only 1.4+
  1457. if(ancestor && this.ancestorJq.length !== 1) { // So empty strings do not generate the warning.
  1458. this._warning( {
  1459. type: $.jPlayer.warning.CSS_SELECTOR_COUNT,
  1460. context: ancestor,
  1461. message: $.jPlayer.warningMsg.CSS_SELECTOR_COUNT + this.ancestorJq.length + " found for cssSelectorAncestor.",
  1462. hint: $.jPlayer.warningHint.CSS_SELECTOR_COUNT
  1463. });
  1464. }
  1465. this._addUiClass();
  1466. $.each(this.options.cssSelector, function(fn, cssSel) {
  1467. self._cssSelector(fn, cssSel);
  1468. });
  1469. },
  1470. _cssSelector: function(fn, cssSel) {
  1471. var self = this;
  1472. if(typeof cssSel === 'string') {
  1473. if($.jPlayer.prototype.options.cssSelector[fn]) {
  1474. if(this.css.jq[fn] && this.css.jq[fn].length) {
  1475. this.css.jq[fn].unbind(".jPlayer");
  1476. }
  1477. this.options.cssSelector[fn] = cssSel;
  1478. this.css.cs[fn] = this.options.cssSelectorAncestor + " " + cssSel;
  1479. if(cssSel) { // Checks for empty string
  1480. this.css.jq[fn] = $(this.css.cs[fn]);
  1481. } else {
  1482. this.css.jq[fn] = []; // To comply with the css.jq[fn].length check before its use. As of jQuery 1.4 could have used $() for an empty set.
  1483. }
  1484. if(this.css.jq[fn].length) {
  1485. var handler = function(e) {
  1486. self[fn](e);
  1487. $(this).blur();
  1488. return false;
  1489. };
  1490. this.css.jq[fn].bind("click.jPlayer", handler); // Using jPlayer namespace
  1491. }
  1492. if(cssSel && this.css.jq[fn].length !== 1) { // So empty strings do not generate the warning. ie., they just remove the old one.
  1493. this._warning( {
  1494. type: $.jPlayer.warning.CSS_SELECTOR_COUNT,
  1495. context: this.css.cs[fn],
  1496. message: $.jPlayer.warningMsg.CSS_SELECTOR_COUNT + this.css.jq[fn].length + " found for " + fn + " method.",
  1497. hint: $.jPlayer.warningHint.CSS_SELECTOR_COUNT
  1498. });
  1499. }
  1500. } else {
  1501. this._warning( {
  1502. type: $.jPlayer.warning.CSS_SELECTOR_METHOD,
  1503. context: fn,
  1504. message: $.jPlayer.warningMsg.CSS_SELECTOR_METHOD,
  1505. hint: $.jPlayer.warningHint.CSS_SELECTOR_METHOD
  1506. });
  1507. }
  1508. } else {
  1509. this._warning( {
  1510. type: $.jPlayer.warning.CSS_SELECTOR_STRING,
  1511. context: cssSel,
  1512. message: $.jPlayer.warningMsg.CSS_SELECTOR_STRING,
  1513. hint: $.jPlayer.warningHint.CSS_SELECTOR_STRING
  1514. });
  1515. }
  1516. },
  1517. seekBar: function(e) { // Handles clicks on the seekBar
  1518. if(this.css.jq.seekBar) {
  1519. var offset = this.css.jq.seekBar.offset();
  1520. var x = e.pageX - offset.left;
  1521. var w = this.css.jq.seekBar.width();
  1522. var p = 100*x/w;
  1523. this.playHead(p);
  1524. }
  1525. },
  1526. playBar: function(e) { // Handles clicks on the playBar
  1527. this.seekBar(e);
  1528. },
  1529. repeat: function() { // Handle clicks on the repeat button
  1530. this._loop(true);
  1531. },
  1532. repeatOff: function() { // Handle clicks on the repeatOff button
  1533. this._loop(false);
  1534. },
  1535. _loop: function(loop) {
  1536. if(this.options.loop !== loop) {
  1537. this.options.loop = loop;
  1538. this._updateButtons();
  1539. this._trigger($.jPlayer.event.repeat);
  1540. }
  1541. },
  1542. // Plan to review the cssSelector method to cope with missing associated functions accordingly.
  1543. currentTime: function(e) { // Handles clicks on the text
  1544. // Added to avoid errors using cssSelector system for the text
  1545. },
  1546. duration: function(e) { // Handles clicks on the text
  1547. // Added to avoid errors using cssSelector system for the text
  1548. },
  1549. gui: function(e) { // Handles clicks on the gui
  1550. // Added to avoid errors using cssSelector system for the gui
  1551. },
  1552. noSolution: function(e) { // Handles clicks on the error message
  1553. // Added to avoid errors using cssSelector system for no-solution
  1554. },
  1555. // Options code adapted from ui.widget.js (1.8.7). Made changes so the key can use dot notation. To match previous getData solution in jPlayer 1.
  1556. option: function(key, value) {
  1557. var options = key;
  1558. // Enables use: options(). Returns a copy of options object
  1559. if ( arguments.length === 0 ) {
  1560. return $.extend( true, {}, this.options );
  1561. }
  1562. if(typeof key === "string") {
  1563. var keys = key.split(".");
  1564. // Enables use: options("someOption") Returns a copy of the option. Supports dot notation.
  1565. if(value === undefined) {
  1566. var opt = $.extend(true, {}, this.options);
  1567. for(var i = 0; i < keys.length; i++) {
  1568. if(opt[keys[i]] !== undefined) {
  1569. opt = opt[keys[i]];
  1570. } else {
  1571. this._warning( {
  1572. type: $.jPlayer.warning.OPTION_KEY,
  1573. context: key,
  1574. message: $.jPlayer.warningMsg.OPTION_KEY,
  1575. hint: $.jPlayer.warningHint.OPTION_KEY
  1576. });
  1577. return undefined;
  1578. }
  1579. }
  1580. return opt;
  1581. }
  1582. // Enables use: options("someOptionObject", someObject}). Creates: {someOptionObject:someObject}
  1583. // Enables use: options("someOption", someValue). Creates: {someOption:someValue}
  1584. // Enables use: options("someOptionObject.someOption", someValue). Creates: {someOptionObject:{someOption:someValue}}
  1585. options = {};
  1586. var opts = options;
  1587. for(var j = 0; j < keys.length; j++) {
  1588. if(j < keys.length - 1) {
  1589. opts[keys[j]] = {};
  1590. opts = opts[keys[j]];
  1591. } else {
  1592. opts[keys[j]] = value;
  1593. }
  1594. }
  1595. }
  1596. // Otherwise enables use: options(optionObject). Uses original object (the key)
  1597. this._setOptions(options);
  1598. return this;
  1599. },
  1600. _setOptions: function(options) {
  1601. var self = this;
  1602. $.each(options, function(key, value) { // This supports the 2 level depth that the options of jPlayer has. Would review if we ever need more depth.
  1603. self._setOption(key, value);
  1604. });
  1605. return this;
  1606. },
  1607. _setOption: function(key, value) {
  1608. var self = this;
  1609. // The ability to set options is limited at this time.
  1610. switch(key) {
  1611. case "volume" :
  1612. this.volume(value);
  1613. break;
  1614. case "muted" :
  1615. this._muted(value);
  1616. break;
  1617. case "cssSelectorAncestor" :
  1618. this._cssSelectorAncestor(value); // Set and refresh all associations for the new ancestor.
  1619. break;
  1620. case "cssSelector" :
  1621. $.each(value, function(fn, cssSel) {
  1622. self._cssSelector(fn, cssSel); // NB: The option is set inside this function, after further validity checks.
  1623. });
  1624. break;
  1625. case "fullScreen" :
  1626. if(this.options[key] !== value) { // if changed
  1627. this._removeUiClass();
  1628. this.options[key] = value;
  1629. this._refreshSize();
  1630. }
  1631. break;
  1632. case "size" :
  1633. if(!this.options.fullScreen && this.options[key].cssClass !== value.cssClass) {
  1634. this._removeUiClass();
  1635. }
  1636. this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
  1637. this._refreshSize();
  1638. break;
  1639. case "sizeFull" :
  1640. if(this.options.fullScreen && this.options[key].cssClass !== value.cssClass) {
  1641. this._removeUiClass();
  1642. }
  1643. this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
  1644. this._refreshSize();
  1645. break;
  1646. case "autohide" :
  1647. this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
  1648. this._updateAutohide();
  1649. break;
  1650. case "loop" :
  1651. this._loop(value);
  1652. break;
  1653. case "nativeVideoControls" :
  1654. this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
  1655. this.status.nativeVideoControls = this._uaBlocklist(this.options.nativeVideoControls);
  1656. this._restrictNativeVideoControls();
  1657. this._updateNativeVideoControls();
  1658. break;
  1659. case "noFullScreen" :
  1660. this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
  1661. this.status.nativeVideoControls = this._uaBlocklist(this.options.nativeVideoControls); // Need to check again as noFullScreen can depend on this flag and the restrict() can override it.
  1662. this.status.noFullScreen = this._uaBlocklist(this.options.noFullScreen);
  1663. this._restrictNativeVideoControls();
  1664. this._updateButtons();
  1665. break;
  1666. case "noVolume" :
  1667. this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
  1668. this.status.noVolume = this._uaBlocklist(this.options.noVolume);
  1669. this._updateVolume();
  1670. this._updateMute();
  1671. break;
  1672. case "emulateHtml" :
  1673. if(this.options[key] !== value) { // To avoid multiple event handlers being created, if true already.
  1674. this.options[key] = value;
  1675. if(value) {
  1676. this._emulateHtmlBridge();
  1677. } else {
  1678. this._destroyHtmlBridge();
  1679. }
  1680. }
  1681. break;
  1682. }
  1683. return this;
  1684. },
  1685. // End of: (Options code adapted from ui.widget.js)
  1686. _refreshSize: function() {
  1687. this._setSize(); // update status and jPlayer element size
  1688. this._addUiClass(); // update the ui class
  1689. this._updateSize(); // update internal sizes
  1690. this._updateButtons();
  1691. this._updateAutohide();
  1692. this._trigger($.jPlayer.event.resize);
  1693. },
  1694. _setSize: function() {
  1695. // Determine the current size from the options
  1696. if(this.options.fullScreen) {
  1697. this.status.width = this.options.sizeFull.width;
  1698. this.status.height = this.options.sizeFull.height;
  1699. this.status.cssClass = this.options.sizeFull.cssClass;
  1700. } else {
  1701. this.status.width = this.options.size.width;
  1702. this.status.height = this.options.size.height;
  1703. this.status.cssClass = this.options.size.cssClass;
  1704. }
  1705. // Set the size of the jPlayer area.
  1706. this.element.css({'width': this.status.width, 'height': this.status.height});
  1707. },
  1708. _addUiClass: function() {
  1709. if(this.ancestorJq.length) {
  1710. this.ancestorJq.addClass(this.status.cssClass);
  1711. }
  1712. },
  1713. _removeUiClass: function() {
  1714. if(this.ancestorJq.length) {
  1715. this.ancestorJq.removeClass(this.status.cssClass);
  1716. }
  1717. },
  1718. _updateSize: function() {
  1719. // The poster uses show/hide so can simply resize it.
  1720. this.internal.poster.jq.css({'width': this.status.width, 'height': this.status.height});
  1721. // Video html or flash resized if necessary at this time, or if native video controls being used.
  1722. if(!this.status.waitForPlay && this.html.active && this.status.video || this.html.video.available && this.html.used && this.status.nativeVideoControls) {
  1723. this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
  1724. }
  1725. else if(!this.status.waitForPlay && this.flash.active && this.status.video) {
  1726. this.internal.flash.jq.css({'width': this.status.width, 'height': this.status.height});
  1727. }
  1728. },
  1729. _updateAutohide: function() {
  1730. var self = this,
  1731. event = "mousemove.jPlayer",
  1732. namespace = ".jPlayerAutohide",
  1733. eventType = event + namespace,
  1734. handler = function() {
  1735. self.css.jq.gui.fadeIn(self.options.autohide.fadeIn, function() {
  1736. clearTimeout(self.internal.autohideId);
  1737. self.internal.autohideId = setTimeout( function() {
  1738. self.css.jq.gui.fadeOut(self.options.autohide.fadeOut);
  1739. }, self.options.autohide.hold);
  1740. });
  1741. };
  1742. if(this.css.jq.gui.length) {
  1743. // End animations first so that its callback is executed now.
  1744. // Otherwise an in progress fadeIn animation still has the callback to fadeOut again.
  1745. this.css.jq.gui.stop(true, true);
  1746. // Removes the fadeOut operation from the fadeIn callback.
  1747. clearTimeout(this.internal.autohideId);
  1748. this.element.unbind(namespace);
  1749. this.css.jq.gui.unbind(namespace);
  1750. if(!this.status.nativeVideoControls) {
  1751. if(this.options.fullScreen && this.options.autohide.full || !this.options.fullScreen && this.options.autohide.restored) {
  1752. this.element.bind(eventType, handler);
  1753. this.css.jq.gui.bind(eventType, handler);
  1754. this.css.jq.gui.hide();
  1755. } else {
  1756. this.css.jq.gui.show();
  1757. }
  1758. } else {
  1759. this.css.jq.gui.hide();
  1760. }
  1761. }
  1762. },
  1763. fullScreen: function() {
  1764. this._setOption("fullScreen", true);
  1765. },
  1766. restoreScreen: function() {
  1767. this._setOption("fullScreen", false);
  1768. },
  1769. _html_initMedia: function() {
  1770. this.htmlElement.media.src = this.status.src;
  1771. if(this.options.preload !== 'none') {
  1772. this._html_load(); // See function for comments
  1773. }
  1774. this._trigger($.jPlayer.event.timeupdate); // The flash generates this event for its solution.
  1775. },
  1776. _html_setAudio: function(media) {
  1777. var self = this;
  1778. // Always finds a format due to checks in setMedia()
  1779. $.each(this.formats, function(priority, format) {
  1780. if(self.html.support[format] && media[format]) {
  1781. self.status.src = media[format];
  1782. self.status.format[format] = true;
  1783. self.status.formatType = format;
  1784. return false;
  1785. }
  1786. });
  1787. this.htmlElement.media = this.htmlElement.audio;
  1788. this._html_initMedia();
  1789. },
  1790. _html_setVideo: function(media) {
  1791. var self = this;
  1792. // Always finds a format due to checks in setMedia()
  1793. $.each(this.formats, function(priority, format) {
  1794. if(self.html.support[format] && media[format]) {
  1795. self.status.src = media[format];
  1796. self.status.format[format] = true;
  1797. self.status.formatType = format;
  1798. return false;
  1799. }
  1800. });
  1801. if(this.status.nativeVideoControls) {
  1802. this.htmlElement.video.poster = this._validString(media.poster) ? media.poster : "";
  1803. }
  1804. this.htmlElement.media = this.htmlElement.video;
  1805. this._html_initMedia();
  1806. },
  1807. _html_resetMedia: function() {
  1808. if(this.htmlElement.media) {
  1809. if(this.htmlElement.media.id === this.internal.video.id && !this.status.nativeVideoControls) {
  1810. this.internal.video.jq.css({'width':'0px', 'height':'0px'});
  1811. }
  1812. this.htmlElement.media.pause();
  1813. }
  1814. },
  1815. _html_clearMedia: function() {
  1816. if(this.htmlElement.media) {
  1817. this.htmlElement.media.src = "";
  1818. this.htmlElement.media.load(); // Stops an old, "in progress" download from continuing the download. Triggers the loadstart, error and emptied events, due to the empty src. Also an abort event if a download was in progress.
  1819. }
  1820. },
  1821. _html_load: function() {
  1822. // This function remains to allow the early HTML5 browsers to work, such as Firefox 3.6
  1823. // A change in the W3C spec for the media.load() command means that this is no longer necessary.
  1824. // This command should be removed and actually causes minor undesirable effects on some browsers. Such as loading the whole file and not only the metadata.
  1825. if(this.status.waitForLoad) {
  1826. this.status.waitForLoad = false;
  1827. this.htmlElement.media.load();
  1828. }
  1829. clearTimeout(this.internal.htmlDlyCmdId);
  1830. },
  1831. _html_play: function(time) {
  1832. var self = this;
  1833. this._html_load(); // Loads if required and clears any delayed commands.
  1834. this.htmlElement.media.play(); // Before currentTime attempt otherwise Firefox 4 Beta never loads.
  1835. if(!isNaN(time)) {
  1836. try {
  1837. this.htmlElement.media.currentTime = time;
  1838. } catch(err) {
  1839. this.internal.htmlDlyCmdId = setTimeout(function() {
  1840. self.play(time);
  1841. }, 100);
  1842. return; // Cancel execution and wait for the delayed command.
  1843. }
  1844. }
  1845. this._html_checkWaitForPlay();
  1846. },
  1847. _html_pause: function(time) {
  1848. var self = this;
  1849. if(time > 0) { // We do not want the stop() command, which does pause(0), causing a load operation.
  1850. this._html_load(); // Loads if required and clears any delayed commands.
  1851. } else {
  1852. clearTimeout(this.internal.htmlDlyCmdId);
  1853. }
  1854. // Order of these commands is important for Safari (Win) and IE9. Pause then change currentTime.
  1855. this.htmlElement.media.pause();
  1856. if(!isNaN(time)) {
  1857. try {
  1858. this.htmlElement.media.currentTime = time;
  1859. } catch(err) {
  1860. this.internal.htmlDlyCmdId = setTimeout(function() {
  1861. self.pause(time);
  1862. }, 100);
  1863. return; // Cancel execution and wait for the delayed command.
  1864. }
  1865. }
  1866. if(time > 0) { // Avoids a setMedia() followed by stop() or pause(0) hiding the video play button.
  1867. this._html_checkWaitForPlay();
  1868. }
  1869. },
  1870. _html_playHead: function(percent) {
  1871. var self = this;
  1872. this._html_load(); // Loads if required and clears any delayed commands.
  1873. try {
  1874. if((typeof this.htmlElement.media.seekable === "object") && (this.htmlElement.media.seekable.length > 0)) {
  1875. this.htmlElement.media.currentTime = percent * this.htmlElement.media.seekable.end(this.htmlElement.media.seekable.length-1) / 100;
  1876. } else if(this.htmlElement.media.duration > 0 && !isNaN(this.htmlElement.media.duration)) {
  1877. this.htmlElement.media.currentTime = percent * this.htmlElement.media.duration / 100;
  1878. } else {
  1879. throw "e";
  1880. }
  1881. } catch(err) {
  1882. this.internal.htmlDlyCmdId = setTimeout(function() {
  1883. self.playHead(percent);
  1884. }, 100);
  1885. return; // Cancel execution and wait for the delayed command.
  1886. }
  1887. if(!this.status.waitForLoad) {
  1888. this._html_checkWaitForPlay();
  1889. }
  1890. },
  1891. _html_checkWaitForPlay: function() {
  1892. if(this.status.waitForPlay) {
  1893. this.status.waitForPlay = false;
  1894. if(this.css.jq.videoPlay.length) {
  1895. this.css.jq.videoPlay.hide();
  1896. }
  1897. if(this.status.video) {
  1898. this.internal.poster.jq.hide();
  1899. this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
  1900. }
  1901. }
  1902. },
  1903. _html_volume: function(v) {
  1904. if(this.html.audio.available) {
  1905. this.htmlElement.audio.volume = v;
  1906. }
  1907. if(this.html.video.available) {
  1908. this.htmlElement.video.volume = v;
  1909. }
  1910. },
  1911. _html_mute: function(m) {
  1912. if(this.html.audio.available) {
  1913. this.htmlElement.audio.muted = m;
  1914. }
  1915. if(this.html.video.available) {
  1916. this.htmlElement.video.muted = m;
  1917. }
  1918. },
  1919. _flash_setAudio: function(media) {
  1920. var self = this;
  1921. try {
  1922. // Always finds a format due to checks in setMedia()
  1923. $.each(this.formats, function(priority, format) {
  1924. if(self.flash.support[format] && media[format]) {
  1925. switch (format) {
  1926. case "m4a" :
  1927. case "fla" :
  1928. self._getMovie().fl_setAudio_m4a(media[format]);
  1929. break;
  1930. case "mp3" :
  1931. self._getMovie().fl_setAudio_mp3(media[format]);
  1932. break;
  1933. }
  1934. self.status.src = media[format];
  1935. self.status.format[format] = true;
  1936. self.status.formatType = format;
  1937. return false;
  1938. }
  1939. });
  1940. if(this.options.preload === 'auto') {
  1941. this._flash_load();
  1942. this.status.waitForLoad = false;
  1943. }
  1944. } catch(err) { this._flashError(err); }
  1945. },
  1946. _flash_setVideo: function(media) {
  1947. var self = this;
  1948. try {
  1949. // Always finds a format due to checks in setMedia()
  1950. $.each(this.formats, function(priority, format) {
  1951. if(self.flash.support[format] && media[format]) {
  1952. switch (format) {
  1953. case "m4v" :
  1954. case "flv" :
  1955. self._getMovie().fl_setVideo_m4v(media[format]);
  1956. break;
  1957. }
  1958. self.status.src = media[format];
  1959. self.status.format[format] = true;
  1960. self.status.formatType = format;
  1961. return false;
  1962. }
  1963. });
  1964. if(this.options.preload === 'auto') {
  1965. this._flash_load();
  1966. this.status.waitForLoad = false;
  1967. }
  1968. } catch(err) { this._flashError(err); }
  1969. },
  1970. _flash_resetMedia: function() {
  1971. this.internal.flash.jq.css({'width':'0px', 'height':'0px'}); // Must do via CSS as setting attr() to zero causes a jQuery error in IE.
  1972. this._flash_pause(NaN);
  1973. },
  1974. _flash_clearMedia: function() {
  1975. try {
  1976. this._getMovie().fl_clearMedia();
  1977. } catch(err) { this._flashError(err); }
  1978. },
  1979. _flash_load: function() {
  1980. try {
  1981. this._getMovie().fl_load();
  1982. } catch(err) { this._flashError(err); }
  1983. this.status.waitForLoad = false;
  1984. },
  1985. _flash_play: function(time) {
  1986. try {
  1987. this._getMovie().fl_play(time);
  1988. } catch(err) { this._flashError(err); }
  1989. this.status.waitForLoad = false;
  1990. this._flash_checkWaitForPlay();
  1991. },
  1992. _flash_pause: function(time) {
  1993. try {
  1994. this._getMovie().fl_pause(time);
  1995. } catch(err) { this._flashError(err); }
  1996. if(time > 0) { // Avoids a setMedia() followed by stop() or pause(0) hiding the video play button.
  1997. this.status.waitForLoad = false;
  1998. this._flash_checkWaitForPlay();
  1999. }
  2000. },
  2001. _flash_playHead: function(p) {
  2002. try {
  2003. this._getMovie().fl_play_head(p);
  2004. } catch(err) { this._flashError(err); }
  2005. if(!this.status.waitForLoad) {
  2006. this._flash_checkWaitForPlay();
  2007. }
  2008. },
  2009. _flash_checkWaitForPlay: function() {
  2010. if(this.status.waitForPlay) {
  2011. this.status.waitForPlay = false;
  2012. if(this.css.jq.videoPlay.length) {
  2013. this.css.jq.videoPlay.hide();
  2014. }
  2015. if(this.status.video) {
  2016. this.internal.poster.jq.hide();
  2017. this.internal.flash.jq.css({'width': this.status.width, 'height': this.status.height});
  2018. }
  2019. }
  2020. },
  2021. _flash_volume: function(v) {
  2022. try {
  2023. this._getMovie().fl_volume(v);
  2024. } catch(err) { this._flashError(err); }
  2025. },
  2026. _flash_mute: function(m) {
  2027. try {
  2028. this._getMovie().fl_mute(m);
  2029. } catch(err) { this._flashError(err); }
  2030. },
  2031. _getMovie: function() {
  2032. return document[this.internal.flash.id];
  2033. },
  2034. _checkForFlash: function (version) {
  2035. // Function checkForFlash adapted from FlashReplace by Robert Nyman
  2036. // http://code.google.com/p/flashreplace/
  2037. var flashIsInstalled = false;
  2038. var flash;
  2039. if(window.ActiveXObject){
  2040. try{
  2041. flash = new ActiveXObject(("ShockwaveFlash.ShockwaveFlash." + version));
  2042. flashIsInstalled = true;
  2043. }
  2044. catch(e){
  2045. // Throws an error if the version isn't available
  2046. }
  2047. }
  2048. else if(navigator.plugins && navigator.mimeTypes.length > 0){
  2049. flash = navigator.plugins["Shockwave Flash"];
  2050. if(flash){
  2051. var flashVersion = navigator.plugins["Shockwave Flash"].description.replace(/.*\s(\d+\.\d+).*/, "$1");
  2052. if(flashVersion >= version){
  2053. flashIsInstalled = true;
  2054. }
  2055. }
  2056. }
  2057. return flashIsInstalled;
  2058. },
  2059. _validString: function(url) {
  2060. return (url && typeof url === "string"); // Empty strings return false
  2061. },
  2062. _limitValue: function(value, min, max) {
  2063. return (value < min) ? min : ((value > max) ? max : value);
  2064. },
  2065. _urlNotSetError: function(context) {
  2066. this._error( {
  2067. type: $.jPlayer.error.URL_NOT_SET,
  2068. context: context,
  2069. message: $.jPlayer.errorMsg.URL_NOT_SET,
  2070. hint: $.jPlayer.errorHint.URL_NOT_SET
  2071. });
  2072. },
  2073. _flashError: function(error) {
  2074. var errorType;
  2075. if(!this.internal.ready) {
  2076. errorType = "FLASH";
  2077. } else {
  2078. errorType = "FLASH_DISABLED";
  2079. }
  2080. this._error( {
  2081. type: $.jPlayer.error[errorType],
  2082. context: this.internal.flash.swf,
  2083. message: $.jPlayer.errorMsg[errorType] + error.message,
  2084. hint: $.jPlayer.errorHint[errorType]
  2085. });
  2086. // Allow the audio player to recover if display:none and then shown again, or with position:fixed on Firefox.
  2087. // This really only affects audio in a media player, as an audio player could easily move the jPlayer element away from such issues.
  2088. this.internal.flash.jq.css({'width':'1px', 'height':'1px'});
  2089. },
  2090. _error: function(error) {
  2091. this._trigger($.jPlayer.event.error, error);
  2092. if(this.options.errorAlerts) {
  2093. this._alert("Error!" + (error.message ? "\n\n" + error.message : "") + (error.hint ? "\n\n" + error.hint : "") + "\n\nContext: " + error.context);
  2094. }
  2095. },
  2096. _warning: function(warning) {
  2097. this._trigger($.jPlayer.event.warning, undefined, warning);
  2098. if(this.options.warningAlerts) {
  2099. this._alert("Warning!" + (warning.message ? "\n\n" + warning.message : "") + (warning.hint ? "\n\n" + warning.hint : "") + "\n\nContext: " + warning.context);
  2100. }
  2101. },
  2102. _alert: function(message) {
  2103. alert("jPlayer " + this.version.script + " : id='" + this.internal.self.id +"' : " + message);
  2104. },
  2105. _emulateHtmlBridge: function() {
  2106. var self = this,
  2107. methods = $.jPlayer.emulateMethods;
  2108. // Emulate methods on jPlayer's DOM element.
  2109. $.each( $.jPlayer.emulateMethods.split(/\s+/g), function(i, name) {
  2110. self.internal.domNode[name] = function(arg) {
  2111. self[name](arg);
  2112. };
  2113. });
  2114. // Bubble jPlayer events to its DOM element.
  2115. $.each($.jPlayer.event, function(eventName,eventType) {
  2116. var nativeEvent = true;
  2117. $.each( $.jPlayer.reservedEvent.split(/\s+/g), function(i, name) {
  2118. if(name === eventName) {
  2119. nativeEvent = false;
  2120. return false;
  2121. }
  2122. });
  2123. if(nativeEvent) {
  2124. self.element.bind(eventType + ".jPlayer.jPlayerHtml", function() { // With .jPlayer & .jPlayerHtml namespaces.
  2125. self._emulateHtmlUpdate();
  2126. var domEvent = document.createEvent("Event");
  2127. domEvent.initEvent(eventName, false, true);
  2128. self.internal.domNode.dispatchEvent(domEvent);
  2129. });
  2130. }
  2131. // The error event would require a special case
  2132. });
  2133. // IE9 has a readyState property on all elements. The document should have it, but all (except media) elements inherit it in IE9. This conflicts with Popcorn, which polls the readyState.
  2134. },
  2135. _emulateHtmlUpdate: function() {
  2136. var self = this;
  2137. $.each( $.jPlayer.emulateStatus.split(/\s+/g), function(i, name) {
  2138. self.internal.domNode[name] = self.status[name];
  2139. });
  2140. $.each( $.jPlayer.emulateOptions.split(/\s+/g), function(i, name) {
  2141. self.internal.domNode[name] = self.options[name];
  2142. });
  2143. },
  2144. _destroyHtmlBridge: function() {
  2145. var self = this;
  2146. // Bridge event handlers are also removed by destroy() through .jPlayer namespace.
  2147. this.element.unbind(".jPlayerHtml"); // Remove all event handlers created by the jPlayer bridge. So you can change the emulateHtml option.
  2148. // Remove the methods and properties
  2149. var emulated = $.jPlayer.emulateMethods + " " + $.jPlayer.emulateStatus + " " + $.jPlayer.emulateOptions;
  2150. $.each( emulated.split(/\s+/g), function(i, name) {
  2151. delete self.internal.domNode[name];
  2152. });
  2153. }
  2154. };
  2155. $.jPlayer.error = {
  2156. FLASH: "e_flash",
  2157. FLASH_DISABLED: "e_flash_disabled",
  2158. NO_SOLUTION: "e_no_solution",
  2159. NO_SUPPORT: "e_no_support",
  2160. URL: "e_url",
  2161. URL_NOT_SET: "e_url_not_set",
  2162. VERSION: "e_version"
  2163. };
  2164. $.jPlayer.errorMsg = {
  2165. FLASH: "jPlayer's Flash fallback is not configured correctly, or a command was issued before the jPlayer Ready event. Details: ", // Used in: _flashError()
  2166. FLASH_DISABLED: "jPlayer's Flash fallback has been disabled by the browser due to the CSS rules you have used. Details: ", // Used in: _flashError()
  2167. NO_SOLUTION: "No solution can be found by jPlayer in this browser. Neither HTML nor Flash can be used.", // Used in: _init()
  2168. NO_SUPPORT: "It is not possible to play any media format provided in setMedia() on this browser using your current options.", // Used in: setMedia()
  2169. URL: "Media URL could not be loaded.", // Used in: jPlayerFlashEvent() and _addHtmlEventListeners()
  2170. URL_NOT_SET: "Attempt to issue media playback commands, while no media url is set.", // Used in: load(), play(), pause(), stop() and playHead()
  2171. VERSION: "jPlayer " + $.jPlayer.prototype.version.script + " needs Jplayer.swf version " + $.jPlayer.prototype.version.needFlash + " but found " // Used in: jPlayerReady()
  2172. };
  2173. $.jPlayer.errorHint = {
  2174. FLASH: "Check your swfPath option and that Jplayer.swf is there.",
  2175. FLASH_DISABLED: "Check that you have not display:none; the jPlayer entity or any ancestor.",
  2176. NO_SOLUTION: "Review the jPlayer options: support and supplied.",
  2177. NO_SUPPORT: "Video or audio formats defined in the supplied option are missing.",
  2178. URL: "Check media URL is valid.",
  2179. URL_NOT_SET: "Use setMedia() to set the media URL.",
  2180. VERSION: "Update jPlayer files."
  2181. };
  2182. $.jPlayer.warning = {
  2183. CSS_SELECTOR_COUNT: "e_css_selector_count",
  2184. CSS_SELECTOR_METHOD: "e_css_selector_method",
  2185. CSS_SELECTOR_STRING: "e_css_selector_string",
  2186. OPTION_KEY: "e_option_key"
  2187. };
  2188. $.jPlayer.warningMsg = {
  2189. CSS_SELECTOR_COUNT: "The number of css selectors found did not equal one: ",
  2190. CSS_SELECTOR_METHOD: "The methodName given in jPlayer('cssSelector') is not a valid jPlayer method.",
  2191. CSS_SELECTOR_STRING: "The methodCssSelector given in jPlayer('cssSelector') is not a String or is empty.",
  2192. OPTION_KEY: "The option requested in jPlayer('option') is undefined."
  2193. };
  2194. $.jPlayer.warningHint = {
  2195. CSS_SELECTOR_COUNT: "Check your css selector and the ancestor.",
  2196. CSS_SELECTOR_METHOD: "Check your method name.",
  2197. CSS_SELECTOR_STRING: "Check your css selector is a string.",
  2198. OPTION_KEY: "Check your option name."
  2199. };
  2200. })(jQuery);