点击进度条音乐从鼠标点击处开始播放
代码如下 | 复制代码 |
var _sound:Sound=new Sound(); var _channel:SoundChannel=new SoundChannel(); var loaded:int; var total:int; var _length:int; var position:int; var hcbfb:Number; var bfjdbfb:Number; //载入MP3并播放 var url:String="****.mp3";//你电脑上的MP3音乐文件名,把该文件与MP3音乐文件放在一个文件夹内。 var _request:URLRequest = new URLRequest(url); _sound.load(_request); _channel=_sound.play(); bfjdt_mc.visible=false; //添加不断更新监听事件 addEventListener(Event.ENTER_FRAME,yx); function yx(event:Event):void { loaded=_sound.bytesLoaded; total=_sound.bytesTotal; _length=_sound.length; position=_channel.position; hcbfb=loaded / total; _length/=hcbfb; bfjdbfb=position / _length; bfjdt_mc.scaleX=bfjdbfb; bfjdt_mc.visible=true; } if (hcbfb>=1) { jdcz_btn.addEventListener(MouseEvent.CLICK,jdcz); } } //播放进度控制 function jdcz(e:MouseEvent):void { _channel.stop(); var bfjdbfb:Number=(mouseX-26)/200; bfjdt_mc.scaleX=bfjdbfb; position =_length*bfjdbfb; _channel=_sound.play(position); } |
代码如下 | 复制代码 |
//申明变量var _sound:Sound=new Sound(); var _channel:SoundChannel=new SoundChannel(); var loaded:int; var total:int; var _length:int; var position:int; var hcbfb:Number; var bfjdbfb:Number; var tdfw:Rectangle=new Rectangle(26,57,200,0) var tdzj:Boolean=false //载入MP3并播放 var url:String="****.mp3";//你电脑上的MP3音乐文件名,把该文件与MP3音乐文件放在一个文件夹内。 var _request:URLRequest = new URLRequest(url); _sound.load(_request); _channel=_sound.play(); bfjdt_mc.visible=false; addEventListener(Event.ENTER_FRAME,yx); function yx(event:Event):void { loaded=_sound.bytesLoaded; total=_sound.bytesTotal; _length=_sound.length; hcbfb=loaded / total; bfjdt_mc.visible=true; if (tdzj==false) { position=_channel.position; bfjdbfb=position / _length; bfjdt_mc.scaleX=bfjdbfb; jdhk_btn.x=26+bfjdbfb*200; } else { bfjdbfb=(jdhk_btn.x-26)/200; bfjdt_mc.scaleX=bfjdbfb; position =_length*bfjdbfb; } } //进度滑块拖动 jdhk_btn.buttonMode=true; jdhk_btn.addEventListener(MouseEvent.MOUSE_DOWN,td); function td(e:MouseEvent):void { tdzj=true; jdhk_btn.startDrag(false,tdfw); stage.addEventListener(MouseEvent.MOUSE_UP,sf); /*该监听事件如果不放在此,你用鼠标点击舞台上任何位置再松开鼠标, 音乐在正常播放过程中也会出现停顿。*/ } jdhk_btn.addEventListener(MouseEvent.MOUSE_UP,sf); function sf(e:MouseEvent):void { stage.removeEventListener(MouseEvent.MOUSE_UP,sf); tdzj=false; stopDrag(); _channel.stop(); _channel=_sound.play(position); } |
http://www.111com.net/down/2010音乐播放器(1)——播放进度1.swf
http://www.111com.net/down/2010音乐播放器(1)——播放进度2.swf