define(["Marionette","base/BaseCtrl","./phonegap/PhonegapPlayer","./html5/Html5Player","events/EventManager"],function(a,b,c,d,e){var f=a.Controller.extend({initialize:function(){b.applyMixin.call(this),this.ctrls={},this.views={},this.eventManager=new e(this),this.rememberIsPaused=!1,_.bindAll(this,"onPlay","onStop","_publishAudioPosition","_startAudioPosition","startAudioPositionTimer","stopAudioPositionTimer"),this.mediaTimer=null},isSupport:function(){return componentUtils.detector.isHTML5AudioSupport()?!0:!0},makeSupport:function(){this.ctrls.player=componentUtils.detector.isHTML5AudioSupport()?new d:new c},isPaused:function(){return this.rememberIsPaused},play:function(a){if(this.ctrls.player&&this.ctrls.player.stop(),this.src=a&&a.src?a.src:this.src,this.onFinish=a&&a.onFinish?_.once(a.onFinish):this.onFinish,!this.src)throw alert("No source in player"),new Error("No source in player");this.isPaused()?(this.rememberIsPaused=!1,this.ctrls.player.play()):(this.stopAudioPositionTimer(),this.ctrls.player.play(this.src,1e3,this.onPlay,this.onStop,this.onFinish))},pause:function(){this.rememberIsPaused=!0,this.ctrls.player.pause()},stop:function(){this.rememberIsPaused=!1,this.ctrls.player&&this.ctrls.player.stop(),this.stopAudioPositionTimer()},onPlay:function(){this.stopAudioPositionTimer(),this.startAudioPositionTimer()},onStop:function(){this.rememberIsPaused=!1,this.stopAudioPositionTimer()},startAudioPositionTimer:function(){null==this.mediaTimer&&(this.mediaTimer=setInterval(this._startAudioPosition,1e3),this._startAudioPosition())},_startAudioPosition:function(){this.isClosed||this.ctrls.player.getPosition(this._publishAudioPosition,this._publishAudioPosition)},stopAudioPositionTimer:function(){clearInterval(this.mediaTimer),this.mediaTimer=null},_publishAudioPosition:function(a,b){var c={currentAudioPosition:_.isNumber(a)?a:0,currentAudioLength:_.isNumber(b)?b:0};this.eventManager.trigger(CtrlEvents.Player.position,c,this),c.currentAudioPosition===c.currentAudioLength&&(this.onStop(),this.onFinish())},onDestroy:function(){this.stop()}});return _.extend(f.prototype,b),f});