Gapless sound looping in ActionScript 3.0
보통 사운드 루핑을 만들 때 Event.SOUND_COMPLETE 이벤트나 Sound.play(0, 999);를 사용할텐데요. 이 경우에 음악이 재생되는 사이에 약간의 틈이 발생합니다. 다음 플래시 무비처럼 말이죠.
이 파일은 아래의 코드와 같이, Event.SOUND_COMPLETE를 사용하여 사운드를 루프시키고 있습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import flash.media.*; import flash.events.*; import flash.utils.Timer; var snd:Sound = new loop(); var chn:SoundChannel; function playSound():void { if(chn){ chn.removeEventListener(Event.SOUND_COMPLETE, sndListener); } chn = snd.play(); chn.addEventListener(Event.SOUND_COMPLETE, sndListener); } function sndListener(e:Event):void { playSound(); } lbl.text = "Loop with Event.SOUND_COMPLETE"; btn2.enabled = false; btn1.addEventListener(MouseEvent.CLICK, clickListener1); btn2.addEventListener(MouseEvent.CLICK, clickListener2); function clickListener1(e:MouseEvent):void { playSound(); btn1.enabled = false; btn2.enabled = true; } function clickListener2(e:MouseEvent):void { btn1.enabled = true; btn2.enabled = false; chn.stop(); } |
Recent Comments