0

我得到了用于录制用户声音的代码:

public class Main extends Sprite
     {
   private var mic:Microphone;
   private var waveEncoder:WaveEncoder = new WaveEncoder();
   private var recorder:MicRecorder = new MicRecorder(waveEncoder);
   private var recBar:RecBar = new RecBar();
   private var tween:Tween;
   private var fileReference:FileReference = new FileReference();

  public function Main():void
   {
    recButton.stop();
    activity.stop();
    mic = Microphone.getMicrophone();
    mic.setSilenceLevel(0);
    mic.gain = 100;
    mic.setLoopBack(true);
    mic.setUseEchoSuppression(true);
    Security.showSettings("2");
    addListeners();
}

private function addListeners():void
{
    recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);
    recorder.addEventListener(RecordingEvent.RECORDING, recording);
    recorder.addEventListener(Event.COMPLETE, recordComplete);
    activity.addEventListener(Event.ENTER_FRAME, updateMeter);
}

private function startRecording(e:MouseEvent):void
{
    if (mic != null)
    {
        recorder.record();
        e.target.gotoAndStop(2);

        recButton.removeEventListener(MouseEvent.MOUSE_UP, startRecording);
        recButton.addEventListener(MouseEvent.MOUSE_UP, stopRecording);

        addChild(recBar);

        tween = new Tween(recBar,"y",Strong.easeOut, -recBar.height,0,1,true);
    }
}

private function stopRecording(e:MouseEvent):void
{
    recorder.stop();

    mic.setLoopBack(false);
    e.target.gotoAndStop(1);

     recButton.removeEventListener(MouseEvent.MOUSE_UP, stopRecording);
    recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);

    tween = new Tween(recBar,"y",Strong.easeOut,0, - recBar.height,1,true);
}

private function updateMeter(e:Event):void
{
    activity.gotoAndPlay(100 - mic.activityLevel);
}

private function recording(e:RecordingEvent):void
{
    var currentTime:int = Math.floor(e.time / 1000);

    recBar.counter.text = String(currentTime);

    if (String(currentTime).length == 1)
    {
        recBar.counter.text = "00:0" + currentTime;
    }
    else if (String(currentTime).length == 2)
    {
        recBar.counter.text = "00:" + currentTime;
    }
}

private function recordComplete(e:Event):void
{
    fileReference.save(recorder.output, "recording.wav");
}
}

我想用计时器事件替换鼠标事件。如果持续时间 == 5 则开始录制并在 10 秒后停止录制。我很困惑在哪里添加我的计时器代码,如下所示:

var myIntrotime:Timer = new Timer(1000,5);
myIntrotime.addEventListener(TimerEvent.TIMER, startIntroTime);
myIntrotime.start();

var SecondsElapsed:Number = 1;

function startIntroTime(event:TimerEvent):void
{
    if (SecondsElapsed==5)
    {
        //start recording
            //start another timer2 and if timer2 finished stop recording
    }
    SecondsElapsed++;
}

有人可以帮助我吗?

4

1 回答 1

1

flash.utils.setTimeout()如果您雇用延迟通话,您可以做得更好。这使您可以使用计时器进行所有肮脏的工作。

setTimeout(startIntroTime,5000)
function startIntroTime():void
{
    //start recording
    setTimeout(stopRecording,10000);
}

关于 setTimeout() 的手册

于 2013-08-02T07:25:40.457 回答