2014-03-01 3 views
0

Sound.play 함수를 사용하면 사운드를 반복 할 횟수뿐만 아니라 인수 중 하나 인 시작 시간 (밀리 초)을 지정할 수 있습니다. 뭔가 빠졌는가, 아니면 종료 시간을 지정하는 방법이 없습니까? 예를 들어, 4 초 사운드의 루프 밀리 초 5-105를 원할 경우 105 밀리 초에서 다음 루프를 시작하도록 지정하는 방법이 있습니까?사운드의 종료 시간을 지정하는 방법

내가 누락 된 것이 없다면이 문제를 해결할 다른 방법이 있습니까?

답변

0

Sound 클래스는 해당 작업을 수행 할 수 없습니다,이 작업을 수행하는 가장 좋은 방법은 타이머를 사용하는 것입니다 :

var musicTimer:Timer = new Timer(100, 5); // Loop total time(ms), N Loops (+1) 
musicTimer.addEventListener(TimerEvent.TIMER, musicTimer_tick); 
musicTimer.addEventListener(TimerEvent.TIMER_COMPLETE, musicTimer_complete); 
musicTimer.start(); 

private function musicTimer_complete(e:TimerEvent):void 
{ 
    // Last loop stop all sounds 
    channel.stop(); 
} 

private function musicTimer_tick(e:TimerEvent):void 
{ 
    // At each loop, stop and (re)start the sound 
    channel.stop(); 
    channel = sound.play(5); // 5 is the loop start time 
} 
0

당신이 원하는 루프 설정에 맞춰 다른 Sound 개체를 만들 수 있습니다. 그런 다음 Sound:extract()을 소스 사운드와 비교하여 사운드가 루프해야하는 정확한 값을 추출한 다음 대상 사운드에서 loadPCMFromByteArray()을 호출 한 다음 해당 사운드를 반복합니다.

function loopASound(sound:Sound,startTime:uint,endTime:uint,loops:int):SoundChannel { 
    var ba:ByteArray=new ByteArray(); 
    var startPos:uint=Math.floor(startTime*44.1); 
    var endPos:uint=Math.floor(endTime*44.1); 
    // sound rate is always 44100, and positions are expected in milliseconds, 
    // as with all the functions of Sound class 
    sound.extract(ba,endPos-startPos,startPos); // get raw data 
    var ripped:Sound=new Sound(); 
    ba.position=0; 
    ripped.loadPCMFromByteArray(ba,endPos-startPos); // format, stereo and sample rate at defaults 
    return ripped.play(0,loops); 
} 

경고 : 코드는 테스트되지 않았으며 매뉴얼을 읽음으로써 만 생성됩니다. 또한 ripped 사운드를 어딘가에 저장할 수도 있으므로 동일한 세그먼트를 여러 번 반복 할 계획이라면 항상 리핑을 수행하지 않아도됩니다.

관련 문제