From 8bb5c3d77ffab9aaf4bb4b2d9a450e5585c425f9 Mon Sep 17 00:00:00 2001 From: Alexander Gorishnyak Date: Mon, 7 Oct 2013 17:29:25 +0600 Subject: [PATCH 1/2] Add option to play only one track at a time Added attribute ("single") which pauses all other tracks when current is played. --- audiojs/audio.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/audiojs/audio.js b/audiojs/audio.js index 1c2a299..3f13c90 100644 --- a/audiojs/audio.js +++ b/audiojs/audio.js @@ -34,6 +34,7 @@ autoplay: false, loop: false, preload: true, + single: false, imageLocation: path + 'player-graphics.gif', swfLocation: path + 'audiojs.swf', useFlash: (function() { @@ -220,10 +221,11 @@ wrapperId = 'audiojs_wrapper'+this.instanceCount, instanceCount = this.instanceCount++; - // Check for `autoplay`, `loop` and `preload` attributes and write them into the settings. + // Check for `autoplay`, `loop`, `preload` and `single` attributes and write them into the settings. if (element.getAttribute('autoplay') != null) s.autoplay = true; if (element.getAttribute('loop') != null) s.loop = true; if (element.getAttribute('preload') == 'none') s.preload = false; + if (element.getAttribute('single') != null) s.single = true; // Merge the default settings with the user-defined `options`. if (options) this.helpers.merge(s, options); @@ -643,7 +645,14 @@ }, playPause: function() { if (this.playing) this.pause(); - else this.play(); + else { + if (this.settings.single) { + for (var i = 0; i < container[audiojs].instanceCount; ++i) { + container[audiojs].instances['audiojs'+i].pause(); + } + } + this.play(); + } }, play: function() { var ios = (/(ipod|iphone|ipad)/i).test(navigator.userAgent); From 7e5662b4cf749ffb905890a0d7bb57e11208e1e8 Mon Sep 17 00:00:00 2001 From: Alexander Gorishnyak Date: Mon, 7 Oct 2013 17:30:25 +0600 Subject: [PATCH 2/2] Update audio.min.js Updated minified version (audio.min.js) --- audiojs/audio.min.js | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/audiojs/audio.min.js b/audiojs/audio.min.js index e5fde2b..ad1d482 100644 --- a/audiojs/audio.min.js +++ b/audiojs/audio.min.js @@ -1,24 +1 @@ -(function(h,o,g){var p=function(){for(var b=/audio(.min)?.js.*/,a=document.getElementsByTagName("script"),c=0,d=a.length;c ',settings:{autoplay:false,loop:false,preload:true,imageLocation:p+"player-graphics.gif",swfLocation:p+"audiojs.swf",useFlash:function(){var b=document.createElement("audio");return!(b.canPlayType&&b.canPlayType("audio/mpeg;").replace(/no/,""))}(),hasFlash:function(){if(navigator.plugins&&navigator.plugins.length&&navigator.plugins["Shockwave Flash"])return true;else if(navigator.mimeTypes&&navigator.mimeTypes.length){var b= -navigator.mimeTypes["application/x-shockwave-flash"];return b&&b.enabledPlugin}else try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash");return true}catch(a){}return false}(),createPlayer:{markup:'

00:00/00:00
', -playPauseClass:"play-pause",scrubberClass:"scrubber",progressClass:"progress",loaderClass:"loaded",timeClass:"time",durationClass:"duration",playedClass:"played",errorMessageClass:"error-message",playingClass:"playing",loadingClass:"loading",errorClass:"error"},css:' .audiojs audio { position: absolute; left: -1px; } .audiojs { width: 460px; height: 36px; background: #404040; overflow: hidden; font-family: monospace; font-size: 12px; background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #444), color-stop(0.5, #555), color-stop(0.51, #444), color-stop(1, #444)); background-image: -moz-linear-gradient(center top, #444 0%, #555 50%, #444 51%, #444 100%); -webkit-box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); -moz-box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); -o-box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); } .audiojs .play-pause { width: 25px; height: 40px; padding: 4px 6px; margin: 0px; float: left; overflow: hidden; border-right: 1px solid #000; } .audiojs p { display: none; width: 25px; height: 40px; margin: 0px; cursor: pointer; } .audiojs .play { display: block; } .audiojs .scrubber { position: relative; float: left; width: 280px; background: #5a5a5a; height: 14px; margin: 10px; border-top: 1px solid #3f3f3f; border-left: 0px; border-bottom: 0px; overflow: hidden; } .audiojs .progress { position: absolute; top: 0px; left: 0px; height: 14px; width: 0px; background: #ccc; z-index: 1; background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #ccc), color-stop(0.5, #ddd), color-stop(0.51, #ccc), color-stop(1, #ccc)); background-image: -moz-linear-gradient(center top, #ccc 0%, #ddd 50%, #ccc 51%, #ccc 100%); } .audiojs .loaded { position: absolute; top: 0px; left: 0px; height: 14px; width: 0px; background: #000; background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #222), color-stop(0.5, #333), color-stop(0.51, #222), color-stop(1, #222)); background-image: -moz-linear-gradient(center top, #222 0%, #333 50%, #222 51%, #222 100%); } .audiojs .time { float: left; height: 36px; line-height: 36px; margin: 0px 0px 0px 6px; padding: 0px 6px 0px 12px; border-left: 1px solid #000; color: #ddd; text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.5); } .audiojs .time em { padding: 0px 2px 0px 0px; color: #f9f9f9; font-style: normal; } .audiojs .time strong { padding: 0px 0px 0px 2px; font-weight: normal; } .audiojs .error-message { float: left; display: none; margin: 0px 10px; height: 36px; width: 400px; overflow: hidden; line-height: 36px; white-space: nowrap; color: #fff; text-overflow: ellipsis; -o-text-overflow: ellipsis; -icab-text-overflow: ellipsis; -khtml-text-overflow: ellipsis; -moz-text-overflow: ellipsis; -webkit-text-overflow: ellipsis; } .audiojs .error-message a { color: #eee; text-decoration: none; padding-bottom: 1px; border-bottom: 1px solid #999; white-space: wrap; } .audiojs .play { background: url("$1") -2px -1px no-repeat; } .audiojs .loading { background: url("$1") -2px -31px no-repeat; } .audiojs .error { background: url("$1") -2px -61px no-repeat; } .audiojs .pause { background: url("$1") -2px -91px no-repeat; } .playing .play, .playing .loading, .playing .error { display: none; } .playing .pause { display: block; } .loading .play, .loading .pause, .loading .error { display: none; } .loading .loading { display: block; } .error .time, .error .play, .error .pause, .error .scrubber, .error .loading { display: none; } .error .error { display: block; } .error .play-pause p { cursor: auto; } .error .error-message { display: block; }', -trackEnded:function(){},flashError:function(){var b=this.settings.createPlayer,a=j(b.errorMessageClass,this.wrapper),c='Missing flash player plugin.';if(this.mp3)c+=' Download audio file.';g[h].helpers.removeClass(this.wrapper,b.loadingClass);g[h].helpers.addClass(this.wrapper,b.errorClass);a.innerHTML=c},loadError:function(){var b=this.settings.createPlayer,a=j(b.errorMessageClass,this.wrapper);g[h].helpers.removeClass(this.wrapper, -b.loadingClass);g[h].helpers.addClass(this.wrapper,b.errorClass);a.innerHTML='Error loading: "'+this.mp3+'"'},init:function(){g[h].helpers.addClass(this.wrapper,this.settings.createPlayer.loadingClass)},loadStarted:function(){var b=this.settings.createPlayer,a=j(b.durationClass,this.wrapper),c=Math.floor(this.duration/60),d=Math.floor(this.duration%60);g[h].helpers.removeClass(this.wrapper,b.loadingClass);a.innerHTML=(c<10?"0":"")+c+":"+(d<10?"0":"")+d},loadProgress:function(b){var a=this.settings.createPlayer, -c=j(a.scrubberClass,this.wrapper);j(a.loaderClass,this.wrapper).style.width=c.offsetWidth*b+"px"},playPause:function(){this.playing?this.settings.play():this.settings.pause()},play:function(){g[h].helpers.addClass(this.wrapper,this.settings.createPlayer.playingClass)},pause:function(){g[h].helpers.removeClass(this.wrapper,this.settings.createPlayer.playingClass)},updatePlayhead:function(b){var a=this.settings.createPlayer,c=j(a.scrubberClass,this.wrapper);j(a.progressClass,this.wrapper).style.width= -c.offsetWidth*b+"px";a=j(a.playedClass,this.wrapper);c=this.duration*b;b=Math.floor(c/60);c=Math.floor(c%60);a.innerHTML=(b<10?"0":"")+b+":"+(c<10?"0":"")+c}},create:function(b,a){a=a||{};return b.length?this.createAll(a,b):this.newInstance(b,a)},createAll:function(b,a){var c=a||document.getElementsByTagName("audio"),d=[];b=b||{};for(var e=0,i=c.length;ea.loadedPercent)){a.updatePlayhead.call(a,[c]);a.element.skipTo(c)}};a.updatePlayhead=function(c){a.settings.updatePlayhead.apply(a,[c])};a.play=function(){if(!a.settings.preload){a.settings.preload=true;a.element.init(a.mp3)}a.playing=true;a.element.pplay();a.settings.play.apply(a)};a.pause=function(){a.playing=false;a.element.ppause();a.settings.pause.apply(a)};a.setVolume=function(c){a.element.setVolume(c)};a.loadStarted=function(){a.swfReady= -true;a.settings.preload&&a.element.init(a.mp3);a.settings.autoplay&&a.play.apply(a)}},injectFlash:function(b,a){var c=this.flashSource.replace(/\$1/g,a);c=c.replace(/\$2/g,b.settings.swfLocation);c=c.replace(/\$3/g,+new Date+Math.random());var d=b.wrapper.innerHTML,e=document.createElement("div");e.innerHTML=c+d;b.wrapper.innerHTML=e.innerHTML;b.element=this.helpers.getSwf(a)},helpers:{merge:function(b,a){for(attr in a)if(b.hasOwnProperty(attr)||a.hasOwnProperty(attr))b[attr]=a[attr]},clone:function(b){if(b== -null||typeof b!=="object")return b;var a=new b.constructor,c;for(c in b)a[c]=arguments.callee(b[c]);return a},addClass:function(b,a){RegExp("(\\s|^)"+a+"(\\s|$)").test(b.className)||(b.className+=" "+a)},removeClass:function(b,a){b.className=b.className.replace(RegExp("(\\s|^)"+a+"(\\s|$)")," ")},injectCss:function(b,a){for(var c="",d=document.getElementsByTagName("style"),e=a.replace(/\$1/g,b.settings.imageLocation),i=0,f=d.length;i1?b[b.length-1]:b}},events:{memoryLeaking:false,listeners:[],addListener:function(b,a,c){if(b.addEventListener)b.addEventListener(a,c,false);else if(b.attachEvent){this.listeners.push(b);if(!this.memoryLeaking){window.attachEvent("onunload",function(){if(this.listeners)for(var d=0,e=this.listeners.length;d-1)d||b.init.apply(b);if(b.element.readyState>1){b.settings.autoplay&&b.play.apply(b);clearInterval(a);c=setInterval(function(){b.loadProgress.apply(b);b.loadedPercent>=1&&clearInterval(c)})}},10);b.readyTimer=a;b.loadTimer=c}},purge:function(b){var a=b.attributes,c;if(a)for(c=0;cthis.loadedPercent)){this.element.currentTime=this.duration*b;this.updatePlayhead()}},load:function(b){this.loadStartedCalled=false;this.source.setAttribute("src",b);this.element.load();this.mp3=b;g[h].events.trackLoadProgress(this)}, -loadError:function(){this.settings.loadError.apply(this)},init:function(){this.settings.init.apply(this)},loadStarted:function(){if(!this.element.duration)return false;this.duration=this.element.duration;this.updatePlayhead();this.settings.loadStarted.apply(this)},loadProgress:function(){if(this.element.buffered!=null&&this.element.buffered.length){if(!this.loadStartedCalled)this.loadStartedCalled=this.loadStarted();this.loadedPercent=this.element.buffered.end(this.element.buffered.length-1)/this.duration; -this.settings.loadProgress.apply(this,[this.loadedPercent])}},playPause:function(){this.playing?this.pause():this.play()},play:function(){/(ipod|iphone|ipad)/i.test(navigator.userAgent)&&this.element.readyState==0&&this.init.apply(this);if(!this.settings.preload){this.settings.preload=true;this.element.setAttribute("preload","auto");g[h].events.trackLoadProgress(this)}this.playing=true;this.element.play();this.settings.play.apply(this)},pause:function(){this.playing=false;this.element.pause();this.settings.pause.apply(this)}, -setVolume:function(b){this.element.volume=b},trackEnded:function(){this.skipTo.apply(this,[0]);this.settings.loop||this.pause.apply(this);this.settings.trackEnded.apply(this)}};var j=function(b,a){var c=[];a=a||document;if(a.getElementsByClassName)c=a.getElementsByClassName(b);else{var d,e,i=a.getElementsByTagName("*"),f=RegExp("(^|\\s)"+b+"(\\s|$)");d=0;for(e=i.length;d1?c:c[0]}})("audiojs","audiojsInstance",this); +(function(e,t,n){var r=function(){var e=new RegExp("audio(.min)?.js.*"),t=document.getElementsByTagName("script");for(var n=0,r=t.length;n ',settings:{autoplay:false,loop:false,preload:true,single:false,imageLocation:r+"player-graphics.gif",swfLocation:r+"audiojs.swf",useFlash:function(){var e=document.createElement("audio");return!(e.canPlayType&&e.canPlayType("audio/mpeg;").replace(/no/,""))}(),hasFlash:function(){if(navigator.plugins&&navigator.plugins.length&&navigator.plugins["Shockwave Flash"]){return true}else if(navigator.mimeTypes&&navigator.mimeTypes.length){var e=navigator.mimeTypes["application/x-shockwave-flash"];return e&&e.enabledPlugin}else{try{var t=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");return true}catch(n){}}return false}(),createPlayer:{markup:'

00:00/00:00
',playPauseClass:"play-pause",scrubberClass:"scrubber",progressClass:"progress",loaderClass:"loaded",timeClass:"time",durationClass:"duration",playedClass:"played",errorMessageClass:"error-message",playingClass:"playing",loadingClass:"loading",errorClass:"error"},css:' .audiojs audio { position: absolute; left: -1px; } .audiojs { width: 460px; height: 36px; background: #404040; overflow: hidden; font-family: monospace; font-size: 12px; background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #444), color-stop(0.5, #555), color-stop(0.51, #444), color-stop(1, #444)); background-image: -moz-linear-gradient(center top, #444 0%, #555 50%, #444 51%, #444 100%); -webkit-box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); -moz-box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); -o-box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3); } .audiojs .play-pause { width: 25px; height: 40px; padding: 4px 6px; margin: 0px; float: left; overflow: hidden; border-right: 1px solid #000; } .audiojs p { display: none; width: 25px; height: 40px; margin: 0px; cursor: pointer; } .audiojs .play { display: block; } .audiojs .scrubber { position: relative; float: left; width: 280px; background: #5a5a5a; height: 14px; margin: 10px; border-top: 1px solid #3f3f3f; border-left: 0px; border-bottom: 0px; overflow: hidden; } .audiojs .progress { position: absolute; top: 0px; left: 0px; height: 14px; width: 0px; background: #ccc; z-index: 1; background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #ccc), color-stop(0.5, #ddd), color-stop(0.51, #ccc), color-stop(1, #ccc)); background-image: -moz-linear-gradient(center top, #ccc 0%, #ddd 50%, #ccc 51%, #ccc 100%); } .audiojs .loaded { position: absolute; top: 0px; left: 0px; height: 14px; width: 0px; background: #000; background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #222), color-stop(0.5, #333), color-stop(0.51, #222), color-stop(1, #222)); background-image: -moz-linear-gradient(center top, #222 0%, #333 50%, #222 51%, #222 100%); } .audiojs .time { float: left; height: 36px; line-height: 36px; margin: 0px 0px 0px 6px; padding: 0px 6px 0px 12px; border-left: 1px solid #000; color: #ddd; text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.5); } .audiojs .time em { padding: 0px 2px 0px 0px; color: #f9f9f9; font-style: normal; } .audiojs .time strong { padding: 0px 0px 0px 2px; font-weight: normal; } .audiojs .error-message { float: left; display: none; margin: 0px 10px; height: 36px; width: 400px; overflow: hidden; line-height: 36px; white-space: nowrap; color: #fff; text-overflow: ellipsis; -o-text-overflow: ellipsis; -icab-text-overflow: ellipsis; -khtml-text-overflow: ellipsis; -moz-text-overflow: ellipsis; -webkit-text-overflow: ellipsis; } .audiojs .error-message a { color: #eee; text-decoration: none; padding-bottom: 1px; border-bottom: 1px solid #999; white-space: wrap; } .audiojs .play { background: url("$1") -2px -1px no-repeat; } .audiojs .loading { background: url("$1") -2px -31px no-repeat; } .audiojs .error { background: url("$1") -2px -61px no-repeat; } .audiojs .pause { background: url("$1") -2px -91px no-repeat; } .playing .play, .playing .loading, .playing .error { display: none; } .playing .pause { display: block; } .loading .play, .loading .pause, .loading .error { display: none; } .loading .loading { display: block; } .error .time, .error .play, .error .pause, .error .scrubber, .error .loading { display: none; } .error .error { display: block; } .error .play-pause p { cursor: auto; } .error .error-message { display: block; }',trackEnded:function(e){},flashError:function(){var t=this.settings.createPlayer,r=i(t.errorMessageClass,this.wrapper),s='Missing flash player plugin.';if(this.mp3)s+=' Download audio file.';n[e].helpers.removeClass(this.wrapper,t.loadingClass);n[e].helpers.addClass(this.wrapper,t.errorClass);r.innerHTML=s},loadError:function(t){var r=this.settings.createPlayer,s=i(r.errorMessageClass,this.wrapper);n[e].helpers.removeClass(this.wrapper,r.loadingClass);n[e].helpers.addClass(this.wrapper,r.errorClass);s.innerHTML='Error loading: "'+this.mp3+'"'},init:function(){var t=this.settings.createPlayer;n[e].helpers.addClass(this.wrapper,t.loadingClass)},loadStarted:function(){var t=this.settings.createPlayer,r=i(t.durationClass,this.wrapper),s=Math.floor(this.duration/60),o=Math.floor(this.duration%60);n[e].helpers.removeClass(this.wrapper,t.loadingClass);r.innerHTML=(s<10?"0":"")+s+":"+(o<10?"0":"")+o},loadProgress:function(e){var t=this.settings.createPlayer,n=i(t.loaderClass,this.wrapper);n.style.width=100*e+"%"},playPause:function(){if(this.playing)this.settings.play();else this.settings.pause()},play:function(){var t=this.settings.createPlayer;n[e].helpers.addClass(this.wrapper,t.playingClass)},pause:function(){var t=this.settings.createPlayer;n[e].helpers.removeClass(this.wrapper,t.playingClass)},updatePlayhead:function(e){var t=this.settings.createPlayer,n=i(t.progressClass,this.wrapper);n.style.width=100*e+"%";var r=i(t.playedClass,this.wrapper),s=this.duration*e,o=Math.floor(s/60),u=Math.floor(s%60);r.innerHTML=(o<10?"0":"")+o+":"+(u<10?"0":"")+u}},create:function(e,t){var t=t||{};if(e.length){return this.createAll(t,e)}else{return this.newInstance(e,t)}},createAll:function(e,t){var n=t||document.getElementsByTagName("audio"),r=[];e=e||{};for(var i=0,s=n.length;it.loadedPercent)return;t.updatePlayhead.call(t,[e]);t.element.skipTo(e)};t["updatePlayhead"]=function(e){t.settings.updatePlayhead.apply(t,[e])};t["play"]=function(){if(!t.settings.preload){t.settings.preload=true;t.element.init(t.mp3)}t.playing=true;t.element.pplay();t.settings.play.apply(t)};t["pause"]=function(){t.playing=false;t.element.ppause();t.settings.pause.apply(t)};t["setVolume"]=function(e){t.element.setVolume(e)};t["loadStarted"]=function(){t.swfReady=true;if(t.settings.preload)t.element.init(t.mp3);if(t.settings.autoplay)t.play.apply(t)}},injectFlash:function(e,t){var n=this.flashSource.replace(/\$1/g,t);n=n.replace(/\$2/g,e.settings.swfLocation);n=n.replace(/\$3/g,+(new Date)+Math.random());var r=e.wrapper.innerHTML,i=document.createElement("div");i.innerHTML=n+r;e.wrapper.innerHTML=i.innerHTML;e.element=this.helpers.getSwf(t)},helpers:{merge:function(e,t){for(attr in t){if(e.hasOwnProperty(attr)||t.hasOwnProperty(attr)){e[attr]=t[attr]}}},clone:function(e){if(e==null||typeof e!=="object")return e;var t=new e.constructor;for(var n in e)t[n]=arguments.callee(e[n]);return t},addClass:function(e,t){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");if(n.test(e.className))return;e.className+=" "+t},removeClass:function(e,t){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")},injectCss:function(e,t){var n="",r=document.getElementsByTagName("style"),i=t.replace(/\$1/g,e.settings.imageLocation);for(var s=0,o=r.length;s1?t[t.length-1]:t}},events:{memoryLeaking:false,listeners:[],addListener:function(t,r,i){if(t.addEventListener){t.addEventListener(r,i,false)}else if(t.attachEvent){this.listeners.push(t);if(!this.memoryLeaking){window.attachEvent("onunload",function(){if(this.listeners){for(var t=0,r=this.listeners.length;t-1){if(!r)e.init.apply(e)}if(e.element.readyState>1){if(e.settings.autoplay)e.play.apply(e);clearInterval(t);n=setInterval(function(){e.loadProgress.apply(e);if(e.loadedPercent>=1)clearInterval(n)},200)}},200);e.readyTimer=t;e.loadTimer=n},purge:function(e){var t=e.attributes,n;if(t){for(n=0;nthis.loadedPercent)return;this.element.currentTime=this.duration*e;this.updatePlayhead()},load:function(t){this.loadStartedCalled=false;this.source.setAttribute("src",t);this.element.load();this.mp3=t;n[e].events.trackLoadProgress(this)},loadError:function(){this.settings.loadError.apply(this)},init:function(){this.settings.init.apply(this)},loadStarted:function(){if(!this.element.duration)return false;this.duration=this.element.duration;this.updatePlayhead();this.settings.loadStarted.apply(this)},loadProgress:function(){if(this.element.buffered!=null&&this.element.buffered.length){if(!this.loadStartedCalled){this.loadStartedCalled=this.loadStarted()}var e=this.element.buffered.end(this.element.buffered.length-1);this.loadedPercent=e/this.duration;this.settings.loadProgress.apply(this,[this.loadedPercent])}},playPause:function(){if(this.playing)this.pause();else{if(this.settings.single){for(var t=0;t1?n:n[0]}})("audiojs","audiojsInstance",this) \ No newline at end of file