(function(){function e(a,b){a._isUnbinded?f(a,b):setTimeout(function(){f(a,b)},200)}function f(a,b){if(a=a.$n())try{if("stop"===b)a.pause(),a.currentTime=0;else a[b]()}catch(c){zk.debugLog(c.message||c)}}var g=zul.med.Audio=zk.$extends(zul.Widget,{$define:{src:function(){this.rerender()},autoplay:function(a){var b=this.$n();b&&(b.autoplay=a)},preload:function(a){var b=this.$n();b&&void 0!==a&&(b.preload=a)},controls:function(a){var b=this.$n();b&&(b.controls=a)},loop:function(a){var b=this.$n();b&&
(b.loop=a)},muted:function(a){var b=this.$n();b&&(b.muted=a)}},play:function(){e(this,"play")},stop:function(){e(this,"stop")},pause:function(){e(this,"pause")},bind_:function(){this.$supers(g,"bind_",arguments);var a=this.$n();a.addEventListener("play",this.proxy(this._audioOnPlay));a.addEventListener("pause",this.proxy(this._audioOnPause));a.addEventListener("ended",this.proxy(this._audioOnEnded))},unbind_:function(){this._isUnbinded=!0;this.stop();var a=this.$n();a.removeEventListener("ended",
this.proxy(this._audioOnEnded));a.removeEventListener("pause",this.proxy(this._audioOnPause));a.removeEventListener("play",this.proxy(this._audioOnPlay));this.$supers(g,"unbind_",arguments)},domAttrs_:function(a){var b=this.$supers("domAttrs_",arguments);this._autoplay&&(b+=" autoplay");void 0!==this._preload&&(b+=' preload="'+this._preload+'"');this._controls&&(b+=" controls");this._loop&&(b+=" loop");this._muted&&(b+=" muted");return b},domContent_:function(){for(var a=this._src,b=a.length,c="",
d=0;d<b;d++)c+='<source src="'+a[d]+'" type="'+this._MIMEtype(a[d])+'">';return c},_audioOnPlay:function(){this._fireOnStateChange(1)},_audioOnPause:function(){this.$n().currentTime&&this._fireOnStateChange(2)},_audioOnEnded:function(){this._fireOnStateChange(3)},_fireOnStateChange:function(a){this.fire("onStateChange",{state:a})},_MIMEtype:function(a){var b=a.lastIndexOf("."),c="wav";-1!==b&&(a=a.substring(b+1).toLowerCase(),"mp3"===a?c="mpeg":"ogg"===a&&(c="ogg"));return"audio/"+c}})})();
