fadeEffect.end(); playProgress.alpha=caption.alpha=1.0; if(e.ctrlKey){ pan=Math.min(1,pan+0.025); balance(pan); break; } if(!keyPressed){ deltaSeek=Math.max(100,snd.length/10000); if(playing) currentTime=sndCh.position; else currentTime=playResumePosition; } keyPressed=true; playResumePosition=Math.min(snd.length-10,currentTime+deltaSeek); seek(playResumePosition/1000); deltaSeek*=1.1; break; case 38: vol=Math.min(1,vol+0.025); volume(vol); break; case 40: if(e.ctrlKey){ pan=0; balance(pan); break; } vol=Math.max(0,vol-0.025); volume(vol); break; default: if(e.charCode==109) mute(); //`m' } } private function onKeyUp(e:KeyboardEvent):void { switch(e.keyCode) { case 37: //<-- case 39: //--> deltaSeek=Math.max(100,snd.length/10000); keyPressed=false; if (!mouseIsOver) fadeEffect.play(); break; } } private function formatLabel(s:Number):String { s/=1000; var hrs:Number = Math.floor(s / 3600); var min:Number = Math.floor(s / 60 % 60); var sec:Number = Math.floor(s % 60); var fmtd:String=''; if(hrs>0) fmtd = String(hrs)+':'; if(hrs>0 && min <10) fmtd+='0'; fmtd += String(min)+':'; if(sec<10) fmtd+='0'; fmtd += String(sec); txtAlign="center"; try{ if(id3.songName) fmtd += ' '+ String.fromCharCode(0x2014) + ' ' + id3.songName; if(id3.artist) fmtd += ' | ' + id3.artist; if(id3.album) fmtd += ' | ' + id3.album; if(id3) txtAlign="start"; }catch(e:Object){} return fmtd; } private function addEventListeners():void { this.setFocus(); this.addEventListener(Event.ENTER_FRAME, onEnterFrame); this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp); this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); } private function setSource(s:String):void { pause(); source=s; initSound(); pause();seek(0); } private function loadPolicy(p:String):void {policy=p;} private function play():void { if(playing) return; try{sndCh = snd.play(playResumePosition, 0, sndTr);} catch(e:Error){Alert.show(e.message,'Error');} sndCh.addEventListener(Event.SOUND_COMPLETE, onSoundComplete); playing = true; } private function pause():void { if(!playing) return; playResumePosition = sndCh.position; sndCh.stop(); playing = false; } private function playPause():void { if(playing) pause(); else play(); } private function seek(p:Number):void { playResumePosition = p*1000; if(!playing) return; sndCh.stop(); playing = false; play(); } private function rewind():void { seek(0); } private function volume(v:Number):void { sndTr.volume = v; sndCh.soundTransform=sndTr; } private function mute():void { if(muted) { if(lastVol==0) lastVol=0.75; volume(lastVol); muted=false; } else { lastVol = sndTr.volume volume(0); muted=true; } } private function balance(p:Number):void { sndTr.pan = p; sndCh.soundTransform=sndTr; } private function initCallBacks():void { ExternalInterface.addCallback("play", play); ExternalInterface.addCallback("pause", pause); ExternalInterface.addCallback("playPause", playPause); ExternalInterface.addCallback("seek", seek); ExternalInterface.addCallback("rewind", rewind); ExternalInterface.addCallback("volume", volume); ExternalInterface.addCallback("balance", balance); ExternalInterface.addCallback("mute", mute); ExternalInterface.addCallback("setSource", setSource); ExternalInterface.addCallback("loadPolicy", loadPolicy); } private function onSoundComplete(e:Event):void { playing = false; playResumePosition = 0; if(loop) play(); } private function onComplete(e:Event):void { playProgress.indeterminate=false; } private function onProgress(e:ProgressEvent):void { playProgress.indeterminate=true; } private function onEnterFrame(e:Event):void { if(!playProgress.indeterminate) { if(playing) { playProgress.setProgress(sndCh.position,snd.length); caption.text=formatLabel(sndCh.position); } else { playProgress.setProgress(playResumePosition,snd.length); caption.text=formatLabel(playResumePosition); } }else{ if(playing) { playProgress.setProgress(Math.random(),1); caption.text=formatLabel(sndCh.position); } else { playProgress.setProgress(snd.bytesLoaded,snd.bytesTotal); caption.text=formatLabel(playResumePosition); } } } private function onID3Info(e:Event):void {id3 = e.target.id3;} private function onError(e:ErrorEvent):void { Alert.show(e.type, e.text); } ]]>