Flash Media Player中Mp3播放模块代码
发布:kinglong | 发布时间: 2005年3月25日P.S.
我提供的Mp3播放模块代码,采用AS2.0规范,代码架构相对比较完善!给大家一些启示吧,可以转载和修改,如若愿意,可以在修改的程序提供一个友情联接!
在线演示:
| 以下是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; |
发布:kinglong | 分类:Flash技术 | 评论:2 | 引用:0 | 浏览:
| TrackBack引用地址
- 相关文章:
终于可以学习和开发flash lite 2.0的程序了 (2006-1-4 15:27:55)
最近刚完成的flash视频项目 (2006-1-4 15:24:2)
更新Flash视频服务端技术 (2005-12-1 15:20:22)
flash视频服务端应用开发 (2005-11-22 14:48:56)
更新Loading组件 (2005-11-9 15:28:47)
从AS2.0到AS3.0 (2005-10-18 15:34:1)
AS 3.0—flash变革性代码体系的来临 (2005-10-8 15:36:58)
Loading组件(原创组件) (2005-9-13 15:41:16)
Flash动态显示波形组件(原创组件) (2005-8-28 15:42:46)
prototype属性和ASSetPropFlags函数(转载) (2005-8-5 15:47:41)
- 1.windward
- http://www.battery-sell.com
- 回家试试看!谢谢~!
- 2006-5-17 14:33:12 回复该留言
- 2.游戏天下
- http://www.whyyoung.com
- 不错,谢了
- 2006-5-23 16:55:50 回复该留言
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。




