SampleDataEvent.SAMPLE_DATA永远不会在Flex中触发?

时间:2010-07-28 11:21:40

标签: flex flash actionscript-3 flex3

microphone.addEventListener(SampleDataEvent.SAMPLE_DATA,gotMicData); 事件gotMicData永远不会被解雇..但是我尝试使用dispatchEvent但这将返回null byteArray .. 但是类似的代码在Flashcs5中工作正常......

        

        import flash.events.SampleDataEvent;
        import flash.media.Microphone;
        import flash.media.Sound;
        import flash.utils.ByteArray;

        [Bindable] private var microphoneList:Array;
                 protected var microphone:Microphone;
                 protected var isRecording:Boolean = false;
                 protected var soundRecording:ByteArray;
                 protected var soundOutput:Sound;

        protected function setupMicrophoneList():void
        {
            microphoneList = Microphone.names;
        }

        protected function setupMicrophone():void
        {
            microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
            microphone.rate = 44;
        }

        protected function startMicRecording():void
        {
            isRecording = true;
            soundRecording = new ByteArray();
            microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
        }

        protected function stopMicRecording():void
        {
            isRecording = false;
            microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
        }

        private function gotMicData(micData:SampleDataEvent):void
        {
            soundRecording.writeBytes(micData.data);
        }

        protected function playbackData():void
        {
            soundRecording.position = 0;

            soundOutput = new Sound();
            soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);

            soundOutput.play();
        }

        private function playSound(soundOutput:SampleDataEvent):void
        {
            if (!soundRecording.bytesAvailable > 0)
                return;
            for (var i:int = 0; i < 8192; i++)
            {
                var sample:Number = 0;
                if (soundRecording.bytesAvailable > 0)
                    sample = soundRecording.readFloat();
                soundOutput.data.writeFloat(sample); 
                soundOutput.data.writeFloat(sample);  
            }               
        }


    ]]>
</mx:Script>

3 个答案:

答案 0 :(得分:0)

安装Flex Builder也会将sdk 3.2设置为默认值,我发现你只需下载最新的flex sdk并在flex builder中使用它......代码就可以了。

答案 1 :(得分:0)

SampleDataEvent是Flash Player 10.1的一项功能。在您项目的Flex Compiler属性中将播放器目标设置为10.1或更高,您应该很好。

答案 2 :(得分:0)

嘿只是为了添加到这个帖子我遇到了类似的问题,直到我在这个博客上看到评论:

http://www.bytearray.org/?p=1858

基本上,您必须确保您的舞台足够大,以容纳Flash安全设置窗口。

让我疯狂,想要把这美丽弄清楚。