class Cincn.Buffer extends Cincn.Config { public var ConInterval; public var PlayInterval; public var StopInterval; public var StartInterval; public var bytNum:Number; public var bytTot:Number; /* 时间和文本框; */ public var txtStatus:TextField; public var startNum:Number; public var pauseNum:Number; public var bufferNum:Number; public function Buffer (SoundObj:Sound) { //BufferPlay (SoundObj); txtStatus = StatusTxt (); txtStatus.text = "正在连接"; ConInterval = setInterval (this, "SdCon", 300, SoundObj); } /* Function : SdCon 连接声音; */ private function SdCon (Obj_sd:Sound) { bytTot = Obj_sd.getBytesTotal (); bytNum = Obj_sd.getBytesLoaded (); if (bytTot != undefined) { clearInterval (ConInterval); StartInterval = setInterval (this, "setPlay", 300, Obj_sd); } else { txtStatus.text = "正在连接"; } } /* Function : 开始播放 */ private function setPlay (Obj_sd:Object) { startNum = StartTime (); //初始缓冲时间; if (Obj_sd.duration - Obj_sd.position <= startNum * 1000) { //预加载时间; txtStatus.text = "缓冲..."; } else { clearInterval (StartInterval); PlayInterval = setInterval (this, "BufferPlay", 500, Obj_sd); Obj_sd.start (0, 0); } } private function BufferPlay (Obj_sd:Sound) { var timeNow:Number = Obj_sd.position; var timeTot:Number = Obj_sd.duration; pauseNum = PauseTime (); txtStatus.text = "正在播放!"; var thisObj = this; if (timeTot - timeNow <= pauseNum * 1000) { if (Obj_sd.getBytesLoaded() == Obj_sd.getBytesTotal()) { //getStatus.txt = "加载完成!"! } else { Obj_sd.stop (); clearInterval (PlayInterval); StopInterval = setInterval (this, "BufferStop", 500, Obj_sd); } } Obj_sd.onSoundComplete = function () { thisObj.txtStatus.text = "播放完成!"; clearInterval (thisObj.PlayInterval); trace ("播放完成!"); } } private function BufferStop (Obj_sd:Sound) { bufferNum = BufferTime () * 1000; if (Obj_sd.duration - Obj_sd.position >= bufferNum) { clearInterval (StopInterval); Obj_sd.start(Obj_sd.position / 1000, 0); PlayInterval = setInterval (this, "BufferPlay", 500, Obj_sd); } else { txtStatus.text = "缓冲" + " " + (Obj_sd.duration - Obj_sd.position) / bufferNum * 100 + "%" ; } } function setStop () { clearInterval (StopInterval); clearInterval (PlayInterval); } }