252 | var listItem = "
";
253 |
254 | // Create remove control
255 | listItem += "
×";
256 |
257 | // Create links to free media
258 | if(media.free) {
259 | console.log(media);
260 | var first = true;
261 | listItem += "
(";
262 | $.each(media, function(property,value) {
263 | if($.jPlayer.prototype.format[property]) { // Check property is a media format.
264 | if(first) {
265 | first = false;
266 | } else {
267 | listItem += " | ";
268 | }
269 | listItem += "" + property + "";
270 | }
271 | });
272 | listItem += ")";
273 | }
274 |
275 | // The title is given next in the HTML otherwise the float:right on the free media corrupts in IE6/7
276 | listItem += "
" + media.title + (media.artist ? " by " + media.artist + "" : "") + (media.duration ? "" + media.duration + "":"") + "";
277 | listItem += "
";
278 |
279 | return listItem;
280 | },
281 | _createItemHandlers: function() {
282 | var self = this;
283 | // Create live handlers for the playlist items
284 | $(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.itemClass).on("click", "a." + this.options.playlistOptions.itemClass, function(e) {
285 | e.preventDefault();
286 | var index = $(this).parent().parent().index();
287 | if(self.current !== index) {
288 | self.play(index);
289 | } else {
290 | $(self.cssSelector.jPlayer).jPlayer("play");
291 | }
292 | self.blur(this);
293 | });
294 |
295 | // Create live handlers that disable free media links to force access via right click
296 | $(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.freeItemClass).on("click", "a." + this.options.playlistOptions.freeItemClass, function(e) {
297 | e.preventDefault();
298 | $(this).parent().parent().find("." + self.options.playlistOptions.itemClass).click();
299 | self.blur(this);
300 | });
301 |
302 | // Create live handlers for the remove controls
303 | $(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.removeItemClass).on("click", "a." + this.options.playlistOptions.removeItemClass, function(e) {
304 | e.preventDefault();
305 | var index = $(this).parent().parent().index();
306 | self.remove(index);
307 | self.blur(this);
308 | });
309 | },
310 | _updateControls: function() {
311 | if(this.options.playlistOptions.enableRemoveControls) {
312 | $(this.cssSelector.playlist + " ." + this.options.playlistOptions.removeItemClass).show();
313 | } else {
314 | $(this.cssSelector.playlist + " ." + this.options.playlistOptions.removeItemClass).hide();
315 | }
316 | if(this.shuffled) {
317 | $(this.cssSelector.jPlayer).jPlayer("addStateClass", "shuffled");
318 | } else {
319 | $(this.cssSelector.jPlayer).jPlayer("removeStateClass", "shuffled");
320 | }
321 | if($(this.cssSelector.shuffle).length && $(this.cssSelector.shuffleOff).length) {
322 | if(this.shuffled) {
323 | $(this.cssSelector.shuffleOff).show();
324 | $(this.cssSelector.shuffle).hide();
325 | } else {
326 | $(this.cssSelector.shuffleOff).hide();
327 | $(this.cssSelector.shuffle).show();
328 | }
329 | }
330 | },
331 | _highlight: function(index) {
332 | if(this.playlist.length && index !== undefined) {
333 | $(this.cssSelector.playlist + " .jp-playlist-current").removeClass("jp-playlist-current");
334 | $(this.cssSelector.playlist + " li:nth-child(" + (index + 1) + ")").addClass("jp-playlist-current").find(".jp-playlist-item").addClass("jp-playlist-current");
335 | //$(this.cssSelector.details + " li").html("
" + this.playlist[index].title + "" + (this.playlist[index].artist ? "
by " + this.playlist[index].artist + "" : "") + (this.playlist[index].duration ? "
" + this.playlist[index].duration + "" : ""));
336 | }
337 | },
338 | setPlaylist: function(playlist) {
339 | this._initPlaylist(playlist);
340 | this._init();
341 | },
342 | add: function(media, playNow) {
343 | $(this.cssSelector.playlist + " ul").append(this._createListItem(media)).find("li:last-child").hide().slideDown(this.options.playlistOptions.addTime);
344 | this._updateControls();
345 | this.original.push(media);
346 | this.playlist.push(media); // Both array elements share the same object pointer. Comforms with _initPlaylist(p) system.
347 |
348 | if(playNow) {
349 | this.play(this.playlist.length - 1);
350 | } else {
351 | if(this.original.length === 1) {
352 | this.select(0);
353 | }
354 | }
355 | },
356 | remove: function(index) {
357 | var self = this;
358 |
359 | if(index === undefined) {
360 | this._initPlaylist([]);
361 | this._refresh(function() {
362 | $(self.cssSelector.jPlayer).jPlayer("clearMedia");
363 | });
364 | return true;
365 | } else {
366 |
367 | if(this.removing) {
368 | return false;
369 | } else {
370 | index = (index < 0) ? self.original.length + index : index; // Negative index relates to end of array.
371 | if(0 <= index && index < this.playlist.length) {
372 | this.removing = true;
373 |
374 | $(this.cssSelector.playlist + " li:nth-child(" + (index + 1) + ")").slideUp(this.options.playlistOptions.removeTime, function() {
375 | $(this).remove();
376 |
377 | if(self.shuffled) {
378 | var item = self.playlist[index];
379 | $.each(self.original, function(i) {
380 | if(self.original[i] === item) {
381 | self.original.splice(i, 1);
382 | return false; // Exit $.each
383 | }
384 | });
385 | self.playlist.splice(index, 1);
386 | } else {
387 | self.original.splice(index, 1);
388 | self.playlist.splice(index, 1);
389 | }
390 |
391 | if(self.original.length) {
392 | if(index === self.current) {
393 | self.current = (index < self.original.length) ? self.current : self.original.length - 1; // To cope when last element being selected when it was removed
394 | self.select(self.current);
395 | } else if(index < self.current) {
396 | self.current--;
397 | }
398 | } else {
399 | $(self.cssSelector.jPlayer).jPlayer("clearMedia");
400 | self.current = 0;
401 | self.shuffled = false;
402 | self._updateControls();
403 | }
404 |
405 | self.removing = false;
406 | });
407 | }
408 | return true;
409 | }
410 | }
411 | },
412 | select: function(index) {
413 | index = (index < 0) ? this.original.length + index : index; // Negative index relates to end of array.
414 | if(0 <= index && index < this.playlist.length) {
415 | this.current = index;
416 | this._highlight(index);
417 | $(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
418 | } else {
419 | this.current = 0;
420 | }
421 | },
422 | play: function(index) {
423 | index = (index < 0) ? this.original.length + index : index; // Negative index relates to end of array.
424 | if(0 <= index && index < this.playlist.length) {
425 | if(this.playlist.length) {
426 | this.select(index);
427 | $(this.cssSelector.jPlayer).jPlayer("play");
428 | }
429 | } else if(index === undefined) {
430 | $(this.cssSelector.jPlayer).jPlayer("play");
431 | }
432 | },
433 | pause: function() {
434 | $(this.cssSelector.jPlayer).jPlayer("pause");
435 | },
436 | next: function() {
437 | var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
438 |
439 | if(this.loop) {
440 | // See if we need to shuffle before looping to start, and only shuffle if more than 1 item.
441 | if(index === 0 && this.shuffled && this.options.playlistOptions.shuffleOnLoop && this.playlist.length > 1) {
442 | this.shuffle(true, true); // playNow
443 | } else {
444 | this.play(index);
445 | }
446 | } else {
447 | // The index will be zero if it just looped round
448 | if(index > 0) {
449 | this.play(index);
450 | }
451 | }
452 | },
453 | previous: function() {
454 | var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
455 |
456 | if(this.loop && this.options.playlistOptions.loopOnPrevious || index < this.playlist.length - 1) {
457 | this.play(index);
458 | }
459 | },
460 | shuffle: function(shuffled, playNow) {
461 | var self = this;
462 |
463 | if(shuffled === undefined) {
464 | shuffled = !this.shuffled;
465 | }
466 |
467 | if(shuffled || shuffled !== this.shuffled) {
468 |
469 | $(this.cssSelector.playlist + " ul").slideUp(this.options.playlistOptions.shuffleTime, function() {
470 | self.shuffled = shuffled;
471 | if(shuffled) {
472 | self.playlist.sort(function() {
473 | return 0.5 - Math.random();
474 | });
475 | } else {
476 | self._originalPlaylist();
477 | }
478 | self._refresh(true); // Instant
479 |
480 | if(playNow || !$(self.cssSelector.jPlayer).data("jPlayer").status.paused) {
481 | self.play(0);
482 | } else {
483 | self.select(0);
484 | }
485 |
486 | $(this).slideDown(self.options.playlistOptions.shuffleTime);
487 | });
488 | }
489 | },
490 | blur: function(that) {
491 | if($(this.cssSelector.jPlayer).jPlayer("option", "autoBlur")) {
492 | $(that).blur();
493 | }
494 | }
495 | };
496 | })(jQuery);
--------------------------------------------------------------------------------
/src/js/shims/modernizr.custom.js:
--------------------------------------------------------------------------------
1 | /* Modernizr 2.8.3 (Custom Build) | MIT & BSD
2 | * Build: http://modernizr.com/download/#-csstransforms-csstransforms3d-csstransitions-shiv-cssclasses-teststyles-testprop-testallprops-prefixes-domprefixes-load
3 | */
4 | ;
5 |
6 |
7 |
8 | window.Modernizr = (function( window, document, undefined ) {
9 |
10 | var version = '2.8.3',
11 |
12 | Modernizr = {},
13 |
14 | enableClasses = true,
15 |
16 | docElement = document.documentElement,
17 |
18 | mod = 'modernizr',
19 | modElem = document.createElement(mod),
20 | mStyle = modElem.style,
21 |
22 | inputElem ,
23 |
24 |
25 | toString = {}.toString,
26 |
27 | prefixes = ' -webkit- -moz- -o- -ms- '.split(' '),
28 |
29 |
30 |
31 | omPrefixes = 'Webkit Moz O ms',
32 |
33 | cssomPrefixes = omPrefixes.split(' '),
34 |
35 | domPrefixes = omPrefixes.toLowerCase().split(' '),
36 |
37 |
38 | tests = {},
39 | inputs = {},
40 | attrs = {},
41 |
42 | classes = [],
43 |
44 | slice = classes.slice,
45 |
46 | featureName,
47 |
48 |
49 | injectElementWithStyles = function( rule, callback, nodes, testnames ) {
50 |
51 | var style, ret, node, docOverflow,
52 | div = document.createElement('div'),
53 | body = document.body,
54 | fakeBody = body || document.createElement('body');
55 |
56 | if ( parseInt(nodes, 10) ) {
57 | while ( nodes-- ) {
58 | node = document.createElement('div');
59 | node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
60 | div.appendChild(node);
61 | }
62 | }
63 |
64 | style = ['',''].join('');
65 | div.id = mod;
66 | (body ? div : fakeBody).innerHTML += style;
67 | fakeBody.appendChild(div);
68 | if ( !body ) {
69 | fakeBody.style.background = '';
70 | fakeBody.style.overflow = 'hidden';
71 | docOverflow = docElement.style.overflow;
72 | docElement.style.overflow = 'hidden';
73 | docElement.appendChild(fakeBody);
74 | }
75 |
76 | ret = callback(div, rule);
77 | if ( !body ) {
78 | fakeBody.parentNode.removeChild(fakeBody);
79 | docElement.style.overflow = docOverflow;
80 | } else {
81 | div.parentNode.removeChild(div);
82 | }
83 |
84 | return !!ret;
85 |
86 | },
87 | _hasOwnProperty = ({}).hasOwnProperty, hasOwnProp;
88 |
89 | if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) {
90 | hasOwnProp = function (object, property) {
91 | return _hasOwnProperty.call(object, property);
92 | };
93 | }
94 | else {
95 | hasOwnProp = function (object, property) {
96 | return ((property in object) && is(object.constructor.prototype[property], 'undefined'));
97 | };
98 | }
99 |
100 |
101 | if (!Function.prototype.bind) {
102 | Function.prototype.bind = function bind(that) {
103 |
104 | var target = this;
105 |
106 | if (typeof target != "function") {
107 | throw new TypeError();
108 | }
109 |
110 | var args = slice.call(arguments, 1),
111 | bound = function () {
112 |
113 | if (this instanceof bound) {
114 |
115 | var F = function(){};
116 | F.prototype = target.prototype;
117 | var self = new F();
118 |
119 | var result = target.apply(
120 | self,
121 | args.concat(slice.call(arguments))
122 | );
123 | if (Object(result) === result) {
124 | return result;
125 | }
126 | return self;
127 |
128 | } else {
129 |
130 | return target.apply(
131 | that,
132 | args.concat(slice.call(arguments))
133 | );
134 |
135 | }
136 |
137 | };
138 |
139 | return bound;
140 | };
141 | }
142 |
143 | function setCss( str ) {
144 | mStyle.cssText = str;
145 | }
146 |
147 | function setCssAll( str1, str2 ) {
148 | return setCss(prefixes.join(str1 + ';') + ( str2 || '' ));
149 | }
150 |
151 | function is( obj, type ) {
152 | return typeof obj === type;
153 | }
154 |
155 | function contains( str, substr ) {
156 | return !!~('' + str).indexOf(substr);
157 | }
158 |
159 | function testProps( props, prefixed ) {
160 | for ( var i in props ) {
161 | var prop = props[i];
162 | if ( !contains(prop, "-") && mStyle[prop] !== undefined ) {
163 | return prefixed == 'pfx' ? prop : true;
164 | }
165 | }
166 | return false;
167 | }
168 |
169 | function testDOMProps( props, obj, elem ) {
170 | for ( var i in props ) {
171 | var item = obj[props[i]];
172 | if ( item !== undefined) {
173 |
174 | if (elem === false) return props[i];
175 |
176 | if (is(item, 'function')){
177 | return item.bind(elem || obj);
178 | }
179 |
180 | return item;
181 | }
182 | }
183 | return false;
184 | }
185 |
186 | function testPropsAll( prop, prefixed, elem ) {
187 |
188 | var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1),
189 | props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' ');
190 |
191 | if(is(prefixed, "string") || is(prefixed, "undefined")) {
192 | return testProps(props, prefixed);
193 |
194 | } else {
195 | props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' ');
196 | return testDOMProps(props, prefixed, elem);
197 | }
198 | }
199 |
200 |
201 | tests['csstransforms'] = function() {
202 | return !!testPropsAll('transform');
203 | };
204 |
205 |
206 | tests['csstransforms3d'] = function() {
207 |
208 | var ret = !!testPropsAll('perspective');
209 |
210 | if ( ret && 'webkitPerspective' in docElement.style ) {
211 |
212 | injectElementWithStyles('@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}', function( node, rule ) {
213 | ret = node.offsetLeft === 9 && node.offsetHeight === 3;
214 | });
215 | }
216 | return ret;
217 | };
218 |
219 |
220 | tests['csstransitions'] = function() {
221 | return testPropsAll('transition');
222 | };
223 |
224 |
225 |
226 | for ( var feature in tests ) {
227 | if ( hasOwnProp(tests, feature) ) {
228 | featureName = feature.toLowerCase();
229 | Modernizr[featureName] = tests[feature]();
230 |
231 | classes.push((Modernizr[featureName] ? '' : 'no-') + featureName);
232 | }
233 | }
234 |
235 |
236 |
237 | Modernizr.addTest = function ( feature, test ) {
238 | if ( typeof feature == 'object' ) {
239 | for ( var key in feature ) {
240 | if ( hasOwnProp( feature, key ) ) {
241 | Modernizr.addTest( key, feature[ key ] );
242 | }
243 | }
244 | } else {
245 |
246 | feature = feature.toLowerCase();
247 |
248 | if ( Modernizr[feature] !== undefined ) {
249 | return Modernizr;
250 | }
251 |
252 | test = typeof test == 'function' ? test() : test;
253 |
254 | if (typeof enableClasses !== "undefined" && enableClasses) {
255 | docElement.className += ' ' + (test ? '' : 'no-') + feature;
256 | }
257 | Modernizr[feature] = test;
258 |
259 | }
260 |
261 | return Modernizr;
262 | };
263 |
264 |
265 | setCss('');
266 | modElem = inputElem = null;
267 |
268 | ;(function(window, document) {
269 | var version = '3.7.0';
270 |
271 | var options = window.html5 || {};
272 |
273 | var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i;
274 |
275 | var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i;
276 |
277 | var supportsHtml5Styles;
278 |
279 | var expando = '_html5shiv';
280 |
281 | var expanID = 0;
282 |
283 | var expandoData = {};
284 |
285 | var supportsUnknownElements;
286 |
287 | (function() {
288 | try {
289 | var a = document.createElement('a');
290 | a.innerHTML = '
';
291 | supportsHtml5Styles = ('hidden' in a);
292 |
293 | supportsUnknownElements = a.childNodes.length == 1 || (function() {
294 | (document.createElement)('a');
295 | var frag = document.createDocumentFragment();
296 | return (
297 | typeof frag.cloneNode == 'undefined' ||
298 | typeof frag.createDocumentFragment == 'undefined' ||
299 | typeof frag.createElement == 'undefined'
300 | );
301 | }());
302 | } catch(e) {
303 | supportsHtml5Styles = true;
304 | supportsUnknownElements = true;
305 | }
306 |
307 | }());
308 |
309 | function addStyleSheet(ownerDocument, cssText) {
310 | var p = ownerDocument.createElement('p'),
311 | parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
312 |
313 | p.innerHTML = 'x';
314 | return parent.insertBefore(p.lastChild, parent.firstChild);
315 | }
316 |
317 | function getElements() {
318 | var elements = html5.elements;
319 | return typeof elements == 'string' ? elements.split(' ') : elements;
320 | }
321 |
322 | function getExpandoData(ownerDocument) {
323 | var data = expandoData[ownerDocument[expando]];
324 | if (!data) {
325 | data = {};
326 | expanID++;
327 | ownerDocument[expando] = expanID;
328 | expandoData[expanID] = data;
329 | }
330 | return data;
331 | }
332 |
333 | function createElement(nodeName, ownerDocument, data){
334 | if (!ownerDocument) {
335 | ownerDocument = document;
336 | }
337 | if(supportsUnknownElements){
338 | return ownerDocument.createElement(nodeName);
339 | }
340 | if (!data) {
341 | data = getExpandoData(ownerDocument);
342 | }
343 | var node;
344 |
345 | if (data.cache[nodeName]) {
346 | node = data.cache[nodeName].cloneNode();
347 | } else if (saveClones.test(nodeName)) {
348 | node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode();
349 | } else {
350 | node = data.createElem(nodeName);
351 | }
352 |
353 | return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node;
354 | }
355 |
356 | function createDocumentFragment(ownerDocument, data){
357 | if (!ownerDocument) {
358 | ownerDocument = document;
359 | }
360 | if(supportsUnknownElements){
361 | return ownerDocument.createDocumentFragment();
362 | }
363 | data = data || getExpandoData(ownerDocument);
364 | var clone = data.frag.cloneNode(),
365 | i = 0,
366 | elems = getElements(),
367 | l = elems.length;
368 | for(;i
-1);
1029 | self.flash.canPlay[format] = self.format[format].flashCanPlay && self.flash.available;
1030 | });
1031 | this.html.desired = false;
1032 | this.aurora.desired = false;
1033 | this.flash.desired = false;
1034 | $.each(this.solutions, function(solutionPriority, solution) {
1035 | if(solutionPriority === 0) {
1036 | self[solution].desired = true;
1037 | } else {
1038 | var audioCanPlay = false;
1039 | var videoCanPlay = false;
1040 | $.each(self.formats, function(formatPriority, format) {
1041 | if(self[self.solutions[0]].canPlay[format]) { // The other solution can play
1042 | if(self.format[format].media === 'video') {
1043 | videoCanPlay = true;
1044 | } else {
1045 | audioCanPlay = true;
1046 | }
1047 | }
1048 | });
1049 | self[solution].desired = (self.require.audio && !audioCanPlay) || (self.require.video && !videoCanPlay);
1050 | }
1051 | });
1052 | // This is what jPlayer will support, based on solution and supplied.
1053 | this.html.support = {};
1054 | this.aurora.support = {};
1055 | this.flash.support = {};
1056 | $.each(this.formats, function(priority, format) {
1057 | self.html.support[format] = self.html.canPlay[format] && self.html.desired;
1058 | self.aurora.support[format] = self.aurora.canPlay[format] && self.aurora.desired;
1059 | self.flash.support[format] = self.flash.canPlay[format] && self.flash.desired;
1060 | });
1061 | // If jPlayer is supporting any format in a solution, then the solution is used.
1062 | this.html.used = false;
1063 | this.aurora.used = false;
1064 | this.flash.used = false;
1065 | $.each(this.solutions, function(solutionPriority, solution) {
1066 | $.each(self.formats, function(formatPriority, format) {
1067 | if(self[solution].support[format]) {
1068 | self[solution].used = true;
1069 | return false;
1070 | }
1071 | });
1072 | });
1073 |
1074 | // Init solution active state and the event gates to false.
1075 | this._resetActive();
1076 | this._resetGate();
1077 |
1078 | // Set up the css selectors for the control and feedback entities.
1079 | this._cssSelectorAncestor(this.options.cssSelectorAncestor);
1080 |
1081 | // If neither html nor aurora nor flash are being used by this browser, then media playback is not possible. Trigger an error event.
1082 | if(!(this.html.used || this.aurora.used || this.flash.used)) {
1083 | this._error( {
1084 | type: $.jPlayer.error.NO_SOLUTION,
1085 | context: "{solution:'" + this.options.solution + "', supplied:'" + this.options.supplied + "'}",
1086 | message: $.jPlayer.errorMsg.NO_SOLUTION,
1087 | hint: $.jPlayer.errorHint.NO_SOLUTION
1088 | });
1089 | if(this.css.jq.noSolution.length) {
1090 | this.css.jq.noSolution.show();
1091 | }
1092 | } else {
1093 | if(this.css.jq.noSolution.length) {
1094 | this.css.jq.noSolution.hide();
1095 | }
1096 | }
1097 |
1098 | // Add the flash solution if it is being used.
1099 | if(this.flash.used) {
1100 | var htmlObj,
1101 | flashVars = 'jQuery=' + encodeURI(this.options.noConflict) + '&id=' + encodeURI(this.internal.self.id) + '&vol=' + this.options.volume + '&muted=' + this.options.muted;
1102 |
1103 | // Code influenced by SWFObject 2.2: http://code.google.com/p/swfobject/
1104 | // Non IE browsers have an initial Flash size of 1 by 1 otherwise the wmode affected the Flash ready event.
1105 |
1106 | if($.jPlayer.browser.msie && (Number($.jPlayer.browser.version) < 9 || $.jPlayer.browser.documentMode < 9)) {
1107 | var objStr = '';
1108 |
1109 | var paramStr = [
1110 | '',
1111 | '',
1112 | '',
1113 | '',
1114 | ''
1115 | ];
1116 |
1117 | htmlObj = document.createElement(objStr);
1118 | for(var i=0; i < paramStr.length; i++) {
1119 | htmlObj.appendChild(document.createElement(paramStr[i]));
1120 | }
1121 | } else {
1122 | var createParam = function(el, n, v) {
1123 | var p = document.createElement("param");
1124 | p.setAttribute("name", n);
1125 | p.setAttribute("value", v);
1126 | el.appendChild(p);
1127 | };
1128 |
1129 | htmlObj = document.createElement("object");
1130 | htmlObj.setAttribute("id", this.internal.flash.id);
1131 | htmlObj.setAttribute("name", this.internal.flash.id);
1132 | htmlObj.setAttribute("data", this.internal.flash.swf);
1133 | htmlObj.setAttribute("type", "application/x-shockwave-flash");
1134 | htmlObj.setAttribute("width", "1"); // Non-zero
1135 | htmlObj.setAttribute("height", "1"); // Non-zero
1136 | htmlObj.setAttribute("tabindex", "-1");
1137 | createParam(htmlObj, "flashvars", flashVars);
1138 | createParam(htmlObj, "allowscriptaccess", "always");
1139 | createParam(htmlObj, "bgcolor", this.options.backgroundColor);
1140 | createParam(htmlObj, "wmode", this.options.wmode);
1141 | }
1142 |
1143 | this.element.append(htmlObj);
1144 | this.internal.flash.jq = $(htmlObj);
1145 | }
1146 |
1147 | // Setup playbackRate ability before using _addHtmlEventListeners()
1148 | if(this.html.used && !this.flash.used) { // If only HTML
1149 | // Using the audio element capabilities for playbackRate. ie., Assuming video element is the same.
1150 | this.status.playbackRateEnabled = this._testPlaybackRate('audio');
1151 | } else {
1152 | this.status.playbackRateEnabled = false;
1153 | }
1154 |
1155 | this._updatePlaybackRate();
1156 |
1157 | // Add the HTML solution if being used.
1158 | if(this.html.used) {
1159 |
1160 | // The HTML Audio handlers
1161 | if(this.html.audio.available) {
1162 | this._addHtmlEventListeners(this.htmlElement.audio, this.html.audio);
1163 | this.element.append(this.htmlElement.audio);
1164 | this.internal.audio.jq = $("#" + this.internal.audio.id);
1165 | }
1166 |
1167 | // The HTML Video handlers
1168 | if(this.html.video.available) {
1169 | this._addHtmlEventListeners(this.htmlElement.video, this.html.video);
1170 | this.element.append(this.htmlElement.video);
1171 | this.internal.video.jq = $("#" + this.internal.video.id);
1172 | if(this.status.nativeVideoControls) {
1173 | this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
1174 | } else {
1175 | this.internal.video.jq.css({'width':'0px', 'height':'0px'}); // Using size 0x0 since a .hide() causes issues in iOS
1176 | }
1177 | this.internal.video.jq.bind("click.jPlayer", function() {
1178 | self._trigger($.jPlayer.event.click);
1179 | });
1180 | }
1181 | }
1182 |
1183 | // Add the Aurora.js solution if being used.
1184 | if(this.aurora.used) {
1185 | // Aurora.js player need to be created for each media, see setMedia function.
1186 | }
1187 |
1188 | // Create the bridge that emulates the HTML Media element on the jPlayer DIV
1189 | if( this.options.emulateHtml ) {
1190 | this._emulateHtmlBridge();
1191 | }
1192 |
1193 | if((this.html.used || this.aurora.used) && !this.flash.used) { // If only HTML, then emulate flash ready() call after 100ms.
1194 | setTimeout( function() {
1195 | self.internal.ready = true;
1196 | self.version.flash = "n/a";
1197 | self._trigger($.jPlayer.event.repeat); // Trigger the repeat event so its handler can initialize itself with the loop option.
1198 | self._trigger($.jPlayer.event.ready);
1199 | }, 100);
1200 | }
1201 |
1202 | // Initialize the interface components with the options.
1203 | this._updateNativeVideoControls();
1204 | // The other controls are now setup in _cssSelectorAncestor()
1205 | if(this.css.jq.videoPlay.length) {
1206 | this.css.jq.videoPlay.hide();
1207 | }
1208 |
1209 | $.jPlayer.prototype.count++; // Change static variable via prototype.
1210 | },
1211 | destroy: function() {
1212 | // MJP: The background change remains. Would need to store the original to restore it correctly.
1213 | // MJP: The jPlayer element's size change remains.
1214 |
1215 | // Clear the media to reset the GUI and stop any downloads. Streams on some browsers had persited. (Chrome)
1216 | this.clearMedia();
1217 | // Remove the size/sizeFull cssClass from the cssSelectorAncestor
1218 | this._removeUiClass();
1219 | // Remove the times from the GUI
1220 | if(this.css.jq.currentTime.length) {
1221 | this.css.jq.currentTime.text("");
1222 | }
1223 | if(this.css.jq.duration.length) {
1224 | this.css.jq.duration.text("");
1225 | }
1226 | // Remove any bindings from the interface controls.
1227 | $.each(this.css.jq, function(fn, jq) {
1228 | // Check selector is valid before trying to execute method.
1229 | if(jq.length) {
1230 | jq.unbind(".jPlayer");
1231 | }
1232 | });
1233 | // Remove the click handlers for $.jPlayer.event.click
1234 | this.internal.poster.jq.unbind(".jPlayer");
1235 | if(this.internal.video.jq) {
1236 | this.internal.video.jq.unbind(".jPlayer");
1237 | }
1238 | // Remove the fullscreen event handlers
1239 | this._fullscreenRemoveEventListeners();
1240 | // Remove key bindings
1241 | if(this === $.jPlayer.focus) {
1242 | $.jPlayer.focus = null;
1243 | }
1244 | // Destroy the HTML bridge.
1245 | if(this.options.emulateHtml) {
1246 | this._destroyHtmlBridge();
1247 | }
1248 | this.element.removeData("jPlayer"); // Remove jPlayer data
1249 | this.element.unbind(".jPlayer"); // Remove all event handlers created by the jPlayer constructor
1250 | this.element.empty(); // Remove the inserted child elements
1251 |
1252 | delete this.instances[this.internal.instance]; // Clear the instance on the static instance object
1253 | },
1254 | destroyRemoved: function() { // Destroy any instances that have gone away.
1255 | var self = this;
1256 | $.each(this.instances, function(i, element) {
1257 | if(self.element !== element) { // Do not destroy this instance.
1258 | if(!element.data("jPlayer")) { // Check that element is a real jPlayer.
1259 | element.jPlayer("destroy");
1260 | delete self.instances[i];
1261 | }
1262 | }
1263 | });
1264 | },
1265 | enable: function() { // Plan to implement
1266 | // options.disabled = false
1267 | },
1268 | disable: function () { // Plan to implement
1269 | // options.disabled = true
1270 | },
1271 | _testCanPlayType: function(elem) {
1272 | // IE9 on Win Server 2008 did not implement canPlayType(), but it has the property.
1273 | try {
1274 | elem.canPlayType(this.format.mp3.codec); // The type is irrelevant.
1275 | return true;
1276 | } catch(err) {
1277 | return false;
1278 | }
1279 | },
1280 | _testPlaybackRate: function(type) {
1281 | // type: String 'audio' or 'video'
1282 | var el, rate = 0.5;
1283 | type = typeof type === 'string' ? type : 'audio';
1284 | el = document.createElement(type);
1285 | // Wrapping in a try/catch, just in case older HTML5 browsers throw and error.
1286 | try {
1287 | if('playbackRate' in el) {
1288 | el.playbackRate = rate;
1289 | return el.playbackRate === rate;
1290 | } else {
1291 | return false;
1292 | }
1293 | } catch(err) {
1294 | return false;
1295 | }
1296 | },
1297 | _uaBlocklist: function(list) {
1298 | // list : object with properties that are all regular expressions. Property names are irrelevant.
1299 | // Returns true if the user agent is matched in list.
1300 | var ua = navigator.userAgent.toLowerCase(),
1301 | block = false;
1302 |
1303 | $.each(list, function(p, re) {
1304 | if(re && re.test(ua)) {
1305 | block = true;
1306 | return false; // exit $.each.
1307 | }
1308 | });
1309 | return block;
1310 | },
1311 | _restrictNativeVideoControls: function() {
1312 | // Fallback to noFullWindow when nativeVideoControls is true and audio media is being used. Affects when both media types are used.
1313 | if(this.require.audio) {
1314 | if(this.status.nativeVideoControls) {
1315 | this.status.nativeVideoControls = false;
1316 | this.status.noFullWindow = true;
1317 | }
1318 | }
1319 | },
1320 | _updateNativeVideoControls: function() {
1321 | if(this.html.video.available && this.html.used) {
1322 | // Turn the HTML Video controls on/off
1323 | this.htmlElement.video.controls = this.status.nativeVideoControls;
1324 | // Show/hide the jPlayer GUI.
1325 | this._updateAutohide();
1326 | // 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.
1327 | if(this.status.nativeVideoControls && this.require.video) {
1328 | this.internal.poster.jq.hide();
1329 | this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
1330 | } else if(this.status.waitForPlay && this.status.video) {
1331 | this.internal.poster.jq.show();
1332 | this.internal.video.jq.css({'width': '0px', 'height': '0px'});
1333 | }
1334 | }
1335 | },
1336 | _addHtmlEventListeners: function(mediaElement, entity) {
1337 | var self = this;
1338 | mediaElement.preload = this.options.preload;
1339 | mediaElement.muted = this.options.muted;
1340 | mediaElement.volume = this.options.volume;
1341 |
1342 | if(this.status.playbackRateEnabled) {
1343 | mediaElement.defaultPlaybackRate = this.options.defaultPlaybackRate;
1344 | mediaElement.playbackRate = this.options.playbackRate;
1345 | }
1346 |
1347 | // Create the event listeners
1348 | // Only want the active entity to affect jPlayer and bubble events.
1349 | // Using entity.gate so that object is referenced and gate property always current
1350 |
1351 | mediaElement.addEventListener("progress", function() {
1352 | if(entity.gate) {
1353 | if(self.internal.cmdsIgnored && this.readyState > 0) { // Detect iOS executed the command
1354 | self.internal.cmdsIgnored = false;
1355 | }
1356 | self._getHtmlStatus(mediaElement);
1357 | self._updateInterface();
1358 | self._trigger($.jPlayer.event.progress);
1359 | }
1360 | }, false);
1361 | mediaElement.addEventListener("loadeddata", function() {
1362 | if(entity.gate) {
1363 | self.androidFix.setMedia = false; // Disable the fix after the first progress event.
1364 | if(self.androidFix.play) { // Play Android audio - performing the fix.
1365 | self.androidFix.play = false;
1366 | self.play(self.androidFix.time);
1367 | }
1368 | if(self.androidFix.pause) { // Pause Android audio at time - performing the fix.
1369 | self.androidFix.pause = false;
1370 | self.pause(self.androidFix.time);
1371 | }
1372 | self._trigger($.jPlayer.event.loadeddata);
1373 | }
1374 | }, false);
1375 | mediaElement.addEventListener("timeupdate", function() {
1376 | if(entity.gate) {
1377 | self._getHtmlStatus(mediaElement);
1378 | self._updateInterface();
1379 | self._trigger($.jPlayer.event.timeupdate);
1380 | }
1381 | }, false);
1382 | mediaElement.addEventListener("durationchange", function() {
1383 | if(entity.gate) {
1384 | self._getHtmlStatus(mediaElement);
1385 | self._updateInterface();
1386 | self._trigger($.jPlayer.event.durationchange);
1387 | }
1388 | }, false);
1389 | mediaElement.addEventListener("play", function() {
1390 | if(entity.gate) {
1391 | self._updateButtons(true);
1392 | self._html_checkWaitForPlay(); // So the native controls update this variable and puts the hidden interface in the correct state. Affects toggling native controls.
1393 | self._trigger($.jPlayer.event.play);
1394 | }
1395 | }, false);
1396 | mediaElement.addEventListener("playing", function() {
1397 | if(entity.gate) {
1398 | self._updateButtons(true);
1399 | self._seeked();
1400 | self._trigger($.jPlayer.event.playing);
1401 | }
1402 | }, false);
1403 | mediaElement.addEventListener("pause", function() {
1404 | if(entity.gate) {
1405 | self._updateButtons(false);
1406 | self._trigger($.jPlayer.event.pause);
1407 | }
1408 | }, false);
1409 | mediaElement.addEventListener("waiting", function() {
1410 | if(entity.gate) {
1411 | self._seeking();
1412 | self._trigger($.jPlayer.event.waiting);
1413 | }
1414 | }, false);
1415 | mediaElement.addEventListener("seeking", function() {
1416 | if(entity.gate) {
1417 | self._seeking();
1418 | self._trigger($.jPlayer.event.seeking);
1419 | }
1420 | }, false);
1421 | mediaElement.addEventListener("seeked", function() {
1422 | if(entity.gate) {
1423 | self._seeked();
1424 | self._trigger($.jPlayer.event.seeked);
1425 | }
1426 | }, false);
1427 | mediaElement.addEventListener("volumechange", function() {
1428 | if(entity.gate) {
1429 | // Read the values back from the element as the Blackberry PlayBook shares the volume with the physical buttons master volume control.
1430 | // However, when tested 6th July 2011, those buttons do not generate an event. The physical play/pause button does though.
1431 | self.options.volume = mediaElement.volume;
1432 | self.options.muted = mediaElement.muted;
1433 | self._updateMute();
1434 | self._updateVolume();
1435 | self._trigger($.jPlayer.event.volumechange);
1436 | }
1437 | }, false);
1438 | mediaElement.addEventListener("ratechange", function() {
1439 | if(entity.gate) {
1440 | self.options.defaultPlaybackRate = mediaElement.defaultPlaybackRate;
1441 | self.options.playbackRate = mediaElement.playbackRate;
1442 | self._updatePlaybackRate();
1443 | self._trigger($.jPlayer.event.ratechange);
1444 | }
1445 | }, false);
1446 | 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.
1447 | if(entity.gate) {
1448 | self._seeked();
1449 | self._trigger($.jPlayer.event.suspend);
1450 | }
1451 | }, false);
1452 | mediaElement.addEventListener("ended", function() {
1453 | if(entity.gate) {
1454 | // Order of the next few commands are important. Change the time and then pause.
1455 | // Solves a bug in Firefox, where issuing pause 1st causes the media to play from the start. ie., The pause is ignored.
1456 | 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.
1457 | 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.)
1458 | }
1459 | 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.
1460 | self._updateButtons(false);
1461 | self._getHtmlStatus(mediaElement, true); // With override true. Otherwise Chrome leaves progress at full.
1462 | self._updateInterface();
1463 | self._trigger($.jPlayer.event.ended);
1464 | }
1465 | }, false);
1466 | mediaElement.addEventListener("error", function() {
1467 | if(entity.gate) {
1468 | self._updateButtons(false);
1469 | self._seeked();
1470 | if(self.status.srcSet) { // Deals with case of clearMedia() causing an error event.
1471 | clearTimeout(self.internal.htmlDlyCmdId); // Clears any delayed commands used in the HTML solution.
1472 | self.status.waitForLoad = true; // Allows the load operation to try again.
1473 | self.status.waitForPlay = true; // Reset since a play was captured.
1474 | if(self.status.video && !self.status.nativeVideoControls) {
1475 | self.internal.video.jq.css({'width':'0px', 'height':'0px'});
1476 | }
1477 | if(self._validString(self.status.media.poster) && !self.status.nativeVideoControls) {
1478 | self.internal.poster.jq.show();
1479 | }
1480 | if(self.css.jq.videoPlay.length) {
1481 | self.css.jq.videoPlay.show();
1482 | }
1483 | self._error( {
1484 | type: $.jPlayer.error.URL,
1485 | context: self.status.src, // this.src shows absolute urls. Want context to show the url given.
1486 | message: $.jPlayer.errorMsg.URL,
1487 | hint: $.jPlayer.errorHint.URL
1488 | });
1489 | }
1490 | }
1491 | }, false);
1492 | // Create all the other event listeners that bubble up to a jPlayer event from html, without being used by jPlayer.
1493 | $.each($.jPlayer.htmlEvent, function(i, eventType) {
1494 | mediaElement.addEventListener(this, function() {
1495 | if(entity.gate) {
1496 | self._trigger($.jPlayer.event[eventType]);
1497 | }
1498 | }, false);
1499 | });
1500 | },
1501 | _addAuroraEventListeners : function(player, entity) {
1502 | var self = this;
1503 | //player.preload = this.options.preload;
1504 | //player.muted = this.options.muted;
1505 | player.volume = this.options.volume * 100;
1506 |
1507 | // Create the event listeners
1508 | // Only want the active entity to affect jPlayer and bubble events.
1509 | // Using entity.gate so that object is referenced and gate property always current
1510 |
1511 | player.on("progress", function() {
1512 | if(entity.gate) {
1513 | if(self.internal.cmdsIgnored && this.readyState > 0) { // Detect iOS executed the command
1514 | self.internal.cmdsIgnored = false;
1515 | }
1516 | self._getAuroraStatus(player);
1517 | self._updateInterface();
1518 | self._trigger($.jPlayer.event.progress);
1519 | // Progress with song duration, we estimate timeupdate need to be triggered too.
1520 | if (player.duration > 0) {
1521 | self._trigger($.jPlayer.event.timeupdate);
1522 | }
1523 | }
1524 | }, false);
1525 | player.on("ready", function() {
1526 | if(entity.gate) {
1527 | self._trigger($.jPlayer.event.loadeddata);
1528 | }
1529 | }, false);
1530 | player.on("duration", function() {
1531 | if(entity.gate) {
1532 | self._getAuroraStatus(player);
1533 | self._updateInterface();
1534 | self._trigger($.jPlayer.event.durationchange);
1535 | }
1536 | }, false);
1537 | player.on("end", function() {
1538 | if(entity.gate) {
1539 | // Order of the next few commands are important. Change the time and then pause.
1540 | self._updateButtons(false);
1541 | self._getAuroraStatus(player, true);
1542 | self._updateInterface();
1543 | self._trigger($.jPlayer.event.ended);
1544 | }
1545 | }, false);
1546 | player.on("error", function() {
1547 | if(entity.gate) {
1548 | self._updateButtons(false);
1549 | self._seeked();
1550 | if(self.status.srcSet) { // Deals with case of clearMedia() causing an error event.
1551 | self.status.waitForLoad = true; // Allows the load operation to try again.
1552 | self.status.waitForPlay = true; // Reset since a play was captured.
1553 | if(self.status.video && !self.status.nativeVideoControls) {
1554 | self.internal.video.jq.css({'width':'0px', 'height':'0px'});
1555 | }
1556 | if(self._validString(self.status.media.poster) && !self.status.nativeVideoControls) {
1557 | self.internal.poster.jq.show();
1558 | }
1559 | if(self.css.jq.videoPlay.length) {
1560 | self.css.jq.videoPlay.show();
1561 | }
1562 | self._error( {
1563 | type: $.jPlayer.error.URL,
1564 | context: self.status.src, // this.src shows absolute urls. Want context to show the url given.
1565 | message: $.jPlayer.errorMsg.URL,
1566 | hint: $.jPlayer.errorHint.URL
1567 | });
1568 | }
1569 | }
1570 | }, false);
1571 | },
1572 | _getHtmlStatus: function(media, override) {
1573 | var ct = 0, cpa = 0, sp = 0, cpr = 0;
1574 |
1575 | // Fixes the duration bug in iOS, where the durationchange event occurs when media.duration is not always correct.
1576 | // Fixes the initial duration bug in BB OS7, where the media.duration is infinity and displays as NaN:NaN due to Date() using inifity.
1577 | if(isFinite(media.duration)) {
1578 | this.status.duration = media.duration;
1579 | }
1580 |
1581 | ct = media.currentTime;
1582 | cpa = (this.status.duration > 0) ? 100 * ct / this.status.duration : 0;
1583 | if((typeof media.seekable === "object") && (media.seekable.length > 0)) {
1584 | sp = (this.status.duration > 0) ? 100 * media.seekable.end(media.seekable.length-1) / this.status.duration : 100;
1585 | cpr = (this.status.duration > 0) ? 100 * media.currentTime / media.seekable.end(media.seekable.length-1) : 0; // Duration conditional for iOS duration bug. ie., seekable.end is a NaN in that case.
1586 | } else {
1587 | sp = 100;
1588 | cpr = cpa;
1589 | }
1590 |
1591 | if(override) {
1592 | ct = 0;
1593 | cpr = 0;
1594 | cpa = 0;
1595 | }
1596 |
1597 | this.status.seekPercent = sp;
1598 | this.status.currentPercentRelative = cpr;
1599 | this.status.currentPercentAbsolute = cpa;
1600 | this.status.currentTime = ct;
1601 |
1602 | this.status.remaining = this.status.duration - this.status.currentTime;
1603 |
1604 | this.status.videoWidth = media.videoWidth;
1605 | this.status.videoHeight = media.videoHeight;
1606 |
1607 | this.status.readyState = media.readyState;
1608 | this.status.networkState = media.networkState;
1609 | this.status.playbackRate = media.playbackRate;
1610 | this.status.ended = media.ended;
1611 | },
1612 | _getAuroraStatus: function(player, override) {
1613 | var ct = 0, cpa = 0, sp = 0, cpr = 0;
1614 |
1615 | this.status.duration = player.duration / 1000;
1616 |
1617 | ct = player.currentTime / 1000;
1618 | cpa = (this.status.duration > 0) ? 100 * ct / this.status.duration : 0;
1619 | if(player.buffered > 0) {
1620 | sp = (this.status.duration > 0) ? (player.buffered * this.status.duration) / this.status.duration : 100;
1621 | cpr = (this.status.duration > 0) ? ct / (player.buffered * this.status.duration) : 0;
1622 | } else {
1623 | sp = 100;
1624 | cpr = cpa;
1625 | }
1626 |
1627 | if(override) {
1628 | ct = 0;
1629 | cpr = 0;
1630 | cpa = 0;
1631 | }
1632 |
1633 | this.status.seekPercent = sp;
1634 | this.status.currentPercentRelative = cpr;
1635 | this.status.currentPercentAbsolute = cpa;
1636 | this.status.currentTime = ct;
1637 |
1638 | this.status.remaining = this.status.duration - this.status.currentTime;
1639 |
1640 | this.status.readyState = 4; // status.readyState;
1641 | this.status.networkState = 0; // status.networkState;
1642 | this.status.playbackRate = 1; // status.playbackRate;
1643 | this.status.ended = false; // status.ended;
1644 | },
1645 | _resetStatus: function() {
1646 | this.status = $.extend({}, this.status, $.jPlayer.prototype.status); // Maintains the status properties that persist through a reset.
1647 | },
1648 | _trigger: function(eventType, error, warning) { // eventType always valid as called using $.jPlayer.event.eventType
1649 | var event = $.Event(eventType);
1650 | event.jPlayer = {};
1651 | event.jPlayer.version = $.extend({}, this.version);
1652 | event.jPlayer.options = $.extend(true, {}, this.options); // Deep copy
1653 | event.jPlayer.status = $.extend(true, {}, this.status); // Deep copy
1654 | event.jPlayer.html = $.extend(true, {}, this.html); // Deep copy
1655 | event.jPlayer.aurora = $.extend(true, {}, this.aurora); // Deep copy
1656 | event.jPlayer.flash = $.extend(true, {}, this.flash); // Deep copy
1657 | if(error) {
1658 | event.jPlayer.error = $.extend({}, error);
1659 | }
1660 | if(warning) {
1661 | event.jPlayer.warning = $.extend({}, warning);
1662 | }
1663 | this.element.trigger(event);
1664 | },
1665 | jPlayerFlashEvent: function(eventType, status) { // Called from Flash
1666 | if(eventType === $.jPlayer.event.ready) {
1667 | if(!this.internal.ready) {
1668 | this.internal.ready = true;
1669 | 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.
1670 |
1671 | this.version.flash = status.version;
1672 | if(this.version.needFlash !== this.version.flash) {
1673 | this._error( {
1674 | type: $.jPlayer.error.VERSION,
1675 | context: this.version.flash,
1676 | message: $.jPlayer.errorMsg.VERSION + this.version.flash,
1677 | hint: $.jPlayer.errorHint.VERSION
1678 | });
1679 | }
1680 | this._trigger($.jPlayer.event.repeat); // Trigger the repeat event so its handler can initialize itself with the loop option.
1681 | this._trigger(eventType);
1682 | } else {
1683 | // This condition occurs if the Flash is hidden and then shown again.
1684 | // Firefox also reloads the Flash if the CSS position changes. position:fixed is used for full screen.
1685 |
1686 | // Only do this if the Flash is the solution being used at the moment. Affects Media players where both solution may be being used.
1687 | if(this.flash.gate) {
1688 |
1689 | // Send the current status to the Flash now that it is ready (available) again.
1690 | if(this.status.srcSet) {
1691 |
1692 | // Need to read original status before issuing the setMedia command.
1693 | var currentTime = this.status.currentTime,
1694 | paused = this.status.paused;
1695 |
1696 | this.setMedia(this.status.media);
1697 | this.volumeWorker(this.options.volume);
1698 | if(currentTime > 0) {
1699 | if(paused) {
1700 | this.pause(currentTime);
1701 | } else {
1702 | this.play(currentTime);
1703 | }
1704 | }
1705 | }
1706 | this._trigger($.jPlayer.event.flashreset);
1707 | }
1708 | }
1709 | }
1710 | if(this.flash.gate) {
1711 | switch(eventType) {
1712 | case $.jPlayer.event.progress:
1713 | this._getFlashStatus(status);
1714 | this._updateInterface();
1715 | this._trigger(eventType);
1716 | break;
1717 | case $.jPlayer.event.timeupdate:
1718 | this._getFlashStatus(status);
1719 | this._updateInterface();
1720 | this._trigger(eventType);
1721 | break;
1722 | case $.jPlayer.event.play:
1723 | this._seeked();
1724 | this._updateButtons(true);
1725 | this._trigger(eventType);
1726 | break;
1727 | case $.jPlayer.event.pause:
1728 | this._updateButtons(false);
1729 | this._trigger(eventType);
1730 | break;
1731 | case $.jPlayer.event.ended:
1732 | this._updateButtons(false);
1733 | this._trigger(eventType);
1734 | break;
1735 | case $.jPlayer.event.click:
1736 | this._trigger(eventType); // This could be dealt with by the default
1737 | break;
1738 | case $.jPlayer.event.error:
1739 | this.status.waitForLoad = true; // Allows the load operation to try again.
1740 | this.status.waitForPlay = true; // Reset since a play was captured.
1741 | if(this.status.video) {
1742 | this.internal.flash.jq.css({'width':'0px', 'height':'0px'});
1743 | }
1744 | if(this._validString(this.status.media.poster)) {
1745 | this.internal.poster.jq.show();
1746 | }
1747 | if(this.css.jq.videoPlay.length && this.status.video) {
1748 | this.css.jq.videoPlay.show();
1749 | }
1750 | if(this.status.video) { // Set up for another try. Execute before error event.
1751 | this._flash_setVideo(this.status.media);
1752 | } else {
1753 | this._flash_setAudio(this.status.media);
1754 | }
1755 | this._updateButtons(false);
1756 | this._error( {
1757 | type: $.jPlayer.error.URL,
1758 | context:status.src,
1759 | message: $.jPlayer.errorMsg.URL,
1760 | hint: $.jPlayer.errorHint.URL
1761 | });
1762 | break;
1763 | case $.jPlayer.event.seeking:
1764 | this._seeking();
1765 | this._trigger(eventType);
1766 | break;
1767 | case $.jPlayer.event.seeked:
1768 | this._seeked();
1769 | this._trigger(eventType);
1770 | break;
1771 | case $.jPlayer.event.ready:
1772 | // The ready event is handled outside the switch statement.
1773 | // Captured here otherwise 2 ready events would be generated if the ready event handler used setMedia.
1774 | break;
1775 | default:
1776 | this._trigger(eventType);
1777 | }
1778 | }
1779 | return false;
1780 | },
1781 | _getFlashStatus: function(status) {
1782 | this.status.seekPercent = status.seekPercent;
1783 | this.status.currentPercentRelative = status.currentPercentRelative;
1784 | this.status.currentPercentAbsolute = status.currentPercentAbsolute;
1785 | this.status.currentTime = status.currentTime;
1786 | this.status.duration = status.duration;
1787 | this.status.remaining = status.duration - status.currentTime;
1788 |
1789 | this.status.videoWidth = status.videoWidth;
1790 | this.status.videoHeight = status.videoHeight;
1791 |
1792 | // The Flash does not generate this information in this release
1793 | this.status.readyState = 4; // status.readyState;
1794 | this.status.networkState = 0; // status.networkState;
1795 | this.status.playbackRate = 1; // status.playbackRate;
1796 | this.status.ended = false; // status.ended;
1797 | },
1798 | _updateButtons: function(playing) {
1799 | if(playing === undefined) {
1800 | playing = !this.status.paused;
1801 | } else {
1802 | this.status.paused = !playing;
1803 | }
1804 | // Apply the state classes. (For the useStateClassSkin:true option)
1805 | if(playing) {
1806 | this.addStateClass('playing');
1807 | } else {
1808 | this.removeStateClass('playing');
1809 | }
1810 | if(!this.status.noFullWindow && this.options.fullWindow) {
1811 | this.addStateClass('fullScreen');
1812 | } else {
1813 | this.removeStateClass('fullScreen');
1814 | }
1815 | if(this.options.loop) {
1816 | this.addStateClass('looped');
1817 | } else {
1818 | this.removeStateClass('looped');
1819 | }
1820 | // Toggle the GUI element pairs. (For the useStateClassSkin:false option)
1821 | if(this.css.jq.play.length && this.css.jq.pause.length) {
1822 | if(playing) {
1823 | this.css.jq.play.hide();
1824 | this.css.jq.pause.show();
1825 | } else {
1826 | this.css.jq.play.show();
1827 | this.css.jq.pause.hide();
1828 | }
1829 | }
1830 | if(this.css.jq.restoreScreen.length && this.css.jq.fullScreen.length) {
1831 | if(this.status.noFullWindow) {
1832 | this.css.jq.fullScreen.hide();
1833 | this.css.jq.restoreScreen.hide();
1834 | } else if(this.options.fullWindow) {
1835 | this.css.jq.fullScreen.hide();
1836 | this.css.jq.restoreScreen.show();
1837 | } else {
1838 | this.css.jq.fullScreen.show();
1839 | this.css.jq.restoreScreen.hide();
1840 | }
1841 | }
1842 | if(this.css.jq.repeat.length && this.css.jq.repeatOff.length) {
1843 | if(this.options.loop) {
1844 | this.css.jq.repeat.hide();
1845 | this.css.jq.repeatOff.show();
1846 | } else {
1847 | this.css.jq.repeat.show();
1848 | this.css.jq.repeatOff.hide();
1849 | }
1850 | }
1851 | },
1852 | _updateInterface: function() {
1853 | if(this.css.jq.seekBar.length) {
1854 | this.css.jq.seekBar.width(this.status.seekPercent+"%");
1855 | }
1856 | if(this.css.jq.playBar.length) {
1857 | if(this.options.smoothPlayBar) {
1858 | this.css.jq.playBar.stop().animate({
1859 | width: this.status.currentPercentAbsolute+"%"
1860 | }, 250, "linear");
1861 | } else {
1862 | this.css.jq.playBar.width(this.status.currentPercentRelative+"%");
1863 | }
1864 | }
1865 | var currentTimeText = '';
1866 | if(this.css.jq.currentTime.length) {
1867 | currentTimeText = this._convertTime(this.status.currentTime);
1868 | if(currentTimeText !== this.css.jq.currentTime.text()) {
1869 | this.css.jq.currentTime.text(this._convertTime(this.status.currentTime));
1870 | }
1871 | }
1872 | var durationText = '',
1873 | duration = this.status.duration,
1874 | remaining = this.status.remaining;
1875 | if(this.css.jq.duration.length) {
1876 | if(typeof this.status.media.duration === 'string') {
1877 | durationText = this.status.media.duration;
1878 | } else {
1879 | if(typeof this.status.media.duration === 'number') {
1880 | duration = this.status.media.duration;
1881 | remaining = duration - this.status.currentTime;
1882 | }
1883 | if(this.options.remainingDuration) {
1884 | durationText = (remaining > 0 ? '-' : '') + this._convertTime(remaining);
1885 | } else {
1886 | durationText = this._convertTime(duration);
1887 | }
1888 | }
1889 | if(durationText !== this.css.jq.duration.text()) {
1890 | this.css.jq.duration.text(durationText);
1891 | }
1892 | }
1893 | },
1894 | _convertTime: ConvertTime.prototype.time,
1895 | _seeking: function() {
1896 | if(this.css.jq.seekBar.length) {
1897 | this.css.jq.seekBar.addClass("jp-seeking-bg");
1898 | }
1899 | this.addStateClass('seeking');
1900 | },
1901 | _seeked: function() {
1902 | if(this.css.jq.seekBar.length) {
1903 | this.css.jq.seekBar.removeClass("jp-seeking-bg");
1904 | }
1905 | this.removeStateClass('seeking');
1906 | },
1907 | _resetGate: function() {
1908 | this.html.audio.gate = false;
1909 | this.html.video.gate = false;
1910 | this.aurora.gate = false;
1911 | this.flash.gate = false;
1912 | },
1913 | _resetActive: function() {
1914 | this.html.active = false;
1915 | this.aurora.active = false;
1916 | this.flash.active = false;
1917 | },
1918 | _escapeHtml: function(s) {
1919 | return s.split('&').join('&').split('<').join('<').split('>').join('>').split('"').join('"');
1920 | },
1921 | _qualifyURL: function(url) {
1922 | var el = document.createElement('div');
1923 | el.innerHTML= 'x';
1924 | return el.firstChild.href;
1925 | },
1926 | _absoluteMediaUrls: function(media) {
1927 | var self = this;
1928 | $.each(media, function(type, url) {
1929 | if(url && self.format[type] && url.substr(0, 5) !== "data:") {
1930 | media[type] = self._qualifyURL(url);
1931 | }
1932 | });
1933 | return media;
1934 | },
1935 | addStateClass: function(state) {
1936 | if(this.ancestorJq.length) {
1937 | this.ancestorJq.addClass(this.options.stateClass[state]);
1938 | }
1939 | },
1940 | removeStateClass: function(state) {
1941 | if(this.ancestorJq.length) {
1942 | this.ancestorJq.removeClass(this.options.stateClass[state]);
1943 | }
1944 | },
1945 | setMedia: function(media) {
1946 |
1947 | /* media[format] = String: URL of format. Must contain all of the supplied option's video or audio formats.
1948 | * media.poster = String: Video poster URL.
1949 | * media.track = Array: Of objects defining the track element: kind, src, srclang, label, def.
1950 | * media.stream = Boolean: * NOT IMPLEMENTED * Designating actual media streams. ie., "false/undefined" for files. Plan to refresh the flash every so often.
1951 | */
1952 |
1953 | var self = this,
1954 | supported = false,
1955 | 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.
1956 |
1957 | this._resetMedia();
1958 | this._resetGate();
1959 | this._resetActive();
1960 |
1961 | // Clear the Android Fix.
1962 | this.androidFix.setMedia = false;
1963 | this.androidFix.play = false;
1964 | this.androidFix.pause = false;
1965 |
1966 | // Convert all media URLs to absolute URLs.
1967 | media = this._absoluteMediaUrls(media);
1968 |
1969 | $.each(this.formats, function(formatPriority, format) {
1970 | var isVideo = self.format[format].media === 'video';
1971 | $.each(self.solutions, function(solutionPriority, solution) {
1972 | if(self[solution].support[format] && self._validString(media[format])) { // Format supported in solution and url given for format.
1973 | var isHtml = solution === 'html';
1974 | var isAurora = solution === 'aurora';
1975 |
1976 | if(isVideo) {
1977 | if(isHtml) {
1978 | self.html.video.gate = true;
1979 | self._html_setVideo(media);
1980 | self.html.active = true;
1981 | } else {
1982 | self.flash.gate = true;
1983 | self._flash_setVideo(media);
1984 | self.flash.active = true;
1985 | }
1986 | if(self.css.jq.videoPlay.length) {
1987 | self.css.jq.videoPlay.show();
1988 | }
1989 | self.status.video = true;
1990 | } else {
1991 | if(isHtml) {
1992 | self.html.audio.gate = true;
1993 | self._html_setAudio(media);
1994 | self.html.active = true;
1995 |
1996 | // Setup the Android Fix - Only for HTML audio.
1997 | if($.jPlayer.platform.android) {
1998 | self.androidFix.setMedia = true;
1999 | }
2000 | } else if(isAurora) {
2001 | self.aurora.gate = true;
2002 | self._aurora_setAudio(media);
2003 | self.aurora.active = true;
2004 | } else {
2005 | self.flash.gate = true;
2006 | self._flash_setAudio(media);
2007 | self.flash.active = true;
2008 | }
2009 | if(self.css.jq.videoPlay.length) {
2010 | self.css.jq.videoPlay.hide();
2011 | }
2012 | self.status.video = false;
2013 | }
2014 |
2015 | supported = true;
2016 | return false; // Exit $.each
2017 | }
2018 | });
2019 | if(supported) {
2020 | return false; // Exit $.each
2021 | }
2022 | });
2023 |
2024 | if(supported) {
2025 | if(!(this.status.nativeVideoControls && this.html.video.gate)) {
2026 | // Set poster IMG if native video controls are not being used
2027 | // Note: With IE the IMG onload event occurs immediately when cached.
2028 | // Note: Poster hidden by default in _resetMedia()
2029 | if(this._validString(media.poster)) {
2030 | if(posterChanged) { // Since some browsers do not generate img onload event.
2031 | this.htmlElement.poster.src = media.poster;
2032 | } else {
2033 | this.internal.poster.jq.show();
2034 | }
2035 | }
2036 | }
2037 | if(typeof media.title === 'string') {
2038 | if(this.css.jq.title.length) {
2039 | this.css.jq.title.html(media.title);
2040 | }
2041 | if(this.htmlElement.audio) {
2042 | this.htmlElement.audio.setAttribute('title', media.title);
2043 | }
2044 | if(this.htmlElement.video) {
2045 | this.htmlElement.video.setAttribute('title', media.title);
2046 | }
2047 | }
2048 | this.status.srcSet = true;
2049 | this.status.media = $.extend({}, media);
2050 | this._updateButtons(false);
2051 | this._updateInterface();
2052 | this._trigger($.jPlayer.event.setmedia);
2053 | } else { // jPlayer cannot support any formats provided in this browser
2054 | // Send an error event
2055 | this._error( {
2056 | type: $.jPlayer.error.NO_SUPPORT,
2057 | context: "{supplied:'" + this.options.supplied + "'}",
2058 | message: $.jPlayer.errorMsg.NO_SUPPORT,
2059 | hint: $.jPlayer.errorHint.NO_SUPPORT
2060 | });
2061 | }
2062 | },
2063 | _resetMedia: function() {
2064 | this._resetStatus();
2065 | this._updateButtons(false);
2066 | this._updateInterface();
2067 | this._seeked();
2068 | this.internal.poster.jq.hide();
2069 |
2070 | clearTimeout(this.internal.htmlDlyCmdId);
2071 |
2072 | if(this.html.active) {
2073 | this._html_resetMedia();
2074 | } else if(this.aurora.active) {
2075 | this._aurora_resetMedia();
2076 | } else if(this.flash.active) {
2077 | this._flash_resetMedia();
2078 | }
2079 | },
2080 | clearMedia: function() {
2081 | this._resetMedia();
2082 |
2083 | if(this.html.active) {
2084 | this._html_clearMedia();
2085 | } else if(this.aurora.active) {
2086 | this._aurora_clearMedia();
2087 | } else if(this.flash.active) {
2088 | this._flash_clearMedia();
2089 | }
2090 |
2091 | this._resetGate();
2092 | this._resetActive();
2093 | },
2094 | load: function() {
2095 | if(this.status.srcSet) {
2096 | if(this.html.active) {
2097 | this._html_load();
2098 | } else if(this.aurora.active) {
2099 | this._aurora_load();
2100 | } else if(this.flash.active) {
2101 | this._flash_load();
2102 | }
2103 | } else {
2104 | this._urlNotSetError("load");
2105 | }
2106 | },
2107 | focus: function() {
2108 | if(this.options.keyEnabled) {
2109 | $.jPlayer.focus = this;
2110 | }
2111 | },
2112 | play: function(time) {
2113 | var guiAction = typeof time === "object"; // Flags GUI click events so we know this was not a direct command, but an action taken by the user on the GUI.
2114 | if(guiAction && this.options.useStateClassSkin && !this.status.paused) {
2115 | this.pause(time); // The time would be the click event, but passing it over so info is not lost.
2116 | } else {
2117 | time = (typeof time === "number") ? time : NaN; // Remove jQuery event from click handler
2118 | if(this.status.srcSet) {
2119 | this.focus();
2120 | if(this.html.active) {
2121 | this._html_play(time);
2122 | } else if(this.aurora.active) {
2123 | this._aurora_play(time);
2124 | } else if(this.flash.active) {
2125 | this._flash_play(time);
2126 | }
2127 | } else {
2128 | this._urlNotSetError("play");
2129 | }
2130 | }
2131 | },
2132 | videoPlay: function() { // Handles clicks on the play button over the video poster
2133 | this.play();
2134 | },
2135 | pause: function(time) {
2136 | time = (typeof time === "number") ? time : NaN; // Remove jQuery event from click handler
2137 | if(this.status.srcSet) {
2138 | if(this.html.active) {
2139 | this._html_pause(time);
2140 | } else if(this.aurora.active) {
2141 | this._aurora_pause(time);
2142 | } else if(this.flash.active) {
2143 | this._flash_pause(time);
2144 | }
2145 | } else {
2146 | this._urlNotSetError("pause");
2147 | }
2148 | },
2149 | tellOthers: function(command, conditions) {
2150 | var self = this,
2151 | hasConditions = typeof conditions === 'function',
2152 | args = Array.prototype.slice.call(arguments); // Convert arguments to an Array.
2153 |
2154 | if(typeof command !== 'string') { // Ignore, since no command.
2155 | return; // Return undefined to maintain chaining.
2156 | }
2157 | if(hasConditions) {
2158 | args.splice(1, 1); // Remove the conditions from the arguments
2159 | }
2160 |
2161 | $.jPlayer.prototype.destroyRemoved();
2162 | $.each(this.instances, function() {
2163 | // Remember that "this" is the instance's "element" in the $.each() loop.
2164 | if(self.element !== this) { // Do not tell my instance.
2165 | if(!hasConditions || conditions.call(this.data("jPlayer"), self)) {
2166 | this.jPlayer.apply(this, args);
2167 | }
2168 | }
2169 | });
2170 | },
2171 | pauseOthers: function(time) {
2172 | this.tellOthers("pause", function() {
2173 | // In the conditions function, the "this" context is the other instance's jPlayer object.
2174 | return this.status.srcSet;
2175 | }, time);
2176 | },
2177 | stop: function() {
2178 | if(this.status.srcSet) {
2179 | if(this.html.active) {
2180 | this._html_pause(0);
2181 | } else if(this.aurora.active) {
2182 | this._aurora_pause(0);
2183 | } else if(this.flash.active) {
2184 | this._flash_pause(0);
2185 | }
2186 | } else {
2187 | this._urlNotSetError("stop");
2188 | }
2189 | },
2190 | playHead: function(p) {
2191 | p = this._limitValue(p, 0, 100);
2192 | if(this.status.srcSet) {
2193 | if(this.html.active) {
2194 | this._html_playHead(p);
2195 | } else if(this.aurora.active) {
2196 | this._aurora_playHead(p);
2197 | } else if(this.flash.active) {
2198 | this._flash_playHead(p);
2199 | }
2200 | } else {
2201 | this._urlNotSetError("playHead");
2202 | }
2203 | },
2204 | _muted: function(muted) {
2205 | this.mutedWorker(muted);
2206 | if(this.options.globalVolume) {
2207 | this.tellOthers("mutedWorker", function() {
2208 | // Check the other instance has global volume enabled.
2209 | return this.options.globalVolume;
2210 | }, muted);
2211 | }
2212 | },
2213 | mutedWorker: function(muted) {
2214 | this.options.muted = muted;
2215 | if(this.html.used) {
2216 | this._html_setProperty('muted', muted);
2217 | }
2218 | if(this.aurora.used) {
2219 | this._aurora_mute(muted);
2220 | }
2221 | if(this.flash.used) {
2222 | this._flash_mute(muted);
2223 | }
2224 |
2225 | // The HTML solution generates this event from the media element itself.
2226 | if(!this.html.video.gate && !this.html.audio.gate) {
2227 | this._updateMute(muted);
2228 | this._updateVolume(this.options.volume);
2229 | this._trigger($.jPlayer.event.volumechange);
2230 | }
2231 | },
2232 | mute: function(mute) { // mute is either: undefined (true), an event object (true) or a boolean (muted).
2233 | var guiAction = typeof mute === "object"; // Flags GUI click events so we know this was not a direct command, but an action taken by the user on the GUI.
2234 | if(guiAction && this.options.useStateClassSkin && this.options.muted) {
2235 | this._muted(false);
2236 | } else {
2237 | mute = mute === undefined ? true : !!mute;
2238 | this._muted(mute);
2239 | }
2240 | },
2241 | unmute: function(unmute) { // unmute is either: undefined (true), an event object (true) or a boolean (!muted).
2242 | unmute = unmute === undefined ? true : !!unmute;
2243 | this._muted(!unmute);
2244 | },
2245 | _updateMute: function(mute) {
2246 | if(mute === undefined) {
2247 | mute = this.options.muted;
2248 | }
2249 | if(mute) {
2250 | this.addStateClass('muted');
2251 | } else {
2252 | this.removeStateClass('muted');
2253 | }
2254 | if(this.css.jq.mute.length && this.css.jq.unmute.length) {
2255 | if(this.status.noVolume) {
2256 | this.css.jq.mute.hide();
2257 | this.css.jq.unmute.hide();
2258 | } else if(mute) {
2259 | this.css.jq.mute.hide();
2260 | this.css.jq.unmute.show();
2261 | } else {
2262 | this.css.jq.mute.show();
2263 | this.css.jq.unmute.hide();
2264 | }
2265 | }
2266 | },
2267 | volume: function(v) {
2268 | this.volumeWorker(v);
2269 | if(this.options.globalVolume) {
2270 | this.tellOthers("volumeWorker", function() {
2271 | // Check the other instance has global volume enabled.
2272 | return this.options.globalVolume;
2273 | }, v);
2274 | }
2275 | },
2276 | volumeWorker: function(v) {
2277 | v = this._limitValue(v, 0, 1);
2278 | this.options.volume = v;
2279 |
2280 | if(this.html.used) {
2281 | this._html_setProperty('volume', v);
2282 | }
2283 | if(this.aurora.used) {
2284 | this._aurora_volume(v);
2285 | }
2286 | if(this.flash.used) {
2287 | this._flash_volume(v);
2288 | }
2289 |
2290 | // The HTML solution generates this event from the media element itself.
2291 | if(!this.html.video.gate && !this.html.audio.gate) {
2292 | this._updateVolume(v);
2293 | this._trigger($.jPlayer.event.volumechange);
2294 | }
2295 | },
2296 | volumeBar: function(e) { // Handles clicks on the volumeBar
2297 | if(this.css.jq.volumeBar.length) {
2298 | // Using $(e.currentTarget) to enable multiple volume bars
2299 | var $bar = $(e.currentTarget),
2300 | offset = $bar.offset(),
2301 | x = e.pageX - offset.left,
2302 | w = $bar.width(),
2303 | y = $bar.height() - e.pageY + offset.top,
2304 | h = $bar.height();
2305 | if(this.options.verticalVolume) {
2306 | this.volume(y/h);
2307 | } else {
2308 | this.volume(x/w);
2309 | }
2310 | }
2311 | if(this.options.muted) {
2312 | this._muted(false);
2313 | }
2314 | },
2315 | _updateVolume: function(v) {
2316 | if(v === undefined) {
2317 | v = this.options.volume;
2318 | }
2319 | v = this.options.muted ? 0 : v;
2320 |
2321 | if(this.status.noVolume) {
2322 | this.addStateClass('noVolume');
2323 | if(this.css.jq.volumeBar.length) {
2324 | this.css.jq.volumeBar.hide();
2325 | }
2326 | if(this.css.jq.volumeBarValue.length) {
2327 | this.css.jq.volumeBarValue.hide();
2328 | }
2329 | if(this.css.jq.volumeMax.length) {
2330 | this.css.jq.volumeMax.hide();
2331 | }
2332 | } else {
2333 | this.removeStateClass('noVolume');
2334 | if(this.css.jq.volumeBar.length) {
2335 | this.css.jq.volumeBar.show();
2336 | }
2337 | if(this.css.jq.volumeBarValue.length) {
2338 | this.css.jq.volumeBarValue.show();
2339 | this.css.jq.volumeBarValue[this.options.verticalVolume ? "height" : "width"]((v*100)+"%");
2340 | }
2341 | if(this.css.jq.volumeMax.length) {
2342 | this.css.jq.volumeMax.show();
2343 | }
2344 | }
2345 | },
2346 | volumeMax: function() { // Handles clicks on the volume max
2347 | this.volume(1);
2348 | if(this.options.muted) {
2349 | this._muted(false);
2350 | }
2351 | },
2352 | _cssSelectorAncestor: function(ancestor) {
2353 | var self = this;
2354 | this.options.cssSelectorAncestor = ancestor;
2355 | this._removeUiClass();
2356 | this.ancestorJq = ancestor ? $(ancestor) : []; // Would use $() instead of [], but it is only 1.4+
2357 | if(ancestor && this.ancestorJq.length !== 1) { // So empty strings do not generate the warning.
2358 | this._warning( {
2359 | type: $.jPlayer.warning.CSS_SELECTOR_COUNT,
2360 | context: ancestor,
2361 | message: $.jPlayer.warningMsg.CSS_SELECTOR_COUNT + this.ancestorJq.length + " found for cssSelectorAncestor.",
2362 | hint: $.jPlayer.warningHint.CSS_SELECTOR_COUNT
2363 | });
2364 | }
2365 | this._addUiClass();
2366 | $.each(this.options.cssSelector, function(fn, cssSel) {
2367 | self._cssSelector(fn, cssSel);
2368 | });
2369 |
2370 | // Set the GUI to the current state.
2371 | this._updateInterface();
2372 | this._updateButtons();
2373 | this._updateAutohide();
2374 | this._updateVolume();
2375 | this._updateMute();
2376 | },
2377 | _cssSelector: function(fn, cssSel) {
2378 | var self = this;
2379 | if(typeof cssSel === 'string') {
2380 | if($.jPlayer.prototype.options.cssSelector[fn]) {
2381 | if(this.css.jq[fn] && this.css.jq[fn].length) {
2382 | this.css.jq[fn].unbind(".jPlayer");
2383 | }
2384 | this.options.cssSelector[fn] = cssSel;
2385 | this.css.cs[fn] = this.options.cssSelectorAncestor + " " + cssSel;
2386 |
2387 | if(cssSel) { // Checks for empty string
2388 | this.css.jq[fn] = $(this.css.cs[fn]);
2389 | } else {
2390 | 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.
2391 | }
2392 |
2393 | if(this.css.jq[fn].length && this[fn]) {
2394 | var handler = function(e) {
2395 | e.preventDefault();
2396 | self[fn](e);
2397 | if(self.options.autoBlur) {
2398 | $(this).blur();
2399 | } else {
2400 | $(this).focus(); // Force focus for ARIA.
2401 | }
2402 | };
2403 | this.css.jq[fn].bind("click.jPlayer", handler); // Using jPlayer namespace
2404 | }
2405 |
2406 | if(cssSel && this.css.jq[fn].length !== 1) { // So empty strings do not generate the warning. ie., they just remove the old one.
2407 | this._warning( {
2408 | type: $.jPlayer.warning.CSS_SELECTOR_COUNT,
2409 | context: this.css.cs[fn],
2410 | message: $.jPlayer.warningMsg.CSS_SELECTOR_COUNT + this.css.jq[fn].length + " found for " + fn + " method.",
2411 | hint: $.jPlayer.warningHint.CSS_SELECTOR_COUNT
2412 | });
2413 | }
2414 | } else {
2415 | this._warning( {
2416 | type: $.jPlayer.warning.CSS_SELECTOR_METHOD,
2417 | context: fn,
2418 | message: $.jPlayer.warningMsg.CSS_SELECTOR_METHOD,
2419 | hint: $.jPlayer.warningHint.CSS_SELECTOR_METHOD
2420 | });
2421 | }
2422 | } else {
2423 | this._warning( {
2424 | type: $.jPlayer.warning.CSS_SELECTOR_STRING,
2425 | context: cssSel,
2426 | message: $.jPlayer.warningMsg.CSS_SELECTOR_STRING,
2427 | hint: $.jPlayer.warningHint.CSS_SELECTOR_STRING
2428 | });
2429 | }
2430 | },
2431 | duration: function(e) {
2432 | if(this.options.toggleDuration) {
2433 | if(this.options.captureDuration) {
2434 | e.stopPropagation();
2435 | }
2436 | this._setOption("remainingDuration", !this.options.remainingDuration);
2437 | }
2438 | },
2439 | seekBar: function(e) { // Handles clicks on the seekBar
2440 | if(this.css.jq.seekBar.length) {
2441 | // Using $(e.currentTarget) to enable multiple seek bars
2442 | var $bar = $(e.currentTarget),
2443 | offset = $bar.offset(),
2444 | x = e.pageX - offset.left,
2445 | w = $bar.width(),
2446 | p = 100 * x / w;
2447 | this.playHead(p);
2448 | }
2449 | },
2450 | playbackRate: function(pbr) {
2451 | this._setOption("playbackRate", pbr);
2452 | },
2453 | playbackRateBar: function(e) { // Handles clicks on the playbackRateBar
2454 | if(this.css.jq.playbackRateBar.length) {
2455 | // Using $(e.currentTarget) to enable multiple playbackRate bars
2456 | var $bar = $(e.currentTarget),
2457 | offset = $bar.offset(),
2458 | x = e.pageX - offset.left,
2459 | w = $bar.width(),
2460 | y = $bar.height() - e.pageY + offset.top,
2461 | h = $bar.height(),
2462 | ratio, pbr;
2463 | if(this.options.verticalPlaybackRate) {
2464 | ratio = y/h;
2465 | } else {
2466 | ratio = x/w;
2467 | }
2468 | pbr = ratio * (this.options.maxPlaybackRate - this.options.minPlaybackRate) + this.options.minPlaybackRate;
2469 | this.playbackRate(pbr);
2470 | }
2471 | },
2472 | _updatePlaybackRate: function() {
2473 | var pbr = this.options.playbackRate,
2474 | ratio = (pbr - this.options.minPlaybackRate) / (this.options.maxPlaybackRate - this.options.minPlaybackRate);
2475 | if(this.status.playbackRateEnabled) {
2476 | if(this.css.jq.playbackRateBar.length) {
2477 | this.css.jq.playbackRateBar.show();
2478 | }
2479 | if(this.css.jq.playbackRateBarValue.length) {
2480 | this.css.jq.playbackRateBarValue.show();
2481 | this.css.jq.playbackRateBarValue[this.options.verticalPlaybackRate ? "height" : "width"]((ratio*100)+"%");
2482 | }
2483 | } else {
2484 | if(this.css.jq.playbackRateBar.length) {
2485 | this.css.jq.playbackRateBar.hide();
2486 | }
2487 | if(this.css.jq.playbackRateBarValue.length) {
2488 | this.css.jq.playbackRateBarValue.hide();
2489 | }
2490 | }
2491 | },
2492 | repeat: function(event) { // Handle clicks on the repeat button
2493 | var guiAction = typeof event === "object"; // Flags GUI click events so we know this was not a direct command, but an action taken by the user on the GUI.
2494 | if(guiAction && this.options.useStateClassSkin && this.options.loop) {
2495 | this._loop(false);
2496 | } else {
2497 | this._loop(true);
2498 | }
2499 | },
2500 | repeatOff: function() { // Handle clicks on the repeatOff button
2501 | this._loop(false);
2502 | },
2503 | _loop: function(loop) {
2504 | if(this.options.loop !== loop) {
2505 | this.options.loop = loop;
2506 | this._updateButtons();
2507 | this._trigger($.jPlayer.event.repeat);
2508 | }
2509 | },
2510 |
2511 | // 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.
2512 | option: function(key, value) {
2513 | var options = key;
2514 |
2515 | // Enables use: options(). Returns a copy of options object
2516 | if ( arguments.length === 0 ) {
2517 | return $.extend( true, {}, this.options );
2518 | }
2519 |
2520 | if(typeof key === "string") {
2521 | var keys = key.split(".");
2522 |
2523 | // Enables use: options("someOption") Returns a copy of the option. Supports dot notation.
2524 | if(value === undefined) {
2525 |
2526 | var opt = $.extend(true, {}, this.options);
2527 | for(var i = 0; i < keys.length; i++) {
2528 | if(opt[keys[i]] !== undefined) {
2529 | opt = opt[keys[i]];
2530 | } else {
2531 | this._warning( {
2532 | type: $.jPlayer.warning.OPTION_KEY,
2533 | context: key,
2534 | message: $.jPlayer.warningMsg.OPTION_KEY,
2535 | hint: $.jPlayer.warningHint.OPTION_KEY
2536 | });
2537 | return undefined;
2538 | }
2539 | }
2540 | return opt;
2541 | }
2542 |
2543 | // Enables use: options("someOptionObject", someObject}). Creates: {someOptionObject:someObject}
2544 | // Enables use: options("someOption", someValue). Creates: {someOption:someValue}
2545 | // Enables use: options("someOptionObject.someOption", someValue). Creates: {someOptionObject:{someOption:someValue}}
2546 |
2547 | options = {};
2548 | var opts = options;
2549 |
2550 | for(var j = 0; j < keys.length; j++) {
2551 | if(j < keys.length - 1) {
2552 | opts[keys[j]] = {};
2553 | opts = opts[keys[j]];
2554 | } else {
2555 | opts[keys[j]] = value;
2556 | }
2557 | }
2558 | }
2559 |
2560 | // Otherwise enables use: options(optionObject). Uses original object (the key)
2561 |
2562 | this._setOptions(options);
2563 |
2564 | return this;
2565 | },
2566 | _setOptions: function(options) {
2567 | var self = this;
2568 | $.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.
2569 | self._setOption(key, value);
2570 | });
2571 |
2572 | return this;
2573 | },
2574 | _setOption: function(key, value) {
2575 | var self = this;
2576 |
2577 | // The ability to set options is limited at this time.
2578 |
2579 | switch(key) {
2580 | case "volume" :
2581 | this.volume(value);
2582 | break;
2583 | case "muted" :
2584 | this._muted(value);
2585 | break;
2586 | case "globalVolume" :
2587 | this.options[key] = value;
2588 | break;
2589 | case "cssSelectorAncestor" :
2590 | this._cssSelectorAncestor(value); // Set and refresh all associations for the new ancestor.
2591 | break;
2592 | case "cssSelector" :
2593 | $.each(value, function(fn, cssSel) {
2594 | self._cssSelector(fn, cssSel); // NB: The option is set inside this function, after further validity checks.
2595 | });
2596 | break;
2597 | case "playbackRate" :
2598 | this.options[key] = value = this._limitValue(value, this.options.minPlaybackRate, this.options.maxPlaybackRate);
2599 | if(this.html.used) {
2600 | this._html_setProperty('playbackRate', value);
2601 | }
2602 | this._updatePlaybackRate();
2603 | break;
2604 | case "defaultPlaybackRate" :
2605 | this.options[key] = value = this._limitValue(value, this.options.minPlaybackRate, this.options.maxPlaybackRate);
2606 | if(this.html.used) {
2607 | this._html_setProperty('defaultPlaybackRate', value);
2608 | }
2609 | this._updatePlaybackRate();
2610 | break;
2611 | case "minPlaybackRate" :
2612 | this.options[key] = value = this._limitValue(value, 0.1, this.options.maxPlaybackRate - 0.1);
2613 | this._updatePlaybackRate();
2614 | break;
2615 | case "maxPlaybackRate" :
2616 | this.options[key] = value = this._limitValue(value, this.options.minPlaybackRate + 0.1, 16);
2617 | this._updatePlaybackRate();
2618 | break;
2619 | case "fullScreen" :
2620 | if(this.options[key] !== value) { // if changed
2621 | var wkv = $.jPlayer.nativeFeatures.fullscreen.used.webkitVideo;
2622 | if(!wkv || wkv && !this.status.waitForPlay) {
2623 | if(!wkv) { // No sensible way to unset option on these devices.
2624 | this.options[key] = value;
2625 | }
2626 | if(value) {
2627 | this._requestFullscreen();
2628 | } else {
2629 | this._exitFullscreen();
2630 | }
2631 | if(!wkv) {
2632 | this._setOption("fullWindow", value);
2633 | }
2634 | }
2635 | }
2636 | break;
2637 | case "fullWindow" :
2638 | if(this.options[key] !== value) { // if changed
2639 | this._removeUiClass();
2640 | this.options[key] = value;
2641 | this._refreshSize();
2642 | }
2643 | break;
2644 | case "size" :
2645 | if(!this.options.fullWindow && this.options[key].cssClass !== value.cssClass) {
2646 | this._removeUiClass();
2647 | }
2648 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2649 | this._refreshSize();
2650 | break;
2651 | case "sizeFull" :
2652 | if(this.options.fullWindow && this.options[key].cssClass !== value.cssClass) {
2653 | this._removeUiClass();
2654 | }
2655 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2656 | this._refreshSize();
2657 | break;
2658 | case "autohide" :
2659 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2660 | this._updateAutohide();
2661 | break;
2662 | case "loop" :
2663 | this._loop(value);
2664 | break;
2665 | case "remainingDuration" :
2666 | this.options[key] = value;
2667 | this._updateInterface();
2668 | break;
2669 | case "toggleDuration" :
2670 | this.options[key] = value;
2671 | break;
2672 | case "nativeVideoControls" :
2673 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2674 | this.status.nativeVideoControls = this._uaBlocklist(this.options.nativeVideoControls);
2675 | this._restrictNativeVideoControls();
2676 | this._updateNativeVideoControls();
2677 | break;
2678 | case "noFullWindow" :
2679 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2680 | this.status.nativeVideoControls = this._uaBlocklist(this.options.nativeVideoControls); // Need to check again as noFullWindow can depend on this flag and the restrict() can override it.
2681 | this.status.noFullWindow = this._uaBlocklist(this.options.noFullWindow);
2682 | this._restrictNativeVideoControls();
2683 | this._updateButtons();
2684 | break;
2685 | case "noVolume" :
2686 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2687 | this.status.noVolume = this._uaBlocklist(this.options.noVolume);
2688 | this._updateVolume();
2689 | this._updateMute();
2690 | break;
2691 | case "emulateHtml" :
2692 | if(this.options[key] !== value) { // To avoid multiple event handlers being created, if true already.
2693 | this.options[key] = value;
2694 | if(value) {
2695 | this._emulateHtmlBridge();
2696 | } else {
2697 | this._destroyHtmlBridge();
2698 | }
2699 | }
2700 | break;
2701 | case "timeFormat" :
2702 | this.options[key] = $.extend({}, this.options[key], value); // store a merged copy of it, incase not all properties changed.
2703 | break;
2704 | case "keyEnabled" :
2705 | this.options[key] = value;
2706 | if(!value && this === $.jPlayer.focus) {
2707 | $.jPlayer.focus = null;
2708 | }
2709 | break;
2710 | case "keyBindings" :
2711 | this.options[key] = $.extend(true, {}, this.options[key], value); // store a merged DEEP copy of it, incase not all properties changed.
2712 | break;
2713 | case "audioFullScreen" :
2714 | this.options[key] = value;
2715 | break;
2716 | case "autoBlur" :
2717 | this.options[key] = value;
2718 | break;
2719 | }
2720 |
2721 | return this;
2722 | },
2723 | // End of: (Options code adapted from ui.widget.js)
2724 |
2725 | _refreshSize: function() {
2726 | this._setSize(); // update status and jPlayer element size
2727 | this._addUiClass(); // update the ui class
2728 | this._updateSize(); // update internal sizes
2729 | this._updateButtons();
2730 | this._updateAutohide();
2731 | this._trigger($.jPlayer.event.resize);
2732 | },
2733 | _setSize: function() {
2734 | // Determine the current size from the options
2735 | if(this.options.fullWindow) {
2736 | this.status.width = this.options.sizeFull.width;
2737 | this.status.height = this.options.sizeFull.height;
2738 | this.status.cssClass = this.options.sizeFull.cssClass;
2739 | } else {
2740 | this.status.width = this.options.size.width;
2741 | this.status.height = this.options.size.height;
2742 | this.status.cssClass = this.options.size.cssClass;
2743 | }
2744 |
2745 | // Set the size of the jPlayer area.
2746 | this.element.css({'width': this.status.width, 'height': this.status.height});
2747 | },
2748 | _addUiClass: function() {
2749 | if(this.ancestorJq.length) {
2750 | this.ancestorJq.addClass(this.status.cssClass);
2751 | }
2752 | },
2753 | _removeUiClass: function() {
2754 | if(this.ancestorJq.length) {
2755 | this.ancestorJq.removeClass(this.status.cssClass);
2756 | }
2757 | },
2758 | _updateSize: function() {
2759 | // The poster uses show/hide so can simply resize it.
2760 | this.internal.poster.jq.css({'width': this.status.width, 'height': this.status.height});
2761 |
2762 | // Video html or flash resized if necessary at this time, or if native video controls being used.
2763 | if(!this.status.waitForPlay && this.html.active && this.status.video || this.html.video.available && this.html.used && this.status.nativeVideoControls) {
2764 | this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
2765 | }
2766 | else if(!this.status.waitForPlay && this.flash.active && this.status.video) {
2767 | this.internal.flash.jq.css({'width': this.status.width, 'height': this.status.height});
2768 | }
2769 | },
2770 | _updateAutohide: function() {
2771 | var self = this,
2772 | event = "mousemove.jPlayer",
2773 | namespace = ".jPlayerAutohide",
2774 | eventType = event + namespace,
2775 | handler = function(event) {
2776 | var moved = false,
2777 | deltaX, deltaY;
2778 | if(typeof self.internal.mouse !== "undefined") {
2779 | //get the change from last position to this position
2780 | deltaX = self.internal.mouse.x - event.pageX;
2781 | deltaY = self.internal.mouse.y - event.pageY;
2782 | moved = (Math.floor(deltaX) > 0) || (Math.floor(deltaY)>0);
2783 | } else {
2784 | moved = true;
2785 | }
2786 | // store current position for next method execution
2787 | self.internal.mouse = {
2788 | x : event.pageX,
2789 | y : event.pageY
2790 | };
2791 | // if mouse has been actually moved, do the gui fadeIn/fadeOut
2792 | if (moved) {
2793 | self.css.jq.gui.fadeIn(self.options.autohide.fadeIn, function() {
2794 | clearTimeout(self.internal.autohideId);
2795 | self.internal.autohideId = setTimeout( function() {
2796 | self.css.jq.gui.fadeOut(self.options.autohide.fadeOut);
2797 | }, self.options.autohide.hold);
2798 | });
2799 | }
2800 | };
2801 |
2802 | if(this.css.jq.gui.length) {
2803 |
2804 | // End animations first so that its callback is executed now.
2805 | // Otherwise an in progress fadeIn animation still has the callback to fadeOut again.
2806 | this.css.jq.gui.stop(true, true);
2807 |
2808 | // Removes the fadeOut operation from the fadeIn callback.
2809 | clearTimeout(this.internal.autohideId);
2810 | // undefine mouse
2811 | delete this.internal.mouse;
2812 |
2813 | this.element.unbind(namespace);
2814 | this.css.jq.gui.unbind(namespace);
2815 |
2816 | if(!this.status.nativeVideoControls) {
2817 | if(this.options.fullWindow && this.options.autohide.full || !this.options.fullWindow && this.options.autohide.restored) {
2818 | this.element.bind(eventType, handler);
2819 | this.css.jq.gui.bind(eventType, handler);
2820 | this.css.jq.gui.hide();
2821 | } else {
2822 | this.css.jq.gui.show();
2823 | }
2824 | } else {
2825 | this.css.jq.gui.hide();
2826 | }
2827 | }
2828 | },
2829 | fullScreen: function(event) {
2830 | var guiAction = typeof event === "object"; // Flags GUI click events so we know this was not a direct command, but an action taken by the user on the GUI.
2831 | if(guiAction && this.options.useStateClassSkin && this.options.fullScreen) {
2832 | this._setOption("fullScreen", false);
2833 | } else {
2834 | this._setOption("fullScreen", true);
2835 | }
2836 | },
2837 | restoreScreen: function() {
2838 | this._setOption("fullScreen", false);
2839 | },
2840 | _fullscreenAddEventListeners: function() {
2841 | var self = this,
2842 | fs = $.jPlayer.nativeFeatures.fullscreen;
2843 |
2844 | if(fs.api.fullscreenEnabled) {
2845 | if(fs.event.fullscreenchange) {
2846 | // Create the event handler function and store it for removal.
2847 | if(typeof this.internal.fullscreenchangeHandler !== 'function') {
2848 | this.internal.fullscreenchangeHandler = function() {
2849 | self._fullscreenchange();
2850 | };
2851 | }
2852 | document.addEventListener(fs.event.fullscreenchange, this.internal.fullscreenchangeHandler, false);
2853 | }
2854 | // No point creating handler for fullscreenerror.
2855 | // Either logic avoids fullscreen occurring (w3c/moz), or their is no event on the browser (webkit).
2856 | }
2857 | },
2858 | _fullscreenRemoveEventListeners: function() {
2859 | var fs = $.jPlayer.nativeFeatures.fullscreen;
2860 | if(this.internal.fullscreenchangeHandler) {
2861 | document.removeEventListener(fs.event.fullscreenchange, this.internal.fullscreenchangeHandler, false);
2862 | }
2863 | },
2864 | _fullscreenchange: function() {
2865 | // If nothing is fullscreen, then we cannot be in fullscreen mode.
2866 | if(this.options.fullScreen && !$.jPlayer.nativeFeatures.fullscreen.api.fullscreenElement()) {
2867 | this._setOption("fullScreen", false);
2868 | }
2869 | },
2870 | _requestFullscreen: function() {
2871 | // Either the container or the jPlayer div
2872 | var e = this.ancestorJq.length ? this.ancestorJq[0] : this.element[0],
2873 | fs = $.jPlayer.nativeFeatures.fullscreen;
2874 |
2875 | // This method needs the video element. For iOS and Android.
2876 | if(fs.used.webkitVideo) {
2877 | e = this.htmlElement.video;
2878 | }
2879 |
2880 | if(fs.api.fullscreenEnabled) {
2881 | fs.api.requestFullscreen(e);
2882 | }
2883 | },
2884 | _exitFullscreen: function() {
2885 |
2886 | var fs = $.jPlayer.nativeFeatures.fullscreen,
2887 | e;
2888 |
2889 | // This method needs the video element. For iOS and Android.
2890 | if(fs.used.webkitVideo) {
2891 | e = this.htmlElement.video;
2892 | }
2893 |
2894 | if(fs.api.fullscreenEnabled) {
2895 | fs.api.exitFullscreen(e);
2896 | }
2897 | },
2898 | _html_initMedia: function(media) {
2899 | // Remove any existing track elements
2900 | var $media = $(this.htmlElement.media).empty();
2901 |
2902 | // Create any track elements given with the media, as an Array of track Objects.
2903 | $.each(media.track || [], function(i,v) {
2904 | var track = document.createElement('track');
2905 | track.setAttribute("kind", v.kind ? v.kind : "");
2906 | track.setAttribute("src", v.src ? v.src : "");
2907 | track.setAttribute("srclang", v.srclang ? v.srclang : "");
2908 | track.setAttribute("label", v.label ? v.label : "");
2909 | if(v.def) {
2910 | track.setAttribute("default", v.def);
2911 | }
2912 | $media.append(track);
2913 | });
2914 |
2915 | this.htmlElement.media.src = this.status.src;
2916 |
2917 | if(this.options.preload !== 'none') {
2918 | this._html_load(); // See function for comments
2919 | }
2920 | this._trigger($.jPlayer.event.timeupdate); // The flash generates this event for its solution.
2921 | },
2922 | _html_setFormat: function(media) {
2923 | var self = this;
2924 | // Always finds a format due to checks in setMedia()
2925 | $.each(this.formats, function(priority, format) {
2926 | if(self.html.support[format] && media[format]) {
2927 | self.status.src = media[format];
2928 | self.status.format[format] = true;
2929 | self.status.formatType = format;
2930 | return false;
2931 | }
2932 | });
2933 | },
2934 | _html_setAudio: function(media) {
2935 | this._html_setFormat(media);
2936 | this.htmlElement.media = this.htmlElement.audio;
2937 | this._html_initMedia(media);
2938 | },
2939 | _html_setVideo: function(media) {
2940 | this._html_setFormat(media);
2941 | if(this.status.nativeVideoControls) {
2942 | this.htmlElement.video.poster = this._validString(media.poster) ? media.poster : "";
2943 | }
2944 | this.htmlElement.media = this.htmlElement.video;
2945 | this._html_initMedia(media);
2946 | },
2947 | _html_resetMedia: function() {
2948 | if(this.htmlElement.media) {
2949 | if(this.htmlElement.media.id === this.internal.video.id && !this.status.nativeVideoControls) {
2950 | this.internal.video.jq.css({'width':'0px', 'height':'0px'});
2951 | }
2952 | this.htmlElement.media.pause();
2953 | }
2954 | },
2955 | _html_clearMedia: function() {
2956 | if(this.htmlElement.media) {
2957 | this.htmlElement.media.src = "about:blank";
2958 | // The following load() is only required for Firefox 3.6 (PowerMacs).
2959 | // Recent HTMl5 browsers only require the src change. Due to changes in W3C spec and load() effect.
2960 | 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.
2961 | }
2962 | },
2963 | _html_load: function() {
2964 | // This function remains to allow the early HTML5 browsers to work, such as Firefox 3.6
2965 | // A change in the W3C spec for the media.load() command means that this is no longer necessary.
2966 | // 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.
2967 | if(this.status.waitForLoad) {
2968 | this.status.waitForLoad = false;
2969 | this.htmlElement.media.load();
2970 | }
2971 | clearTimeout(this.internal.htmlDlyCmdId);
2972 | },
2973 | _html_play: function(time) {
2974 | var self = this,
2975 | media = this.htmlElement.media;
2976 |
2977 | this.androidFix.pause = false; // Cancel the pause fix.
2978 |
2979 | this._html_load(); // Loads if required and clears any delayed commands.
2980 |
2981 | // Setup the Android Fix.
2982 | if(this.androidFix.setMedia) {
2983 | this.androidFix.play = true;
2984 | this.androidFix.time = time;
2985 |
2986 | } else if(!isNaN(time)) {
2987 |
2988 | // Attempt to play it, since iOS has been ignoring commands
2989 | if(this.internal.cmdsIgnored) {
2990 | media.play();
2991 | }
2992 |
2993 | try {
2994 | // !media.seekable is for old HTML5 browsers, like Firefox 3.6.
2995 | // Checking seekable.length is important for iOS6 to work with setMedia().play(time)
2996 | if(!media.seekable || typeof media.seekable === "object" && media.seekable.length > 0) {
2997 | media.currentTime = time;
2998 | media.play();
2999 | } else {
3000 | throw 1;
3001 | }
3002 | } catch(err) {
3003 | this.internal.htmlDlyCmdId = setTimeout(function() {
3004 | self.play(time);
3005 | }, 250);
3006 | return; // Cancel execution and wait for the delayed command.
3007 | }
3008 | } else {
3009 | media.play();
3010 | }
3011 | this._html_checkWaitForPlay();
3012 | },
3013 | _html_pause: function(time) {
3014 | var self = this,
3015 | media = this.htmlElement.media;
3016 |
3017 | this.androidFix.play = false; // Cancel the play fix.
3018 |
3019 | if(time > 0) { // We do not want the stop() command, which does pause(0), causing a load operation.
3020 | this._html_load(); // Loads if required and clears any delayed commands.
3021 | } else {
3022 | clearTimeout(this.internal.htmlDlyCmdId);
3023 | }
3024 |
3025 | // Order of these commands is important for Safari (Win) and IE9. Pause then change currentTime.
3026 | media.pause();
3027 |
3028 | // Setup the Android Fix.
3029 | if(this.androidFix.setMedia) {
3030 | this.androidFix.pause = true;
3031 | this.androidFix.time = time;
3032 |
3033 | } else if(!isNaN(time)) {
3034 | try {
3035 | if(!media.seekable || typeof media.seekable === "object" && media.seekable.length > 0) {
3036 | media.currentTime = time;
3037 | } else {
3038 | throw 1;
3039 | }
3040 | } catch(err) {
3041 | this.internal.htmlDlyCmdId = setTimeout(function() {
3042 | self.pause(time);
3043 | }, 250);
3044 | return; // Cancel execution and wait for the delayed command.
3045 | }
3046 | }
3047 | if(time > 0) { // Avoids a setMedia() followed by stop() or pause(0) hiding the video play button.
3048 | this._html_checkWaitForPlay();
3049 | }
3050 | },
3051 | _html_playHead: function(percent) {
3052 | var self = this,
3053 | media = this.htmlElement.media;
3054 |
3055 | this._html_load(); // Loads if required and clears any delayed commands.
3056 |
3057 | // This playHead() method needs a refactor to apply the android fix.
3058 |
3059 | try {
3060 | if(typeof media.seekable === "object" && media.seekable.length > 0) {
3061 | media.currentTime = percent * media.seekable.end(media.seekable.length-1) / 100;
3062 | } else if(media.duration > 0 && !isNaN(media.duration)) {
3063 | media.currentTime = percent * media.duration / 100;
3064 | } else {
3065 | throw "e";
3066 | }
3067 | } catch(err) {
3068 | this.internal.htmlDlyCmdId = setTimeout(function() {
3069 | self.playHead(percent);
3070 | }, 250);
3071 | return; // Cancel execution and wait for the delayed command.
3072 | }
3073 | if(!this.status.waitForLoad) {
3074 | this._html_checkWaitForPlay();
3075 | }
3076 | },
3077 | _html_checkWaitForPlay: function() {
3078 | if(this.status.waitForPlay) {
3079 | this.status.waitForPlay = false;
3080 | if(this.css.jq.videoPlay.length) {
3081 | this.css.jq.videoPlay.hide();
3082 | }
3083 | if(this.status.video) {
3084 | this.internal.poster.jq.hide();
3085 | this.internal.video.jq.css({'width': this.status.width, 'height': this.status.height});
3086 | }
3087 | }
3088 | },
3089 | _html_setProperty: function(property, value) {
3090 | if(this.html.audio.available) {
3091 | this.htmlElement.audio[property] = value;
3092 | }
3093 | if(this.html.video.available) {
3094 | this.htmlElement.video[property] = value;
3095 | }
3096 | },
3097 | _aurora_setAudio: function(media) {
3098 | var self = this;
3099 |
3100 | // Always finds a format due to checks in setMedia()
3101 | $.each(this.formats, function(priority, format) {
3102 | if(self.aurora.support[format] && media[format]) {
3103 | self.status.src = media[format];
3104 | self.status.format[format] = true;
3105 | self.status.formatType = format;
3106 |
3107 | return false;
3108 | }
3109 | });
3110 |
3111 | this.aurora.player = new AV.Player.fromURL(this.status.src);
3112 | this._addAuroraEventListeners(this.aurora.player, this.aurora);
3113 |
3114 | if(this.options.preload === 'auto') {
3115 | this._aurora_load();
3116 | this.status.waitForLoad = false;
3117 | }
3118 | },
3119 | _aurora_resetMedia: function() {
3120 | if (this.aurora.player) {
3121 | this.aurora.player.stop();
3122 | }
3123 | },
3124 | _aurora_clearMedia: function() {
3125 | // Nothing to clear.
3126 | },
3127 | _aurora_load: function() {
3128 | if(this.status.waitForLoad) {
3129 | this.status.waitForLoad = false;
3130 | this.aurora.player.preload();
3131 | }
3132 | },
3133 | _aurora_play: function(time) {
3134 | if (!this.status.waitForLoad) {
3135 | if (!isNaN(time)) {
3136 | this.aurora.player.seek(time);
3137 | }
3138 | }
3139 | if (!this.aurora.player.playing) {
3140 | this.aurora.player.play();
3141 | }
3142 | this.status.waitForLoad = false;
3143 | this._aurora_checkWaitForPlay();
3144 |
3145 | // No event from the player, update UI now.
3146 | this._updateButtons(true);
3147 | this._trigger($.jPlayer.event.play);
3148 | },
3149 | _aurora_pause: function(time) {
3150 | if (!isNaN(time)) {
3151 | this.aurora.player.seek(time * 1000);
3152 | }
3153 | this.aurora.player.pause();
3154 |
3155 | if(time > 0) { // Avoids a setMedia() followed by stop() or pause(0) hiding the video play button.
3156 | this._aurora_checkWaitForPlay();
3157 | }
3158 |
3159 | // No event from the player, update UI now.
3160 | this._updateButtons(false);
3161 | this._trigger($.jPlayer.event.pause);
3162 | },
3163 | _aurora_playHead: function(percent) {
3164 | if(this.aurora.player.duration > 0) {
3165 | // The seek() sould be in milliseconds, but the only codec that works with seek (aac.js) uses seconds.
3166 | this.aurora.player.seek(percent * this.aurora.player.duration / 100); // Using seconds
3167 | }
3168 |
3169 | if(!this.status.waitForLoad) {
3170 | this._aurora_checkWaitForPlay();
3171 | }
3172 | },
3173 | _aurora_checkWaitForPlay: function() {
3174 | if(this.status.waitForPlay) {
3175 | this.status.waitForPlay = false;
3176 | }
3177 | },
3178 | _aurora_volume: function(v) {
3179 | this.aurora.player.volume = v * 100;
3180 | },
3181 | _aurora_mute: function(m) {
3182 | if (m) {
3183 | this.aurora.properties.lastvolume = this.aurora.player.volume;
3184 | this.aurora.player.volume = 0;
3185 | } else {
3186 | this.aurora.player.volume = this.aurora.properties.lastvolume;
3187 | }
3188 | this.aurora.properties.muted = m;
3189 | },
3190 | _flash_setAudio: function(media) {
3191 | var self = this;
3192 | try {
3193 | // Always finds a format due to checks in setMedia()
3194 | $.each(this.formats, function(priority, format) {
3195 | if(self.flash.support[format] && media[format]) {
3196 | switch (format) {
3197 | case "m4a" :
3198 | case "fla" :
3199 | self._getMovie().fl_setAudio_m4a(media[format]);
3200 | break;
3201 | case "mp3" :
3202 | self._getMovie().fl_setAudio_mp3(media[format]);
3203 | break;
3204 | case "rtmpa":
3205 | self._getMovie().fl_setAudio_rtmp(media[format]);
3206 | break;
3207 | }
3208 | self.status.src = media[format];
3209 | self.status.format[format] = true;
3210 | self.status.formatType = format;
3211 | return false;
3212 | }
3213 | });
3214 |
3215 | if(this.options.preload === 'auto') {
3216 | this._flash_load();
3217 | this.status.waitForLoad = false;
3218 | }
3219 | } catch(err) { this._flashError(err); }
3220 | },
3221 | _flash_setVideo: function(media) {
3222 | var self = this;
3223 | try {
3224 | // Always finds a format due to checks in setMedia()
3225 | $.each(this.formats, function(priority, format) {
3226 | if(self.flash.support[format] && media[format]) {
3227 | switch (format) {
3228 | case "m4v" :
3229 | case "flv" :
3230 | self._getMovie().fl_setVideo_m4v(media[format]);
3231 | break;
3232 | case "rtmpv":
3233 | self._getMovie().fl_setVideo_rtmp(media[format]);
3234 | break;
3235 | }
3236 | self.status.src = media[format];
3237 | self.status.format[format] = true;
3238 | self.status.formatType = format;
3239 | return false;
3240 | }
3241 | });
3242 |
3243 | if(this.options.preload === 'auto') {
3244 | this._flash_load();
3245 | this.status.waitForLoad = false;
3246 | }
3247 | } catch(err) { this._flashError(err); }
3248 | },
3249 | _flash_resetMedia: function() {
3250 | this.internal.flash.jq.css({'width':'0px', 'height':'0px'}); // Must do via CSS as setting attr() to zero causes a jQuery error in IE.
3251 | this._flash_pause(NaN);
3252 | },
3253 | _flash_clearMedia: function() {
3254 | try {
3255 | this._getMovie().fl_clearMedia();
3256 | } catch(err) { this._flashError(err); }
3257 | },
3258 | _flash_load: function() {
3259 | try {
3260 | this._getMovie().fl_load();
3261 | } catch(err) { this._flashError(err); }
3262 | this.status.waitForLoad = false;
3263 | },
3264 | _flash_play: function(time) {
3265 | try {
3266 | this._getMovie().fl_play(time);
3267 | } catch(err) { this._flashError(err); }
3268 | this.status.waitForLoad = false;
3269 | this._flash_checkWaitForPlay();
3270 | },
3271 | _flash_pause: function(time) {
3272 | try {
3273 | this._getMovie().fl_pause(time);
3274 | } catch(err) { this._flashError(err); }
3275 | if(time > 0) { // Avoids a setMedia() followed by stop() or pause(0) hiding the video play button.
3276 | this.status.waitForLoad = false;
3277 | this._flash_checkWaitForPlay();
3278 | }
3279 | },
3280 | _flash_playHead: function(p) {
3281 | try {
3282 | this._getMovie().fl_play_head(p);
3283 | } catch(err) { this._flashError(err); }
3284 | if(!this.status.waitForLoad) {
3285 | this._flash_checkWaitForPlay();
3286 | }
3287 | },
3288 | _flash_checkWaitForPlay: function() {
3289 | if(this.status.waitForPlay) {
3290 | this.status.waitForPlay = false;
3291 | if(this.css.jq.videoPlay.length) {
3292 | this.css.jq.videoPlay.hide();
3293 | }
3294 | if(this.status.video) {
3295 | this.internal.poster.jq.hide();
3296 | this.internal.flash.jq.css({'width': this.status.width, 'height': this.status.height});
3297 | }
3298 | }
3299 | },
3300 | _flash_volume: function(v) {
3301 | try {
3302 | this._getMovie().fl_volume(v);
3303 | } catch(err) { this._flashError(err); }
3304 | },
3305 | _flash_mute: function(m) {
3306 | try {
3307 | this._getMovie().fl_mute(m);
3308 | } catch(err) { this._flashError(err); }
3309 | },
3310 | _getMovie: function() {
3311 | return document[this.internal.flash.id];
3312 | },
3313 | _getFlashPluginVersion: function() {
3314 |
3315 | // _getFlashPluginVersion() code influenced by:
3316 | // - FlashReplace 1.01: http://code.google.com/p/flashreplace/
3317 | // - SWFObject 2.2: http://code.google.com/p/swfobject/
3318 |
3319 | var version = 0,
3320 | flash;
3321 | if(window.ActiveXObject) {
3322 | try {
3323 | flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
3324 | if (flash) { // flash will return null when ActiveX is disabled
3325 | var v = flash.GetVariable("$version");
3326 | if(v) {
3327 | v = v.split(" ")[1].split(",");
3328 | version = parseInt(v[0], 10) + "." + parseInt(v[1], 10);
3329 | }
3330 | }
3331 | } catch(e) {}
3332 | }
3333 | else if(navigator.plugins && navigator.mimeTypes.length > 0) {
3334 | flash = navigator.plugins["Shockwave Flash"];
3335 | if(flash) {
3336 | version = navigator.plugins["Shockwave Flash"].description.replace(/.*\s(\d+\.\d+).*/, "$1");
3337 | }
3338 | }
3339 | return version * 1; // Converts to a number
3340 | },
3341 | _checkForFlash: function (version) {
3342 | var flashOk = false;
3343 | if(this._getFlashPluginVersion() >= version) {
3344 | flashOk = true;
3345 | }
3346 | return flashOk;
3347 | },
3348 | _validString: function(url) {
3349 | return (url && typeof url === "string"); // Empty strings return false
3350 | },
3351 | _limitValue: function(value, min, max) {
3352 | return (value < min) ? min : ((value > max) ? max : value);
3353 | },
3354 | _urlNotSetError: function(context) {
3355 | this._error( {
3356 | type: $.jPlayer.error.URL_NOT_SET,
3357 | context: context,
3358 | message: $.jPlayer.errorMsg.URL_NOT_SET,
3359 | hint: $.jPlayer.errorHint.URL_NOT_SET
3360 | });
3361 | },
3362 | _flashError: function(error) {
3363 | var errorType;
3364 | if(!this.internal.ready) {
3365 | errorType = "FLASH";
3366 | } else {
3367 | errorType = "FLASH_DISABLED";
3368 | }
3369 | this._error( {
3370 | type: $.jPlayer.error[errorType],
3371 | context: this.internal.flash.swf,
3372 | message: $.jPlayer.errorMsg[errorType] + error.message,
3373 | hint: $.jPlayer.errorHint[errorType]
3374 | });
3375 | // Allow the audio player to recover if display:none and then shown again, or with position:fixed on Firefox.
3376 | // This really only affects audio in a media player, as an audio player could easily move the jPlayer element away from such issues.
3377 | this.internal.flash.jq.css({'width':'1px', 'height':'1px'});
3378 | },
3379 | _error: function(error) {
3380 | this._trigger($.jPlayer.event.error, error);
3381 | if(this.options.errorAlerts) {
3382 | this._alert("Error!" + (error.message ? "\n" + error.message : "") + (error.hint ? "\n" + error.hint : "") + "\nContext: " + error.context);
3383 | }
3384 | },
3385 | _warning: function(warning) {
3386 | this._trigger($.jPlayer.event.warning, undefined, warning);
3387 | if(this.options.warningAlerts) {
3388 | this._alert("Warning!" + (warning.message ? "\n" + warning.message : "") + (warning.hint ? "\n" + warning.hint : "") + "\nContext: " + warning.context);
3389 | }
3390 | },
3391 | _alert: function(message) {
3392 | var msg = "jPlayer " + this.version.script + " : id='" + this.internal.self.id +"' : " + message;
3393 | if(!this.options.consoleAlerts) {
3394 | alert(msg);
3395 | } else if(window.console && window.console.log) {
3396 | window.console.log(msg);
3397 | }
3398 | },
3399 | _emulateHtmlBridge: function() {
3400 | var self = this;
3401 |
3402 | // Emulate methods on jPlayer's DOM element.
3403 | $.each( $.jPlayer.emulateMethods.split(/\s+/g), function(i, name) {
3404 | self.internal.domNode[name] = function(arg) {
3405 | self[name](arg);
3406 | };
3407 |
3408 | });
3409 |
3410 | // Bubble jPlayer events to its DOM element.
3411 | $.each($.jPlayer.event, function(eventName,eventType) {
3412 | var nativeEvent = true;
3413 | $.each( $.jPlayer.reservedEvent.split(/\s+/g), function(i, name) {
3414 | if(name === eventName) {
3415 | nativeEvent = false;
3416 | return false;
3417 | }
3418 | });
3419 | if(nativeEvent) {
3420 | self.element.bind(eventType + ".jPlayer.jPlayerHtml", function() { // With .jPlayer & .jPlayerHtml namespaces.
3421 | self._emulateHtmlUpdate();
3422 | var domEvent = document.createEvent("Event");
3423 | domEvent.initEvent(eventName, false, true);
3424 | self.internal.domNode.dispatchEvent(domEvent);
3425 | });
3426 | }
3427 | // The error event would require a special case
3428 | });
3429 |
3430 | // 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.
3431 | },
3432 | _emulateHtmlUpdate: function() {
3433 | var self = this;
3434 |
3435 | $.each( $.jPlayer.emulateStatus.split(/\s+/g), function(i, name) {
3436 | self.internal.domNode[name] = self.status[name];
3437 | });
3438 | $.each( $.jPlayer.emulateOptions.split(/\s+/g), function(i, name) {
3439 | self.internal.domNode[name] = self.options[name];
3440 | });
3441 | },
3442 | _destroyHtmlBridge: function() {
3443 | var self = this;
3444 |
3445 | // Bridge event handlers are also removed by destroy() through .jPlayer namespace.
3446 | this.element.unbind(".jPlayerHtml"); // Remove all event handlers created by the jPlayer bridge. So you can change the emulateHtml option.
3447 |
3448 | // Remove the methods and properties
3449 | var emulated = $.jPlayer.emulateMethods + " " + $.jPlayer.emulateStatus + " " + $.jPlayer.emulateOptions;
3450 | $.each( emulated.split(/\s+/g), function(i, name) {
3451 | delete self.internal.domNode[name];
3452 | });
3453 | }
3454 | };
3455 |
3456 | $.jPlayer.error = {
3457 | FLASH: "e_flash",
3458 | FLASH_DISABLED: "e_flash_disabled",
3459 | NO_SOLUTION: "e_no_solution",
3460 | NO_SUPPORT: "e_no_support",
3461 | URL: "e_url",
3462 | URL_NOT_SET: "e_url_not_set",
3463 | VERSION: "e_version"
3464 | };
3465 |
3466 | $.jPlayer.errorMsg = {
3467 | FLASH: "jPlayer's Flash fallback is not configured correctly, or a command was issued before the jPlayer Ready event. Details: ", // Used in: _flashError()
3468 | FLASH_DISABLED: "jPlayer's Flash fallback has been disabled by the browser due to the CSS rules you have used. Details: ", // Used in: _flashError()
3469 | NO_SOLUTION: "No solution can be found by jPlayer in this browser. Neither HTML nor Flash can be used.", // Used in: _init()
3470 | NO_SUPPORT: "It is not possible to play any media format provided in setMedia() on this browser using your current options.", // Used in: setMedia()
3471 | URL: "Media URL could not be loaded.", // Used in: jPlayerFlashEvent() and _addHtmlEventListeners()
3472 | URL_NOT_SET: "Attempt to issue media playback commands, while no media url is set.", // Used in: load(), play(), pause(), stop() and playHead()
3473 | VERSION: "jPlayer " + $.jPlayer.prototype.version.script + " needs Jplayer.swf version " + $.jPlayer.prototype.version.needFlash + " but found " // Used in: jPlayerReady()
3474 | };
3475 |
3476 | $.jPlayer.errorHint = {
3477 | FLASH: "Check your swfPath option and that Jplayer.swf is there.",
3478 | FLASH_DISABLED: "Check that you have not display:none; the jPlayer entity or any ancestor.",
3479 | NO_SOLUTION: "Review the jPlayer options: support and supplied.",
3480 | NO_SUPPORT: "Video or audio formats defined in the supplied option are missing.",
3481 | URL: "Check media URL is valid.",
3482 | URL_NOT_SET: "Use setMedia() to set the media URL.",
3483 | VERSION: "Update jPlayer files."
3484 | };
3485 |
3486 | $.jPlayer.warning = {
3487 | CSS_SELECTOR_COUNT: "e_css_selector_count",
3488 | CSS_SELECTOR_METHOD: "e_css_selector_method",
3489 | CSS_SELECTOR_STRING: "e_css_selector_string",
3490 | OPTION_KEY: "e_option_key"
3491 | };
3492 |
3493 | $.jPlayer.warningMsg = {
3494 | CSS_SELECTOR_COUNT: "The number of css selectors found did not equal one: ",
3495 | CSS_SELECTOR_METHOD: "The methodName given in jPlayer('cssSelector') is not a valid jPlayer method.",
3496 | CSS_SELECTOR_STRING: "The methodCssSelector given in jPlayer('cssSelector') is not a String or is empty.",
3497 | OPTION_KEY: "The option requested in jPlayer('option') is undefined."
3498 | };
3499 |
3500 | $.jPlayer.warningHint = {
3501 | CSS_SELECTOR_COUNT: "Check your css selector and the ancestor.",
3502 | CSS_SELECTOR_METHOD: "Check your method name.",
3503 | CSS_SELECTOR_STRING: "Check your css selector is a string.",
3504 | OPTION_KEY: "Check your option name."
3505 | };
3506 | }));
3507 |
--------------------------------------------------------------------------------