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

发布于 2024-09-12 03:38:58 字数 2324 浏览 4 评论 0原文

麦克风.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>

microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
the event gotMicData is never fired.. however i tried using dispatchEvent but that will return null byteArray..
However similar code works fine in 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伏妖词 2024-09-19 03:38:58

安装 Flex Builder 还会将 sdk 3.2 设置为默认值,我发现您只需下载最新的 Flex sdk 并在 Flex Builder 中使用它..代码就可以正常工作..

Installing the Flex Builder will also set sdk 3.2 as default and I found that u just have to download the latest flex sdk and use it in flex builder.. and the code will work fine..

长安忆 2024-09-19 03:38:58

SampleDataEvent 是 Fl​​ash Player 10.1 的一项功能。在项目的 Flex 编译器属性中将播放器目标设置为 10.1 或更高,这样就可以了。

SampleDataEvent is a Flash player 10.1 feature. Set your player target to 10.1 or higher in the Flex Compiler properties for your project, and you should be good.

肩上的翅膀 2024-09-19 03:38:58

嘿,只是为了添加到此线程中,我遇到了类似的问题,直到我看到此博客上的评论:

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

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

试图弄清楚这种美让我发疯。

Hey Just to add to this thread I was having a similar problem until I saw a comment on this blog :

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

Basically you have to make sure your stage is big enough to accommodate the flash security settings window.

Drove me nuts trying to figure this beauty out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文