").append(x.parseHTML(e)).find(r):e)}).complete(n&&function(e,t){s.each(n,o||[e.responseText,t,e])}),this},x.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){x.fn[t]=function(e){return this.on(t,e)}}),x.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:Ut,type:"GET",isLocal:Kt.test(Xt[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":sn,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":x.parseJSON,"text xml":x.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?cn(cn(e,x.ajaxSettings),t):cn(x.ajaxSettings,e)},ajaxPrefilter:un(rn),ajaxTransport:un(on),ajax:function(e,t){"object"==typeof e&&(t=e,e=undefined),t=t||{};var n,r,i,o,s,a,u,l,c=x.ajaxSetup({},t),p=c.context||c,f=c.context&&(p.nodeType||p.jquery)?x(p):x.event,h=x.Deferred(),d=x.Callbacks("once memory"),g=c.statusCode||{},m={},y={},v=0,b="canceled",T={readyState:0,getResponseHeader:function(e){var t;if(2===v){if(!o){o={};while(t=Qt.exec(i))o[t[1].toLowerCase()]=t[2]}t=o[e.toLowerCase()]}return null==t?null:t},getAllResponseHeaders:function(){return 2===v?i:null},setRequestHeader:function(e,t){var n=e.toLowerCase();return v||(e=y[n]=y[n]||e,m[e]=t),this},overrideMimeType:function(e){return v||(c.mimeType=e),this},statusCode:function(e){var t;if(e)if(2>v)for(t in e)g[t]=[g[t],e[t]];else T.always(e[T.status]);return this},abort:function(e){var t=e||b;return n&&n.abort(t),k(0,t),this}};if(h.promise(T).complete=d.add,T.success=T.done,T.error=T.fail,c.url=((e||c.url||Ut)+"").replace(Gt,"").replace(en,Xt[1]+"//"),c.type=t.method||t.type||c.method||c.type,c.dataTypes=x.trim(c.dataType||"*").toLowerCase().match(w)||[""],null==c.crossDomain&&(a=tn.exec(c.url.toLowerCase()),c.crossDomain=!(!a||a[1]===Xt[1]&&a[2]===Xt[2]&&(a[3]||("http:"===a[1]?"80":"443"))===(Xt[3]||("http:"===Xt[1]?"80":"443")))),c.data&&c.processData&&"string"!=typeof c.data&&(c.data=x.param(c.data,c.traditional)),ln(rn,c,t,T),2===v)return T;u=c.global,u&&0===x.active++&&x.event.trigger("ajaxStart"),c.type=c.type.toUpperCase(),c.hasContent=!Zt.test(c.type),r=c.url,c.hasContent||(c.data&&(r=c.url+=(Vt.test(r)?"&":"?")+c.data,delete c.data),c.cache===!1&&(c.url=Jt.test(r)?r.replace(Jt,"$1_="+Yt++):r+(Vt.test(r)?"&":"?")+"_="+Yt++)),c.ifModified&&(x.lastModified[r]&&T.setRequestHeader("If-Modified-Since",x.lastModified[r]),x.etag[r]&&T.setRequestHeader("If-None-Match",x.etag[r])),(c.data&&c.hasContent&&c.contentType!==!1||t.contentType)&&T.setRequestHeader("Content-Type",c.contentType),T.setRequestHeader("Accept",c.dataTypes[0]&&c.accepts[c.dataTypes[0]]?c.accepts[c.dataTypes[0]]+("*"!==c.dataTypes[0]?", "+sn+"; q=0.01":""):c.accepts["*"]);for(l in c.headers)T.setRequestHeader(l,c.headers[l]);if(c.beforeSend&&(c.beforeSend.call(p,T,c)===!1||2===v))return T.abort();b="abort";for(l in{success:1,error:1,complete:1})T[l](c[l]);if(n=ln(on,c,t,T)){T.readyState=1,u&&f.trigger("ajaxSend",[T,c]),c.async&&c.timeout>0&&(s=setTimeout(function(){T.abort("timeout")},c.timeout));try{v=1,n.send(m,k)}catch(C){if(!(2>v))throw C;k(-1,C)}}else k(-1,"No Transport");function k(e,t,o,a){var l,m,y,b,w,C=t;2!==v&&(v=2,s&&clearTimeout(s),n=undefined,i=a||"",T.readyState=e>0?4:0,l=e>=200&&300>e||304===e,o&&(b=pn(c,T,o)),b=fn(c,b,T,l),l?(c.ifModified&&(w=T.getResponseHeader("Last-Modified"),w&&(x.lastModified[r]=w),w=T.getResponseHeader("etag"),w&&(x.etag[r]=w)),204===e||"HEAD"===c.type?C="nocontent":304===e?C="notmodified":(C=b.state,m=b.data,y=b.error,l=!y)):(y=C,(e||!C)&&(C="error",0>e&&(e=0))),T.status=e,T.statusText=(t||C)+"",l?h.resolveWith(p,[m,C,T]):h.rejectWith(p,[T,C,y]),T.statusCode(g),g=undefined,u&&f.trigger(l?"ajaxSuccess":"ajaxError",[T,c,l?m:y]),d.fireWith(p,[T,C]),u&&(f.trigger("ajaxComplete",[T,c]),--x.active||x.event.trigger("ajaxStop")))}return T},getJSON:function(e,t,n){return x.get(e,t,n,"json")},getScript:function(e,t){return x.get(e,undefined,t,"script")}}),x.each(["get","post"],function(e,t){x[t]=function(e,n,r,i){return x.isFunction(n)&&(i=i||r,r=n,n=undefined),x.ajax({url:e,type:t,dataType:i,data:n,success:r})}});function pn(e,t,n){var r,i,o,s,a=e.contents,u=e.dataTypes;while("*"===u[0])u.shift(),r===undefined&&(r=e.mimeType||t.getResponseHeader("Content-Type"));if(r)for(i in a)if(a[i]&&a[i].test(r)){u.unshift(i);break}if(u[0]in n)o=u[0];else{for(i in n){if(!u[0]||e.converters[i+" "+u[0]]){o=i;break}s||(s=i)}o=o||s}return o?(o!==u[0]&&u.unshift(o),n[o]):undefined}function fn(e,t,n,r){var i,o,s,a,u,l={},c=e.dataTypes.slice();if(c[1])for(s in e.converters)l[s.toLowerCase()]=e.converters[s];o=c.shift();while(o)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!u&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),u=o,o=c.shift())if("*"===o)o=u;else if("*"!==u&&u!==o){if(s=l[u+" "+o]||l["* "+o],!s)for(i in l)if(a=i.split(" "),a[1]===o&&(s=l[u+" "+a[0]]||l["* "+a[0]])){s===!0?s=l[i]:l[i]!==!0&&(o=a[0],c.unshift(a[1]));break}if(s!==!0)if(s&&e["throws"])t=s(t);else try{t=s(t)}catch(p){return{state:"parsererror",error:s?p:"No conversion from "+u+" to "+o}}}return{state:"success",data:t}}x.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(e){return x.globalEval(e),e}}}),x.ajaxPrefilter("script",function(e){e.cache===undefined&&(e.cache=!1),e.crossDomain&&(e.type="GET")}),x.ajaxTransport("script",function(e){if(e.crossDomain){var t,n;return{send:function(r,i){t=x("
ExternalInterface.call(script_js, EmbedObject.getId(), event);
}
}
}
--------------------------------------------------------------------------------
/src/flash/player.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianhadaway/UbaPlayer/b915aa3695b9d9ce05a9dcbdc9b3f4ba115aa57a/src/flash/player.fla
--------------------------------------------------------------------------------
/src/images/btn.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianhadaway/UbaPlayer/b915aa3695b9d9ce05a9dcbdc9b3f4ba115aa57a/src/images/btn.psd
--------------------------------------------------------------------------------
/src/jquery.ubaplayer.js:
--------------------------------------------------------------------------------
1 | (function($, window, document, undefined) {
2 | var UbaPlayer = function(elem, options) {
3 | this.$elem = $(elem);
4 | this.$elem.data('instance', this);
5 | this.init(options);
6 | };
7 |
8 | UbaPlayer.prototype = {
9 | defaults: {
10 | audioButtonClass: 'ubaplayer-button',
11 | autoPlay: null,
12 | codecs: [{
13 | name: 'OGG',
14 | codec: 'audio/ogg; codecs="vorbis"'
15 | }, {
16 | name: 'MP3',
17 | codec: 'audio/mpeg'
18 | }],
19 | continuous: false,
20 | controlsClass: 'ubaplayer-controls',
21 | extension: null,
22 | fallbackExtension: '.mp3',
23 | fallbackFunctions: {
24 | error: null,
25 | pause: null,
26 | play: null,
27 | resume: null
28 | },
29 | flashAudioPlayerPath: 'swf/player.swf',
30 | flashExtension: '.mp3',
31 | flashObjectID: 'ubaplayer-flash',
32 | loadingClass: 'ubaplayer-loading',
33 | loop: false,
34 | playerContainer: 'ubaplayer-container',
35 | playingClass: 'ubaplayer-playing',
36 | swfobjectPath: 'js/swfobject.js',
37 | volume: 0.5,
38 | shuffle: false
39 | },
40 |
41 | isPlaying: false,
42 | isFlash: false,
43 | isFallback: false,
44 |
45 | init: function(options) {
46 | var scope = this,
47 | i = 0,
48 | ilen;
49 | //set defaults
50 | this.options = $.extend(true, {}, this.defaults, (options || {}));
51 | this.loadProxy = $.proxy(this.onLoaded, this);
52 | this.errorProxy = $.proxy(this.onError, this);
53 | this.endProxy = $.proxy(this.onEnded, this);
54 | this.$buttons = $("." + this.options.audioButtonClass);
55 |
56 | ilen = this.options.codecs.length;
57 |
58 | //listen for clicks on the controls
59 | $("." + this.options.controlsClass).on("click", function(event) {
60 | // Only manage click events to audioButtonClass.
61 | if ($(event.target).hasClass(scope.options.audioButtonClass)) {
62 | scope.updateTrackState(event);
63 | return false;
64 | }
65 | });
66 |
67 | for (; i < ilen; i++) {
68 | var type = this.options.codecs[i];
69 | if (this.canPlay(type)) {
70 | this.options.extension = [".", type.name.toLowerCase()].join("");
71 | break;
72 | }
73 | }
74 |
75 | if (!this.options.extension || this.isFlash) {
76 | this.isFlash = true;
77 | this.options.extension = this.options.flashExtension;
78 | }
79 |
80 | if (this.isFlash) {
81 | this.$elem.html("
");
82 | $.getScript(this.options.swfobjectPath, $.proxy(function() {
83 | swfobject.embedSWF(this.options.flashAudioPlayerPath, this.options.playerContainer, "0", "0", "9.0.0", "swf/expressInstall.swf", false, false, {
84 | id: this.options.flashObjectID
85 | }, $.proxy(this.swfLoaded, this));
86 | }, this));
87 | } else {
88 | if (this.options.autoPlay) {
89 | this.play(this.options.autoPlay);
90 | }
91 | }
92 | },
93 |
94 | pause: function() {
95 | if (this.isFallback) {
96 | if (typeof this.options.fallbackFunctions.pause == "function") {
97 | this.options.fallbackFunctions.pause();
98 | }
99 | } else if (this.isFlash) {
100 | this.audio.pauseFlash();
101 | } else {
102 | this.audio.pause();
103 | }
104 |
105 | this.$tgt.removeClass(this.options.playingClass);
106 | this.isPlaying = false;
107 | },
108 |
109 | play: function(element) {
110 |
111 | var track;
112 | if (this.options.shuffle)
113 | {
114 | var numberoftracks = $('.' + this.options.audioButtonClass+':not(.ended)').length;
115 | if (numberoftracks > 0){
116 |
117 | var track = Math.floor((Math.random() * numberoftracks) + 0);
118 | }
119 | }else{
120 | track = 0;
121 | }
122 |
123 | this.$tgt = typeof element === 'undefined' ? $('.' + this.options.audioButtonClass).eq(track) : element;
124 | this.currentTrack = this.getFileNameWithoutExtension(this.$tgt.attr("href"));
125 | this.isPlaying = true;
126 | this.$tgt.addClass(this.options.loadingClass);
127 | this.$buttons.removeClass(this.options.playingClass);
128 |
129 | if (this.isFallback) {
130 | if (typeof this.options.fallbackFunctions.play == "function") {
131 | this.options.fallbackFunctions.play(this.currentTrack + this.options.fallbackExtension);
132 | }
133 | } else if (this.isFlash) {
134 | if (this.audio) {
135 | this.removeListeners(window);
136 | }
137 | this.audio = document.getElementById(this.options.flashObjectID);
138 | this.addListeners(window);
139 | this.audio.playFlash(this.currentTrack + this.options.extension);
140 | } else {
141 | if (this.audio) {
142 | this.audio.pause();
143 | this.removeListeners(this.audio);
144 | }
145 | this.audio = new Audio("");
146 | this.addListeners(this.audio);
147 | this.audio.id = "audio";
148 | this.audio.loop = this.options.loop ? "loop" : "";
149 | this.audio.volume = this.options.volume;
150 | this.audio.src = this.currentTrack + this.options.extension;
151 | this.audio.play();
152 | }
153 | },
154 |
155 | playing: function() {
156 | return this.isPlaying;
157 | },
158 |
159 | resume: function() {
160 | if (this.isFallback) {
161 | if (typeof this.options.fallbackFunctions.resume == "function") {
162 | this.options.fallbackFunctions.resume();
163 | }
164 | } else if (this.isFlash) {
165 | this.audio.playFlash();
166 | } else {
167 | this.audio.play();
168 | }
169 | this.$tgt.addClass(this.options.playingClass);
170 | this.isPlaying = true;
171 | },
172 |
173 | updateTrackState: function(evt) {
174 | this.$tgt = $(evt.target);
175 | if (!this.$tgt.hasClass(this.options.audioButtonClass)) {
176 | return;
177 | }
178 | if (!this.audio || (this.audio && this.currentTrack !== this.getFileNameWithoutExtension(this.$tgt.attr("href")))) {
179 | this.play(this.$tgt);
180 | } else if (!this.isPlaying) {
181 | this.resume();
182 | } else {
183 | this.pause();
184 | }
185 | },
186 |
187 | addListeners: function(elem) {
188 | var el = $(elem);
189 | el.on('canplay', this.loadProxy);
190 | el.on('error', this.errorProxy);
191 | el.on('ended', this.endProxy);
192 | },
193 |
194 | removeListeners: function(elem) {
195 | var el = $(elem);
196 | el.off('canplay', this.loadProxy);
197 | el.off('error', this.errorProxy);
198 | el.off('ended', this.endProxy);
199 | },
200 |
201 | onLoaded: function() {
202 | this.$buttons.removeClass(this.options.loadingClass);
203 | this.$tgt.addClass(this.options.playingClass);
204 |
205 | this.audio.play();
206 | },
207 |
208 | onError: function() {
209 | this.$buttons.removeClass(this.options.loadingClass);
210 | if (this.isFlash) {
211 | this.removeListeners(window);
212 | } else {
213 | this.removeListeners(this.audio);
214 | }
215 | },
216 |
217 | onEnded: function() {
218 | this.isPlaying = false;
219 | this.$tgt.removeClass(this.options.playingClass);
220 | this.$tgt.addClass("ended");
221 | this.currentTrack = "";
222 | if (this.isFlash) {
223 | this.removeListeners(window);
224 | } else {
225 | this.removeListeners(this.audio);
226 | }
227 |
228 | if (this.options.continuous) {
229 | //shuffle
230 | if (this.options.shuffle)
231 | {
232 |
233 | var numberoftracks = $('.' + this.options.audioButtonClass+':not(.ended)').length;
234 | if (numberoftracks > 0){
235 |
236 | var randomtrack = Math.floor((Math.random() * numberoftracks) + 0);
237 | var $next = $('.' + this.options.audioButtonClass+':not(.ended)').eq(randomtrack);
238 |
239 | if (this.options.loop && numberoftracks == 1)
240 | {
241 | $('.' + this.options.audioButtonClass+' .ended').removeClass('ended');
242 | }
243 |
244 | this.play($next);
245 |
246 | }
247 |
248 | }else{
249 | var $next = this.$tgt.next().length ? this.$tgt.next() : $(this.options.audioButtonClass).eq(0);
250 | this.play($next);
251 |
252 | }
253 |
254 | }
255 |
256 | },
257 |
258 | canPlay: function(type) {
259 | if (!document.createElement("audio").canPlayType) {
260 | return false;
261 | } else {
262 | return document.createElement("audio").canPlayType(type.codec).match(/maybe|probably/i) ? true : false;
263 | }
264 | },
265 |
266 | swfLoaded: function(e) {
267 | if (!e.success) {
268 | this.isFlash = false;
269 | this.isFallback = true;
270 |
271 | if (typeof this.options.fallbackFunctions.error == "function") {
272 | this.options.fallbackFunctions.error();
273 | }
274 | }
275 |
276 | if (this.options.autoPlay) {
277 | setTimeout(function() {
278 | this.play(this.options.autoPlay);
279 | }, 500);
280 | }
281 | },
282 |
283 | getFileNameWithoutExtension: function(fileName) {
284 | //this function take a full file name and returns an extensionless file name
285 | //ex. entering foo.mp3 returns foo
286 | //ex. entering foo returns foo (no change)
287 | var fileNamePieces = fileName.split('.');
288 | fileNamePieces.pop();
289 | return fileNamePieces.join(".");
290 | }
291 | };
292 |
293 | $.fn.ubaPlayer = function(options, args) {
294 | if (typeof options === 'string') {
295 | return this.each(function() {
296 | $(this).data('instance')[options](args);
297 | });
298 | } else {
299 | return this.each(function() {
300 | new UbaPlayer(this, options);
301 | });
302 | }
303 | };
304 |
305 | })(jQuery, window, document);
306 |
--------------------------------------------------------------------------------
/ubaplayer.jquery.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ubaplayer",
3 | "version":"2.0.3",
4 | "title": "UbaPlayer",
5 | "description": "The jQuery HTML5 Audio Player with Flash Fallback.",
6 | "keywords": [
7 | "jquery",
8 | "plugin",
9 | "audio",
10 | "player",
11 | "html5",
12 | "flash",
13 | "fallback"
14 | ],
15 | "homepage": "http://brianhadaway.github.io/UbaPlayer/",
16 | "author": {
17 | "name":"Brian Hadaway",
18 | "url": "http://brianhadaway.com"
19 | },
20 | "bugs": "https://github.com/brianhadaway/UbaPlayer/issues",
21 | "licenses": [
22 | {
23 | "type": "MIT",
24 | "url": "https://github.com/jstayton/jquery-manifest/blob/master/LICENSE-MIT"
25 | }
26 | ],
27 | "dependencies": {
28 | "jquery": ">=1.8"
29 | },
30 | "docs": "https://github.com/brianhadaway/UbaPlayer/blob/master/README.md",
31 | "demo": "http://brianhadaway.github.io/UbaPlayer/"
32 | }
--------------------------------------------------------------------------------