.flash filename="snd3.swf" bbox=420x440 version=9 fps=12 background=#666666 .edittext log width=40 height=50 color=black multiline html .put log x=10 y=20 .action: package { import flash.display.*; import flash.text.* ; import flash.events.* ; import flash.media.Sound;; import flash.net.URLRequest; import flash.media.SoundChannel; public dynamic class Main extends MovieClip { var snd:Sound ; var file; var vum:Sprite ; var but:Sprite ; var bar2:Sprite ; var channel:SoundChannel ; var loaded=0; var run:Boolean=false; var pos:uint=0; function completed(evt:ProgressEvent):void { this.log.text="\nReady"; loaded=1; } function enterFrame(evt:Event) { if ( loaded == 1 ) { //vumetre var l= 318 +(channel.leftPeak * - 230); var r= 318 +(channel.rightPeak * - 230); vum.graphics.clear(); vum.graphics.lineStyle(1,0x00FF00); vum.graphics.moveTo(0, 93); vum.graphics.lineTo(0+r,93); vum.graphics.lineStyle(1,0xFF0000); vum.graphics.moveTo(0, 96); vum.graphics.lineTo(0+l,96); // progression pos=(channel.position/snd.length)*100; pos=Math.round(pos) ; if ( pos ==0 ) trace("Press on green bar where you want to start\n or on yellow button"); else trace(pos+"%"); bar2.graphics.lineStyle(5,0x0000FF);//blue bar2.graphics.moveTo(0,77); bar2.graphics.lineTo(pos,77); } else { var ratio=snd.bytesLoaded/snd.bytesTotal; ratio *=100; if ( ratio == 100 ) { bar2.addEventListener(MouseEvent.CLICK, clic); loaded=1; } this.log.text=ratio+" %"; bar2.graphics.lineStyle(5,0x00FF00);//green bar2.graphics.moveTo(0, 77); bar2.graphics.lineTo(ratio, 77); } } function clic(evt:MouseEvent):void { var position:uint = evt.localX; var percent:uint= Math.round(position) ; var cue:uint = (percent/100) * snd.length; this.log.text="started at "+percent+" % "; bar2.graphics.lineStyle(5,0x00FF00); bar2.graphics.moveTo(0, 77); bar2.graphics.lineTo(100,77); //loaded=2; channel=snd.play(cue); } function toggle(evt:MouseEvent):void { trace(run); var col ; if (run) { run=false; col=0xFF0000;//red pos=channel.position; trace(pos); channel.stop(); } else { channel=snd.play(pos); col=0x00FF00;//green run=true; } but.graphics.lineStyle(5,col); but.graphics.moveTo(0,65); but.graphics.lineTo(10,65); //loaded=2; } function errorHandler(evt:IOErrorEvent):void { this.log.text=file+" could not be loaded ... try snd3.swf?file=my.mp3 "+evt.text; } function trace (s) { this.log.text=s+"\n"; } public function Main() { var o = this.loaderInfo.parameters; if ( o.file ) file=o.file ; else file="mp3/petitpapa.mp3"; var req:URLRequest=new URLRequest(file); this.log.autoSize = TextFieldAutoSize.LEFT; this.log.text="loading ... \n" ; snd=new Sound(); snd.load(req); vum=new Sprite(); addChild(vum); but=new Sprite(); but.graphics.lineStyle(7,0xFFFF00); but.graphics.moveTo(0, 65); but.graphics.lineTo(10,65); but.addEventListener(MouseEvent.CLICK, toggle); addChild(but); bar2=new Sprite(); addChild(bar2); snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); snd.addEventListener(Event.COMPLETE, completed); addEventListener(Event.ENTER_FRAME, enterFrame); channel=snd.play(); channel.stop(); } } } .end # action .end # .flash