-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.ion.sound.min.js
executable file
·4 lines (4 loc) · 2.28 KB
/
jquery.ion.sound.min.js
1
2
3
4
// jQuery.Ion.Sound
// version 2.0.1 Build: 32
// https://github.com/IonDen/ion.sound
(function(e){var g=function(a){a&&console&&(console.warn&&"function"===typeof console.warn?console.warn(a):console.log&&"function"===typeof console.log&&console.log(a))};if(e.ionSound)g("$.ionSound already exists!");else if("function"!==typeof Audio&&"object"!==typeof Audio){var f=function(){g("HTML5 Audio is not supported in this browser")};e.ionSound=function(){};e.ionSound.play=f;e.ionSound.stop=f;e.ionSound.destroy=f;f()}else{var c={},b={},k,l,h,d,m=function(a){this.name=a.name;this.volume=c.volume||.5;this.preload=c.preload?"auto":"none";this.loop=!1;this.sound=null;"volume"in a&&(this.volume=+a.volume);"preload"in a&&(this.preload=a.preload?"auto":"none")};m.prototype={init:function(){this.sound=new Audio;this.sound.src=c.path+this.name+h;this.sound.load();this.sound.preload=this.preload;this.sound.volume=this.volume;this.sound.addEventListener("ended",this._ended.bind(this),!1)},play:function(a){a||(a={});a.volume&&(this.volume=+a.volume,this.sound.volume=this.volume);a.loop?this._playLoop(a.loop):(this.loop=!1,this._play())},_play:function(){try{this.sound.currentTime=0}catch(a){}this.sound.play()},_playLoop:function(a){"boolean"===typeof a?(this.loop=9999999,this._play()):"number"===typeof a&&(this.loop=a-1,this._play())},_ended:function(){0<this.loop&&(this.loop-=1,this._play())},stop:function(){this.loop=!1;this.sound.pause();try{this.sound.currentTime=0}catch(a){}},destroy:function(){this.stop();this.sound.removeEventListener("ended",this._ended.bind(this),!1);this.sound.src="";this.sound=null}};e.ionSound=function(a){c=JSON.parse(JSON.stringify(a));c.path=c.path||"";c.volume=c.volume||.5;c.preload=c.preload||!1;c.mix=c.mix||!0;if(k=c.sounds.length){l=(new Audio).canPlayType("audio/mpeg");switch(l){case "probably":case "maybe":h=".mp3";break;default:h=".ogg"}for(d=0;d<k;d++)a=c.sounds[d],b[a.name]=new m(a),b[a.name].init()}else g("No sound-files provided!")};e.ionSound.version="2.0.1";e.ionSound.play=function(a,c){b[a]&&b[a].play(c)};e.ionSound.stop=function(a){if(a&&b[a])b[a].stop();else for(d in b)b.hasOwnProperty(d)&&b[d]&&b[d].stop()};e.ionSound.destroy=function(a){if(a&&b[a])b[a].destroy(),b[a]=null;else for(d in b)b.hasOwnProperty(d)&&b[d]&&(b[d].destroy(),b[d]=null)}}})(jQuery);