import com.klstudio.player.Constant; import com.klstudio.player.Parameter; class com.klstudio.player.Mp3Player extends MovieClip { private var __sound:Object; private var __target:Object; private var __param:Parameter; private var __path:String; private var __position:Number; private var __paused:Boolean private var __refresh_time:Number = 500; private var __mar:Number; function Mp3Player(){ this.__param = new Parameter(); this.init(); } private function init():Void{ _soundbuftime = 10; this.__sound = new Sound(); this.__sound.__target = this; this.__sound.onSoundComplete = doSoundComplete; } private function doSoundComplete():Void{ if(this.__target.__param.getPlayerRotative()){ this.__target.doPlay(this.__target.__path); }else{ this.__target.doEnd(); } } private function doInterval():Void{ var sound_load:Number = 0; var sound_play:Number = 0; if(this.__sound.getBytesTotal()>0){ sound_load = int(this.__sound.getBytesLoaded()/this.__sound.getBytesTotal()*100); } if(this.__sound.duration>0){ sound_play = int(this.__sound.position/(this.__sound.duration*this.__sound.getBytesTotal()/this.__sound.getBytesLoaded())*100) } this.onStatus(Constant.MP3_PLAN_LOAD,sound_load); this.onStatus(Constant.MP3_PLAN_PLAY,sound_play); } public function doPlay(path:String):Void{ this.init(); this.__path = path; this.__paused = false; this.__position = 0; this.__sound.loadSound(path,true); this.__sound.setVolume(this.__param.getPlayerVolume()); this.__sound.start(); this.onStatus(Constant.MP3_PLAY_START,null); this.__mar = setInterval(this,"doInterval",this.__refresh_time); } public function doStop():Void{ this.__sound.stop(); this.onStatus(Constant.MP3_PLAY_STOP,null); clearInterval(this.__mar); } private function doEnd():Void{ this.__sound.stop(); this.onStatus(Constant.MP3_PLAY_END,null); clearInterval(this.__mar); } public function doPause():Void{ if(this.__paused){ this.__sound.start(this.__position/1000); this.onStatus(Constant.MP3_PLAY_START,null); this.__mar = setInterval(this,"doInterval",this.__refresh_time); }else{ this.__position = this.__sound.position; this.__sound.stop(); this.onStatus(Constant.MP3_PLAY_PAUSE,null); clearInterval(this.__mar); } this.__paused = !this.__paused; } public function setVolume(_v:Number):Void{ this.__sound.setVolume(_v); this.__param.setPlayerVolume(_v); } public function setRefreshTime(_t:Number):Void{ this.__refresh_time = _t; } public function onStatus(code:String,result:Object):Void{ } }