P.S.
我提供的Mp3播放模块代码,采用AS2.0规范,代码架构相对比较完善!给大家一些启示吧,可以转载和修改,如若愿意,可以在修改的程序提供一个友情联接!

在线演示:

pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" menu="false" wmode="opaque" width="200"
height="200">

以下是Parameter类代码片段:
/*
* 全局参数
*/
class com.klstudio.player.Parameter extends MovieClip{
 //全局对象;
 private static var Player_Volume:Number = 100;
 private static var Player_Rotative:Boolean = false;
 function Parameter(){  
 }
 public function setPlayerVolume(_v:Number):Void{
  Parameter.Player_Volume = _v;
 }
 public function getPlayerVolume():Number{
  return Parameter.Player_Volume;
 }
 public function setPlayerRotative(_b:Boolean):Void{
  Parameter.Player_Rotative = _b;
 }
 public function getPlayerRotative():Boolean{
  return Parameter.Player_Rotative;
 }
 
}

以下是Mp3Player类代码片段:
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{  
 }
}
以下是Constant类代码片段:
/*
* 类中常量
*/
class com.klstudio.player.Constant extends MovieClip{
 public static var MP3_PLAY_START:String = "Mp3.Play.Start";
 //;
 public static var MP3_PLAY_STOP:String = "Mp3.Play.Stop";
 //;
 public static var MP3_PLAY_PAUSE:String = "Mp3.Play.Pause";
 //;
 public static var MP3_PLAY_END:String = "Mp3.Play.End";
 //;
 public static var MP3_PLAY_ERROR:String = "Mp3.Play.Error";
 //;
 public static var MP3_PLAN_PLAY:String = "Mp3.Plan.Play";
 //;
 public static var MP3_PLAN_LOAD:String = "Mp3.Plan.Load";
}
以下是调用演示代码片段:
stop();
import com.klstudio.player.Constant;
import com.klstudio.player.Mp3Player;
var player:Mp3Player = new Mp3Player();
player.onStatus = function(code:String, result:Object) {
 if (code != Constant.MP3_PLAN_LOAD && code != Constant.MP3_PLAN_PLAY) {
  s_txt.text = code;
 }
 switch (code) {
 case Constant.MP3_PLAY_START :
  play_btn._visible = false;
  pause_btn._visible = true;
  stop_btn._visible = true;
  break;
 case Constant.MP3_PLAY_STOP :
  play_btn._visible = true;
  pause_btn._visible = false;
  stop_btn._visible = false;
  break;
 case Constant.MP3_PLAY_PAUSE :
  play_btn._visible = true;
  pause_btn._visible = true;
  stop_btn._visible = true;
  break;
 case Constant.MP3_PLAY_END :
  doPlay();
  break;
 case Constant.MP3_PLAN_PLAY :
  p_txt.text = result+"%";
  break;
 case Constant.MP3_PLAN_LOAD :
  l_txt.text = result+"%";
  break;
 }
};
function doPlay():Void {
 player.doPlay("http://www.klstudio.com/media/200492011225.mp3");
}
play_btn.onRelease = function() {
 doPlay();
};
pause_btn.onRelease = function() {
 player.doPause();
};
stop_btn.onRelease = function() {
 player.doStop();
};
play_btn._visible = true;
pause_btn._visible = false;
stop_btn._visible = false;