0

こんにちは私はAS3ワーカーを使用してユーザーサウンドを録音しようとしていますが、ワーカーとメインシーン間の通信に関してはすべてうまく機能しますが、ここでの録音機能には問題があると思います。bytearray.org(http: //www.bytearray.org/?p=1858)そしてこれが私のコードです何かが足りません:

    package objects
{
    import flash.events.Event;
    import flash.system.MessageChannel;
    import flash.system.Worker;
    import flash.system.WorkerDomain;
    import flash.utils.ByteArray;

    import starling.display.Button;
    import starling.display.Image;
    import starling.display.Sprite;
    import starling.events.Event;

    public class RecordComponent extends Sprite
    {
        private var audioContainer:Image;
        private var recButton:Button;
        private var playButton:Button;
        private var stopButton:Button;

        //background thread for recording       
        private var worker:Worker;
        private var wtm:MessageChannel;
        private var mtw:MessageChannel;
        private var output:ByteArray;

        public function RecordComponent()
        {
            super();
            worker = WorkerDomain.current.createWorker(Workers.RecordWorker);
            wtm = worker.createMessageChannel(Worker.current);
            mtw = Worker.current.createMessageChannel(worker);

            worker.setSharedProperty("wtm",wtm);
            worker.setSharedProperty("mtw",mtw);
            worker.start();
            wtm.addEventListener(flash.events.Event.CHANNEL_MESSAGE,onChannelMessage);
            this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
        }

        protected function onChannelMessage(event:flash.events.Event):void
        {
            output = wtm.receive();
        }

        protected function onAddedToStage(event:starling.events.Event):void
        {
            this.removeEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
            drawScreen();
        }

        private function drawScreen():void
        {
            audioContainer  = new Image( Assets.getAtlas().getTexture("audioContainer") );
            addChild(audioContainer);           

            //record button
            recButton = new Button( Assets.getAtlas().getTexture("recordButton") );
            recButton.x=Math.ceil(194/2 - recButton.width/2);
            recButton.y=5;
            addChild(recButton);

            //stop button
            stopButton = new Button( Assets.getAtlas().getTexture("stopButton") );
            stopButton.x=recButton.x+10;
            stopButton.y=10;
            stopButton.visible = false;
            addChild(stopButton);

            //play button
            playButton = new Button( Assets.getAtlas().getTexture("playButton") );
            playButton.x=Math.ceil(194 - playButton.width)-25;
            playButton.y=10;
            playButton.visible = false;
            addChild(playButton);


            this.addEventListener(starling.events.Event.TRIGGERED, buttons_triggeredHandler);
        }

        private function buttons_triggeredHandler(event:starling.events.Event):void
        {
            var currentButton:Button = event.target as Button;
            switch(currentButton)
            {
                case recButton:
                    startRecording();
                    break;
                case stopButton:
                    stopRecording();
                    break;
                case playButton:
                    playRecording();
                    break;
            }
        }

        private function playRecording():void
        {
            mtw.send("RECORD_PLAY");
        }

        private function stopRecording():void
        {
            stopButton.visible = false;
            recButton.x = 25;
            playButton.visible = true;
            recButton.visible = true;
            mtw.send("RECORD_STOP");
            //
        }

        private function startRecording():void
        {
            recButton.visible = false;
            stopButton.visible = true;
            playButton.visible = false;
            mtw.send("RECORD_START");
        }



    }
}

RecordWorker

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.media.Microphone;
    import flash.system.MessageChannel;
    import flash.system.Worker;

    import org.as3wavsound.WavSound;
    import org.bytearray.micrecorder.MicRecorder;
    import org.bytearray.micrecorder.encoder.WaveEncoder;
    import org.bytearray.micrecorder.events.RecordingEvent;

    public class RecordWorker extends Sprite
    {
        private var wtm:MessageChannel;
        private var mtw:MessageChannel;
        // volume in the final WAV file will be downsampled to 50%
        private var volume:Number = .75;
        // we create the WAV encoder to be used by MicRecorder
        private var wavEncoder:WaveEncoder = new WaveEncoder( volume );
        // we create the MicRecorder object which does the job
        private var recorder:MicRecorder = new MicRecorder( wavEncoder,Microphone.getEnhancedMicrophone() );

        public function RecordWorker()
        {
            wtm = Worker.current.getSharedProperty("wtm");
            mtw = Worker.current.getSharedProperty("mtw");

            mtw.addEventListener(Event.CHANNEL_MESSAGE,command_Handler);
        }
        //message received from the main component
        protected function command_Handler(event:Event):void
        {
            switch(mtw.receive())
            {
                case "RECORD_START":
                    trace("recording.....");
                    recorder.record();
                    recorder.addEventListener(RecordingEvent.RECORDING, onRecording);
                    recorder.addEventListener(flash.events.Event.COMPLETE, onRecordComplete);
                    break;
                case "RECORD_STOP":
                    trace("record stopped....");
                    recorder.stop();
                    break;
                case "RECORD_PLAY":
                    if(recorder.output.length>0)
                    {
                        var player:WavSound = new WavSound(recorder.output);
                        player.play();
                    }
                    break;
            }
        }
        private function onRecording(event:RecordingEvent):void
        {
            trace ( event.time );
        }

        private function onRecordComplete(event:flash.events.Event):void
        {

        }
    }
}

アニーヘルプが適用されます

ありがとう、Khaled

4

1 に答える 1

0

AdobeのAS3リファレンスに関するこの記事を見ると、作成された各ワーカーは「Flashランタイムの仮想インスタンス」であるため、コアランタイムの入力チャネルまたは出力チャネルに直接接続されていないようです。マイククラスはそのようなカットオフインターフェイスの1つであるため、ワーカー内のシステムマイクに到達できません。

于 2013-08-21T07:45:51.467 に答える