var myControl,Control=function(a){this.setting="object"==typeof a?a:{},this.audio=this.setting.audio,this.progressWrap=this.setting.progressWrap,this.playBtn=this.setting.playBtn,this.pauseBtn=this.setting.pauseBtn,this.progress=this.setting.progress,this.oWinObj=this.setting.oWinObj,this.allTimeNode=this.setting.allTimeNode,this.currentTimeNode=this.setting.currentTimeNode,this.init()};Control.prototype={init:function(){this.start=!0,this.timer=null,this.loadTimer=null},mainControl:function(){this.start?this.goPlay():this.goPause()},selectTime:function(a){var b=a.pageX-this.progressWrap.offset().left,c=this.audio.buffered.end(this.audio.buffered.length-1),d=Math.round(c/this.audio.duration*parseInt(this.progressWrap.css("width")));d>=b&&(this.audio.currentTime=b/parseInt(this.progressWrap.css("width"))*this.audio.duration,this.progress.css("width",b+"px"))},loadMusic:function(a){var b=this;this.audio.addEventListener("progress",function(){$(".loaded").show()}),this.audio.addEventListener("error",function(){$(".audiojs").addClass("error"),b.oWinObj.html("歌曲播放失败："+b.audio.src)}),this.audio.src=a},timeDispose:function(a){var b=parseInt(a/60),c=parseInt(a%60);return b=b>=10?b:"0"+b,c=c>=10?c:"0"+c,b+":"+c},oWindow:function(a){this.oWinObj.show(),this.oWinObj.html(a)},oTime:function(){if(this.audio.readyState>=4){var a=Math.round(this.audio.currentTime/this.audio.duration*parseInt(this.progressWrap.css("width")));this.progress.css("width",a+"px"),0>=a?$(".audiojs").addClass("loading"):$(".audiojs").removeClass("loading"),this.allTimeNode.html(this.timeDispose(this.audio.duration)),this.currentTimeNode.html(this.timeDispose(this.audio.currentTime)),currentTime=this.audio.currentTime,totalTime=this.audio.duration,totalTime==currentTime&&(isEnd=!0)}else $(".audiojs").addClass("loading")},loadTime:function(){var a,b;this.audio.readyState>=1&&(a=this.audio.buffered.end(this.audio.buffered.length-1),b=Math.round(a/this.audio.duration*parseInt(this.progressWrap.css("width"))),$(".loaded").css("width",b+"px"))},goPlay:function(){this.audio.play();var a=this;this.timer=setInterval(function(){a.oTime()},1e3),this.goPlayStyle(),this.start=!1},goPause:function(){this.audio.pause(),this.goPauseStyle(),clearInterval(this.timer),clearInterval(this.loadTimer),this.start=!0},goPlayStyle:function(){$(".audiojs").addClass("playing")},goPauseStyle:function(){$(".audiojs").removeClass("playing")}},myControl=new Control({audio:document.getElementById("myPlayer"),playBtn:$(".play"),pauseBtn:$(".pause"),progressWrap:$(".scrubber"),progress:$(".progress"),oWinObj:$(".error-message"),allTimeNode:$(".duration"),currentTimeNode:$(".played")}),$(".play").bind("click",function(){myControl.mainControl()}),$(".pause").bind("click",function(){myControl.mainControl()}),$(".scrubber").bind("click",function(){myControl.selectTime(event)});